This section assumes you've already implemented a solution for collecting and tokenizing your customers' cards. If you haven't, see Collecting Card Details before proceeding.
Xendit.js and your payment form alone do not create a charge. Combined, Xendit.js and the HTML form fulfill the first half of the payment process, but server-side code is also necessary to complete the workflow.
Once the token has been successfully created with either Xendit.js or mobile SDK, it must be submitted to your server where the card can be charged.
After you've securely collected and tokenized your customer's card details using Xendit.js or mobile SDK, you can charge the card.
curl https://api.xendit.co/credit_card_charges -X POST \
-u xnd_development_O46JfOtygef9kMNsK+ZPGT+ZZ9b3ooF4w3Dn+R1k+2fT/7GlCAN3jg==: \
-d external_id=your-external-id \
-d token_id=your-token-id \
-d amount=17000
<?php
require("vendor/autoload.php");
$options['secret_api_key'] = "xnd_development_O46JfOtygef9kMNsK+ZPGT+ZZ9b3ooF4w3Dn+R1k+2fT/7GlCAN3jg==";
$xenditPHPClient = new XenditClientXenditPHPClient($options);
$external_id = "your-external-id";
$token_id = "your-token-id";
$amount = 17000; // Amount must match what was passed to createToken in the browser
$response = $xenditPHPClient->captureCreditCardPayment($external_id, $token_id, $amount);
print_r($response);
?>
Be sure to use your Secret API key instead of your Public API key here.
That's it! If the charge creation request succeeds, the card has been successfully charged.
For full API references you can check our API Reference .
These test card numbers work only in development (test) mode.
Card Brand | Bank | Number |
Visa | BRI | 4000 0000 0000 0002 |
Visa | BNI | 4365 0237 8115 5828 |
Visa | BCA | 4472 4299 6831 3785 |
Visa | Xendit | 4111 1111 1111 1111 |
MasterCard | BRI | 5104 5821 7994 9459 |
MasterCard | BNI | 5426 4045 6410 9386 |
MasterCard | BCA | 5413 2258 5638 7173 |
MasterCard | Xendit | 5200 0000 0000 0007 |
JCB | BRI | 3565 1052 0569 5297 |
JCB | BNI | 3565 2427 2869 5395 |
JCB | BCA | 3562 8025 5872 3915 |
JCB | Xendit | 3569 9600 1008 3758 |
In Development mode, you can use these magic amounts to simulate failure responses when you create a charge. Enter in one of the amounts listed here as the amount to be charged.
FAILURE REASON | DEFINITION | MAGIC AMOUNT |
---|---|---|
EXPIRED_CARD | The card you are trying to capture is expired. | 10051 |
CARD_DECLINED | The card you are trying to capture has been declined by the issuing bank. | 10052 |
PROCESSOR_ERROR | The charge failed because there's an integration issue between the card processor and the bank. | 10053 |
INSUFFICIENT_BALANCE | The card you are trying to capture does not have enough balance to complete the capture. | 10054 |
STOLEN_CARD | The card you are trying to capture has been marked as stolen. | 10055 |
INACTIVE_CARD | The card you are trying to capture is inactive. | 10056 |
TEMPORARY_SYSTEM_ERROR | There is a temporary system error when the charge attempt happens. | 10057 |
CAPTURE_AMOUNT_LIMIT_ERROR | The amount capture is either below the minimum limit or above the maximum limit. | 10058 |
Still have more questions? We're always happy to help however we can. Shoot us an email or talk to us in live chat.