Skip to main content

Direct Apple Integration

This feature allows merchants to integrate Apple Pay directly on their website, eliminating the need to redirect to the Hesabe payment landing page. Below are the steps to implement the integration:

Steps to Implement:

1. Contact Hesabe IT Team

-Request the Hesabe IT team at itsupport@hesabe.com to whitelist your merchant domain.

-Once whitelisted, Hesabe will provide an Apple Domain Verification Value.

-This file needs to be added on your website’s hosting server in the following path:

{MerchantWebsite}/.well-known/apple-developer-merchantid-domain-association.txt

2. Create a Checkout Request

Send a checkout request with the required parameters. Ensure to follow Hesabe’s guidelines on the parameters needed for the request.

Parameters

NameDescriptionConditionType/Length
amountAmount must be greater than zeroRequiredNumeric
responseUrlWebpay will be redirected back to this URL after payment completesRequiredAlphanumeric (200) Characters allowed: Alphabet (A-Z), (a-z), Numbers, /, _
failureUrlWebpay will be redirected back to this URL after payment is declinedRequiredAlphanumeric (200) Characters allowed: Alphabet (A-Z), (a-z), Numbers, /, _
merchantCodeMerchant Code is a unique identifier generated by Hesabe for each activated merchant.RequiredNumeric
access_codeAccess code is used to revalidate a Merchant. To be used only for Indirect Integration.RequiredAlphanumeric [32]
paymentTypePayment Type: 9 - ApplePay-Visa/Master, 11 - ApplePay-KnetRequiredNumeric
versionVersion of the API (example: 2.0)RequiredAlphanumeric [10]
variable1Custom user parameter which will be included in the response when it returnsOptionalAlphanumeric [100]
variable2Custom user parameter which will be included in the response when it returnsOptionalAlphanumeric [100]
variable3Custom user parameter which will be included in the response when it returnsOptionalAlphanumeric [100]
variable4Custom user parameter which will be included in the response when it returnsOptionalAlphanumeric [100]
variable5Merchant Domain Name as example.comRequiredValid Domain

Code Example

$baseUrl =  "http://sandbox.hesebe.com/api/";
$CaptureApiUrl = "{$baseUrl}/checkout";
$requestData = [
"merchantCode" => "842217",
"amount" => "2",
"serviceTypeId" => "3",
"paymentType" => "9",
"responseUrl" => "https://sandbox.hesabe.com/customer-response?id=842217",
"failureUrl" => "https://sandbox.hesabe.com/customer-response?id=842217",
"version" => "2.0",
"orderReferenceNumber" => "9874659805",
"currency" => "KWD",
"description" => "authorize transaction",
"name" => "customername",
"email" => "customeremail@gmail.com",
"mobile_number" => "98758889",
"variable1" => "First__variable",
"variable2" => "Second__variable",
"variable3" => "Third__variable",
"variable4" => "forth__variable",
"variable5" => "example.com"
];

$encryptedData = HesabeCrypto::encrypt($requestData, $encryptionKey, $ivKey);
$checkoutRequestData = new Request([
'data' => $encryptedData
]);

$checkoutRequest = Request::create($CaptureApiUrl, 'POST', $checkoutRequestData->all());
$checkoutRequest->headers->set('accessCode', $accessCode);

3. Decrypt the Response

Decrypt the response returned from the checkout request using the same encryption library used for encryption during the request.

$checkoutResponse = Route::dispatch($checkoutRequest);
$checkoutResponseContent = $checkoutResponse->content();
$decryptedResponse = HesabeCrypto::decrypt($checkoutResponseContent, $encryptionKey, $ivKey);
$responseDataJson = json_decode($decryptedResponse);

4.Invoking Hesabe Apple Pay Script on the Merchant's Website Checkout/Payment Page

$baseUrl =  "http://sandbox.hesebe.com";
$hesabetoken= $responseDataJson->response->data;
<script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"></script>
<script src="{$baseUrl}/applepay?data={$hesabetoken}"></script>

5. Set Up the Apple Pay Button Add an Apple Pay button to your checkout page.

Make sure to follow the official Apple Pay guidelines for styling and branding.

6. Add an ID Attribute Ensure the Apple Pay button has an id attribute assigned to it. This will be necessary for Apple Pay to initialize correctly.

7. Apple Pay Initialization The Apple Pay button will only be displayed and functional on Apple Pay-capable devices. Ensure your code handles this condition appropriately.

By following these steps, you can integrate Apple Pay directly into your website's checkout process, providing a seamless experience for your customers.