Integrating With Your Webhook


Next Page: Webhook Integration
Previous Page: Indirect Integration


Direct Apple Pay 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

Name Description Condition Type/Length
amount Amount must be greater than zero Required Numeric
responseUrl Webpay will be redirected back to this URL after payment completes Required Alphanumeric (200) Characters allowed: Alphabet (A-Z), (a-z), Numbers, / (slash), _ (underscore)
failureUrl Webpay will be redirected back to this URL after payment is declined Required Alphanumeric (200) Characters allowed: Alphabet (A-Z), (a-z), Numbers, / (slash), _ (underscore)
merchantCode Merchant Code is a unique identifier generated by Hesabe for each activated merchant. Required Numeric
access_code Access code is used to revalidate a Merchant. To be used only for Indirect Integration. Required Alphanumeric [32]
paymentType Payment Type: 9 - ApplePay-Visa/Master, 11 - ApplePay-Knet Required Numeric
version Version of the API (example: 2.0) Required Alphanumeric [10]
variable1 Custom user parameter which will be included in the response when it returns Optional Alphanumeric [100]
variable2 Custom user parameter which will be included in the response when it returns Optional Alphanumeric [100]
variable3 Custom user parameter which will be included in the response when it returns Optional Alphanumeric [100]
variable4 Custom user parameter which will be included in the response when it returns Optional Alphanumeric [100]
variable5 Merchant Domain Name as example.com Required Valid 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.




Next Page: HesabeRequestHandler
Previous Page: Access Keys