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:

$securionPay = new SecurionPayGateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');

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

$charge = $securionPay->createCharge($chargeRequest);
SecurionPayGateway securionPay =
		new SecurionPayGateway("pr_test_tXHm9qV9qV9bjIRHcQr9PLPa");

ChargeRequest chargeRequest = new ChargeRequest(799, "EUR")
		.card(new CardRequest(cardToken));
Charge charge = securionPay.createCharge(chargeRequest);
								var gateway = new SecurionPayGateway("pr_test_tXHm9qV9qV9bjIRHcQr9PLPa");

var chargeRequest = new ChargeRequest() { Amount = 799, Currency = "EUR",
									  Card = new CardRequest() { Id = token.Id } };
var charge = await gateway.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 and expires after 24 hours. 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:

$securionPay = new SecurionPayGateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');

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

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

CustomerRequest customerRequest = new CustomerRequest("[email protected]")
		.card(new CardRequest(tokenId));
Customer customer = securionPay.createCustomer(customerRequest);

ChargeRequest chargeRequest = new ChargeRequest(799, "EUR")
		.customerId(customer.getId());
Charge charge = securionPay.createCharge(chargeRequest);
var gateway = new SecurionPayGateway("pr_test_tXHm9qV9qV9bjIRHcQr9PLPa");

var customerRequest = new CustomerRequest() { Email = "[email protected]",
								      Card = new CardRequest() { Id = token.Id } };
var customer = await gateway.CreateCustomer(customerRequest);

var chargeRequest = new ChargeRequest() { Amount = 799, Currency = "EUR",
								          CustomerId = customer.Id };
var charge = await gateway.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.