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 3 minutes 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 informations about creating charges can be found in API references.

Saving card for later use

Card tokens are one-time use only and expires after 3 minutes. 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 and use it save a card. Best way to do this is to use existing charge and save card used to create that charge as customer's card.

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

$securionPay = new SecurionPayGateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');

$firstChargeRequest = new ChargeRequest();
$firstChargeRequest->amount(799)->currency('EUR')->card($cardToken);
$firstCharge = $securionPay->createCharge($firstChargeRequest);

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

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

ChargeRequest firstChargeRequest = new ChargeRequest(799, "EUR")
		.card(new CardRequest(cardToken));
Charge firstCharge = securionPay.createCharge(firstChargeRequest);

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

ChargeRequest secondChargeRequest = new ChargeRequest(799, "EUR")
		.customerId(customer.getId());
Charge secondCharge = securionPay.createCharge(secondChargeRequest);
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);

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

var secondChargeRequest = new ChargeRequest() { Amount = 799, Currency = "EUR",
								          CustomerId = customer.Id };
var secondCharge = await gateway.CreateCharge(secondChargeRequest);

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 informations about creating customers can be found in API references.