In the previous section on Creating Charges, the method of charging explained will require your customers to enter their card details every time they want to make a payment. By using our Multiple Charges feature, you can allow your customers to perform authentication once, and then charge multiple times using the same token.
There are three(3) steps involved in using this:
Step 1: Create a Multiple-Use Token
Multiple-use token can be created using the same
Xendit.card.createToken function in Xendit.js. The difference is that you should add
is_multiple_use = true in
The result of this function is to create a multiple use token, which will need to be authenticated before being used for capture.
Step 2: Authenticate the Token
To authenticate the token, you can call the
Xendit.card.createAuthentication function in Xendit.js.
This function receives three(3) arguments :
authenticationData: the authentication details including
xenditResponseHandler: a callback you will need to write that handles the response from Xendit
authentication_id: what you can use to charge the multiple use token
Step 3: Charge the Multiple-Use Token
Charge the multiple-use token you have created, using the same endpoint as charging a single-use token.
The difference is that you should add
authentication_id as the payload of this endpoint - for example:
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 \
$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 on createAuthentication in the browser
$authentication_id = "your-authentication-id";
$response = $xenditPHPClient->captureCreditCardPayment($external_id, $token_id, $amount);