Signing Initiate Request
Generate A Key Pair
Before using SPS you'll need to generate a RSA private and public key. The public key will be exchanged with the SPS dev team and an API key will be assigned. The private key is used to create a signature that is sent with the /v1/initiate request.
# Generate a 2048-bit private key
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
# Extract the public key from the private key
openssl rsa -pubout -in private_key.pem -out public_key.pem
PHP Example /v1/initiate
Example PHP code for signing and making the /v1/initiate request to SPS. The response is an initiateResponse which contains the session token. The token is used to display the payment page to the guest to complete the reservation payment.
Example
<?php
$initiate = file_get_contents('initiate.json');
$spsEndpoint = 'https://checkout.rescms-secure.com';
$apiKey = "<YOUR_API_KEY>";
// Sign the request
$signature = null;
$pkeyid = openssl_pkey_get_private(file_get_contents('private_key.pem'));
openssl_sign($initiate, $signature, $pkeyid, OPENSSL_ALGO_SHA256);
openssl_free_key($pkeyid);
$signature = base64_encode($signature);
echo $signature . "\n\n";
// Initiate the session with SPS
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $spsEndpoint . '/v1/initiate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $initiate);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-SPS-Signature: ' . $signature,
'Content-Type: application/json',
'x-api-key: ' . $apiKey,
'grpc-metadata-x-api-key: ' . $apiKey,
));
$json = curl_exec($ch);
curl_close($ch);
$data = json_decode($json);
// Redirect the guest to /$token
$url = $spsEndpoint . '/' . $data->token;
echo $url . "\n\n";