Documentation
Quickly integrate SmartPayLive into your platform.
Custom API Integration
Integrate and receive payments securely from our payment platform.
Introduction
Common request structure
Common response structure
Authentication
Request payment
Check payment status
Cancel payment
Webhook
Conduct security checks
Class libraries
Introduction
The SmartPayLive API is organized around REST and all API calls are POST requests. The POST body contains credentials as well as the request parameters, formatted in JSON. The response is a JSON-formatted string containing status codes as well as the response data.
https://api.smartpaylive.com/api/V1/
http://devapi.smartpaylive.com/api/V1/
Common request structure
The common request structure is laid out as follows:
{
"Credentials": {
"ChannelName": "<Channel-Name>",
"ChannelHash": "<Channel-Hash>",
"Timestamp": "<Current-Timestamp>",
"RequestReference": "<Request-Reference>"
},
"OriginatingIpAddress": "<Client-IP>",
"ClientVersion": "<Client-Version>",
"Request": {}
}
Common response structure
The common response structure is laid out as follows:
{
"Response": {},
"Succeeded": true,
"ErrorCode": null,
"ErrorMessage": null,
"RequestId": "3dde5697-c576-42fb-af4f-9c5cbe26bb32",
"ProcessingTimeMS": 62
}
Authentication
Authentication is done by providing credentials object with each API request. The credentials object consists of following fields:
UpperCaseString(SHA256(AES192CBC(ChannelName + Timestamp + ChannelPassword + RequestReference, ChannelPassword)))
function generateChannelHash($channelName, $channelPassword, $timestamp, $requestReference) {
$data = $channelName . $timestamp . $channelPassword . $requestReference;
$encryptionMethod = "aes-192-cbc";
$iv = str_repeat(chr(0x0), 16);
$encryptedData = openssl_encrypt($data, $encryptionMethod, $channelPassword, OPENSSL_RAW_DATA, $iv);
return strtoupper(hash("sha256", $encryptedData));
}
Request payment
This API provides Merchants with the ability to receive money from their customers.
Request parameters
Response
{
"Credentials": {
"ChannelName": "<Channel-Name>",
"ChannelHash": "<Channel-Hash>",
"Timestamp": "<Current-Timestamp>",
"RequestReference": "<Request-Reference>"
},
"OriginatingIpAddress": "<Client-IP>",
"ClientVersion": "<Client-Version>",
"Request": {
"IntegratorTransactionReference": "1122334455",
"IntegratorCustomerId": "321321",
"Amount": "100",
"IntegratorRedirectUrl": "http://example.com/complete",
"CustomerEmailAddress": "customer-name@example.com",
"CancelRedirectUrl": "http://example.com/cancel"
}
}
{
"Response": {
"PaymentRequestId": "0cc9ad66-9758-4279-a022-9b26f720ba7c",
"PaymentUrl": "http://devweb.smartpaylive.com/payment/0cc9ad66-9758-4279-a022-9b26f720ba7c",
"PaymentReference": "OP007H9W"
},
"Succeeded": true,
"ErrorCode": null,
"ErrorMessage": null,
"RequestId": "d9796ff5-b6ee-46a3-9fa1-b85c9fe5d2cd",
"ProcessingTimeMS": 106
}
Check payment status
This API helps Merchants check the payment status.
Request parameters
Response
- 1: Requested
- 2: In Progress
- 3: Completed Successfully
- 4: Canceled
- 5: Failed
{
"Credentials": {
"ChannelName": "<Channel-Name>",
"ChannelHash": "<Channel-Hash>",
"Timestamp": "<Current-Timestamp>",
"RequestReference": "<Request-Reference>"
},
"OriginatingIpAddress": "<Client-IP>",
"ClientVersion": "<Client-Version>",
"Request": {
"PaymentRequestId": "f04e76c3-2290-4a1e-8195-d9727678c2a8"
}
}
{
"Response": {
"Status": 3,
"AmountRequested": 100.00,
"RequestedByIntegratorName": "<Channel-Name>",
"IntegratorTransactionReference": "1122334455",
"IntegratorLogoUrl": "http://devapi.smartpaylive.com/media/defaultmerchant.png",
"RedirectUrl": "http://example.com/complete",
"PaymentReference": "OP007H9W",
"PaymentUrl": "http://devweb.smartpaylive.com/payment/0cc9ad66-9758-4279-a022-9b26f720ba7c",
"CancelRedirectUrl": "http://example.com/cancel",
"RecurringPaymentsRequested": 0,
"RecurringPaymentsCompleted": 0,
"RecurringPaymentsRemaining": 0
},
"Succeeded": true,
"ErrorCode": null,
"ErrorMessage": null,
"RequestId": "0f677604-e38d-4840-a466-5f246488bb33",
"ProcessingTimeMS": 16
}
Cancel payment
This API provides Merchants with the ability to cancel the payment. If the payment still has a number of recurring requests remaining, these will no longer be requested.
Request parameters
{
"Credentials": {
"ChannelName": "<Channel-Name>",
"ChannelHash": "<Channel-Hash>",
"Timestamp": "<Current-Timestamp>",
"RequestReference": "<Request-Reference>"
},
"OriginatingIpAddress": "<Client-IP>",
"ClientVersion": "<Client-Version>",
"Request": {
"PaymentRequestId": "2dcd39c4-c18e-45f9-b459-60ea57fc6e4f",
"CancellationReason": "Your reason for cancellation"
}
}
{
"Response": {},
"Succeeded": true,
"ErrorCode": null,
"ErrorMessage": null,
"RequestId": "3dde5697-c576-42fb-af4f-9c5cbe26bb32",
"ProcessingTimeMS": 62
}
Webhook
When a payment is successfully completed, the payment gateway will notify the Merchant by performing an HTTP POST to an endpoint in the Merchant’s environment. This allows the Merchant to be notified of payments without having to query the status of each pending payment. The information posted to the webhook endpoint is as follows:
Arguments
- 1: Requested
- 2: In Progress
- 3: Completed Successfully
- 4: Canceled
- 5: Failed
{
"PaymentRequestId": "0cc9ad66-9758-4279-a022-9b26f720ba7c",
"IntegratorTransactionReference": "1122334455",
"PaymentStatus": 3,
"AmountRequested": 100.00,
"Fee": 2.3,
"NetAmount": 97.7,
"DateCompletedUTC": "2021-04-20T12:14:01.7878431Z",
"PaymentMethod": 2,
"NumRecurringPaymentsRemaining": 0
}
Conduct security checks
Conduct following four security checks to ensure that the data you are receiving in webhook is correct, from the correct source and has not been altered; you should not continue the process if a test fails!
-
Check if payment was requested by your (Merchant’s) systemValidate request identifierPHP
function validateRequestId($paymentRequestId, $orderPaymentRequestId) { return $paymentRequestId === $orderPaymentRequestId; }
-
Compare payment amountValidate payment amountPHP
function validatePaymentAmount($amountRequested, $orderTotal) { return (float)$amountRequested == (float)$orderTotal; }
-
Check that the notification has come from a valid SmartPayLive domainValidate IPPHP
function validateIP() { $validSmartPayIPs = [ '41.185.80.146', '41.185.18.98', '41.185.18.99' ]; $referrerIP = $_SERVER['REMOTE_ADDR']; return in_array($referrerIP, $validSmartPayIPs, true); }
-
Perform server request to /QueryStatus API to confirm the detailsValidate payment statusPHP
function validatePaymentStatus($channelName, $channelPassword, $paymentRequestId, $paymentStatus) { // SmartPay class is available in our PHP class library, you can download it from https://smartpaylive.com/downloads/SmartPay.zip $smartPay = new SmartPay($channelName, $channelPassword); $status = $smartPay->queryStatus($paymentRequestId); if (!is_null($status) && $status->Succeeded == true) { if ($status->Response->Status == $paymentStatus && $paymentStatus == 3) { return true; } } return false; }
Bringing all the checks togetherPHP$requestIdCheck = validateRequestId($webhookPayload->PaymentRequestId, $orderDetails->PaymentRequestId); $paymentAmountCheck = validatePaymentAmount($webhookPayload->AmountRequested, $orderDetails->OrderTotal); $validIpCheck = validateIP(); $validPaymentStatusCheck = validatePaymentStatus($channelName, $channelPassword, $webhookPayload->PaymentRequestId, $webhookPayload->PaymentStatus); if ($requestIdCheck && $paymentAmountCheck && $validIpCheck && $validPaymentStatusCheck) { // All checks have passed } else { // Some checks have failed, check payment manually and log for investigation }