Testing tips

Use this information as you test your integration.

Test card numbers

Successful charges can be created using the following card numbers in conjunction with the test-mode secret key and a card expiration in the future:

Card NumberCard Type
378282246310005American Express
371449635398431American Express
5105105105105100MasterCard
5499740000000057MasterCard
30569309025904Diners Club
38520000023237Diners Club
6011111111111117Discover
6011000990139424Discover
3530111333300000JCB
3566002020360505JCB
4242424242424242Visa
4012888888881881Visa
4012000010000Visa

Failure scenarios can be tested using the following card numbers and the test-mode secret key:

Card NumberError Code
4000000000000002card_declined
4000000000000044card_declined_insufficient_funds
4000000000000051card_declined_limit_exceeded
4000000000000069card_expired
4000000000000119card_declined_processing_error
4000000000000127card_declined_hold
4242424242424241card_number_invalid
4000000000000135card_type_not_accepted

CVV and AVS checks can be tested against various account policies using the following card numbers and the test-mode secret key. Note that depending on the policy in effect, the CVV and AVS results may or may not result in an error code being returned. For example, if the CVV policy is set to DISABLED, a CVV Not Matched response will not cause a failure, whereas it would if the CVV policy were set to REQUIRE_MATCH_LENIENT.

Card NumberCVV/AVS Response
4000000000000077CVV Unavailable
4000000000000101CVV Not Matched
4000000000000010AVS Not Matched
4000000000000085AVS Unavailable
4000000000000093AVS Error
4000000000000028If card postal code is null or empty, AVS returns Not Matched. Otherwise, an AVS Postal Code Match is returned.
4000000000000036If card address is null or empty, AVS returns Not Matched. Otherwise an AVS Address Match is returned.

Test bank account numbers

Using a TEST bank account, you can capture eCheck transfers using the routing numbers 000000000 or 000000013 with any account number. The following exceptions return eCheck errors useful for testing purposes:

Routing NumberAccount NumberError Code
0000000131000000001ach_declined
0000000131000000002ach_declined_hold
0000000131000000003ach_declined_duplicate
0000000131000000004ach_invalid_account_number
0000000131000000005ach_insufficient_funds
0000000131000000006ach_account_not_found
0000000131000000007ach_account_closed
0000000131000000008ach_account_frozen
0000000131000000009ach_limit_exceeded
000000001Anyach_invalid_routing_number

cURL and Postman tips

All of the API examples you see on this site use cURL commands to demonstrate requests to our APIs. However, there are more popular tools that make testing APIs easier, like Postman. This topic explains how to test our APIs using either cURL or Postman.

All API requests are authenticated using HTTP Basic Authentication.

Note: As part of basic authentication, you must base64-encode your keys when you submit them in a request.

The method you use to authenticate depends on what you’re trying to do:

Using cURL

cURL is a command line tool for transferring data using URL syntax. If your system isn’t already configured to use cURL, you may need to download and install it.

Most cURL commands on this site have the same structure. Let’s evaluate the following example:

Exchange card details for a one-time token
curl -X POST -H "Content-Type:application/json" --user <public_key>: https://api.chargeio.com/v1/tokens -d '
{
      "type": "card",
      "number": "4242424242424242",
      "exp_month": 10,
      "exp_year": 2022,
      "cvv": "123",
      "name": "Some Customer",
      "address1": "123 Street St",
      "postal_code": "78701",
      "email":"test@affinipay.com"
  }'

Our APIs return JSON-formatted responses. Here’s an example response based on the previous cURL example:

{
    "id": "QkeoVcnkQe25ceADBYJfQw",
    "created": "2018-06-25T17:27:33.987Z",
    "modified": "2018-06-25T17:27:33.987Z",
    "name": "Some Customer",
    "address1": "123 Street St",
    "postal_code": "78701",
    "email": "test@affinipay.com",
    "type": "card",
    "number": "************4242",
    "exp_month": 10,
    "exp_year": 2022,
    "cvv": "***"
}

Using Postman

Postman is a free API test client available for MacOS, Windows, Linux, and Chrome. It provides a feature-rich GUI for making API calls and can be a little easier to use than cURL.

Let’s launch the Postman app and make the same API request we made using cURL:

  1. Select Post from the method drop-down menu.
  2. Enter the following endpoint URL in the adjacent text box: https://api.chargeio.com/v1/tokens
  3. Configure headers. No Auth should be selected in Authorization > Type by default. If not, do that now.
    • Enter Content-Type in the first key field and application/json in the adjacent value field.
    • Enter Authorization in the next key field and Basic followed by your base64-encoded secret key plus trailing colon (<secret_key>:). Use the base64 (OS X/Linux) or certutil (Windows) command line tool to encode your secret key.

  4. Click Body, click the raw option, and paste in the following JSON:
    
     {
         "type": "card",
         "number": "4242424242424242",
         "name": "Dave Bowman",
         "address1": "2001 Space Odyssey Ln",
         "postal_code": "78750",
         "email": "devsupport@affinipay.com",
         "exp_month": 10,
         "exp_year": 2022,
         "cvv": "123"
     }
  5. Click Send.

This is what a successful response in Postman looks like: