Charging Cards

Once you have card token representing your user's card with custom form - the next step is to charge that card for money. This have to be done on your server by making simple request to our API.

Note that card token is a temporary representation of card details - it have to be used within 24 hours after creation or it will expire.

This example shows how to create charge from cardToken :

$Epayoo = new EpayooGateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');

$chargeRequest = new ChargeRequest();
$chargeRequest->amount(799)->currency('EUR')->card($cardToken);

$charge = $Epayoo->createCharge($chargeRequest);

Note that we have placed your test mode API secret key in this example. This is needed to authenticate your requests. Remember to change that key to your live mode in production.

After successfully creating charge you should be able to see it on charges list in your dashboard.

More information about creating charges can be found in API references.

Saving card for later use

Card tokens are one-time use only. Once you create charge from token that token can't be used to do anything else. To avoid asking user for his card data every time you want to create charge you must create a customer with a card.

This example shows how use card token to create customer with a card and how to create charge on that customer's card:

$Epayoo = new EpayooGateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');

$customerRequest = new CustomerRequest();
$customerRequest->email('[email protected]')->card($tokenId);
$customer = $Epayoo->createCustomer($customerRequest);

$chargeRequest = new ChargeRequest();
$chargeRequest->amount(799)->currency('EUR')->customerId($customer->getId());
$charge = $Epayoo->createCharge($chargeRequest);

Note that we have placed your test mode API secret key in this example. This is needed to authenticate your requests. Remember to change that key to your live mode in production.

More information about creating customers can be found in API references.