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 .
A POST request should be sent to https://www.fakepay.io/purchase
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.
The following parameters are required:
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
The credit card number to charge. See below for which card numbers to use to trigger various responses.
cvv
The card's CVV, expressed as a string1. See below for which CVV numbers to use to trigger various responses.
expiration_month
The month the card expires, as a two-digit number expressed as a string1. For example, June would be "06"
.
expiration_year
The year the card expires, as a four-digit number expressed as a string1.
zip_code
The zip code of the credit card, expressed as a string1.
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.
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 |
The only valid cvv value is 123 . Anything else will return an error code of 1000004 .
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 . |
# 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.
# 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.
# 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.
# 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 .