Fakepay

The purpose of Fakepay is to mimic, very simply, the card tokenization behavior of a real payment gateway in test mode.

Developers will send a  POST  request to the  /purchase  endpoint to simulate the authorization, tokenization, and charging of a credit card for some amount.

A successful request will see a  token  returned. The  token  is suitable for storing and using for subsequent charges.

Unsuccessful requests will have an  error_code .

URL

A  POST  request should be sent to  https://www.fakepay.io/purchase 

Authorization

You will receive an API key from Chargify. This key must be passed along with every request as the authorization token.

Assuming your API key is  cfc65ad1671a865ba28c4911126ce9 , the  Authorization  header would look like:

        
curl -X POST \
  -H "Authorization: Token token=cfc65ad1671a865ba28c4911126ce9" \
  https://www.fakepay.io/purchase
        
      

More full example requests are below.

Request Parameters

The following parameters are required:

Amount

amount

The amount to charge for. This should always be in cents, expressed as a string or integer. For example, $10.00 would be  amount: 1000 .

Card Number

card_number

The credit card number to charge. See below for which card numbers to use to trigger various responses.

CVV

cvv

The card's CVV, expressed as a string1. See below for which CVV numbers to use to trigger various responses.

Expiration Month

expiration_month

The month the card expires, as a two-digit number expressed as a string1. For example, June would be "06".

Expiration Year

expiration_year

The year the card expires, as a four-digit number expressed as a string1.

Zip Code

zip_code

The zip code of the credit card, expressed as a string1.

Token

token

The  token  from a previously successful purchase. Note that, if you specify a token in your API request, you cannot also pass in other credit card attributes like  card_number ,  cvv ,  expiration_month ,  expiration_year  or  zip .

1 Why strings for "numeric" values? CVVs, dates, and zip codes, can contain leading zeros. International postal codes can contain letters.

Test Card Numbers

Test Card Numbers

Use the following credit card numbers to trigger various scenarios:

Card Number Description Error Code
4242424242424242 Successful purchase None
4242424242424241 Invalid card number 1000001
4242424242420089 Insufficient funds 1000002

CVV Values

The only valid  cvv  value is  123 . Anything else will return an error code of  1000004 .

Error Codes

Error Code Description
1000001 Invalid credit card number
1000002 Insufficient funds
1000003 CVV failure
1000004 Expired card
1000005 Invalid zip code
1000006 Invalid purchase amount
1000007 Invalid token
1000008 Invalid params: cannot specify both  token  and other credit card params like  card_number ,  cvv ,  expiration_month ,  expiration_year  or  zip .

Making Requests

A successful purchase

        
# Request
curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Token token=cfc65ad1671a865ba28c4911126ce9" \
  -d '{"amount":"1000","card_number":"4242424242424242","cvv":"123","expiration_month":"01","expiration_year":"2024","zip_code":"10045"}' \
  https://www.fakepay.io/purchase

# Response
{"token":"2e3673154977752b3ed5e0a5a849c3","success":true,"error_code":null}
        
      

Note the  token  in the response: this is the "credit card token" to be used for future charges.

A successful purchase with a token from a previously successful purchase:

        
# Request
curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Token token=cfc65ad1671a865ba28c4911126ce9" \
  -d '{"amount":"1000", "token":"2e3673154977752b3ed5e0a5a849c3"}' \
  https://www.fakepay.io/purchase

# Response
{"token":"2e3673154977752b3ed5e0a5a849c3","success":true,"error_code":null}
        
      

Note the  token  in the response is the same (valid) token from your request.

Attempting a purchase with invalid API credentials

        
# Request
curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Token token=a_bad_token" \
  -d '{"amount":"1000","card_number":"4242424242424242","cvv":"123","expiration_month":"01","expiration_year":"2024","zip_code":"10045"}' \
  https://www.fakepay.io/purchase

# Response
HTTP Token: Access denied.
        
      

Attempting a purchase with an invalid card number

        
# Request
curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Token token=cfc65ad1671a865ba28c4911126ce9" \
  -d '{"amount":"1000","card_number":"4242424242424241","cvv":"123","expiration_month":"01","expiration_year":"2024","zip_code":"10045"}' \
  https://www.fakepay.io/purchase

# Response
{"token":null,"success":false,"error_code":1000001}
        
      

Note the presence of an  error_code ,  success: false , and no  token .