EPoint — Apple Pay & Google Pay (JS SDK)¶
Info
Bu səhifə EPoint-in "Epoint.az - Apple Pay & Google Pay" sənədinin Markdown versiyasıdır (ictimai linki yoxdur). Bu sənəd düymələrin birbaşa sizin səhifənizə, EPoint JS SDK-sı ilə qoşulmasını izah edir. Daha sadə, iframe/webview əsaslı üsul üçün rəsmi API sənədindəki Apple Pay & Google Pay (widget) bölməsinə baxın.
Client¶
To add Apple Pay and Google Pay buttons to your web page (site) or app, you can use the code below.
HTML implementation:
<script src="https://epoint.az/js/epoint-token-pay.min.js"></script>
<google-pay-button type="pay" color="white"></google-pay-button>
<apple-pay-button type="pay" color="black"></apple-pay-button>
1. Create Payment¶
After adding buttons to the view you need to initialize them, but before that you need to create a
tokenized payment on Epoint, so all tokenized operations will be referenced to this payment. You can
get payment information by sending a request to /api/1/token/payment.
You need to add 2 parameters to the request: data, signature.
- data: base64 encoded form of your json data like below.
Fields:
public_key,amount,currency,language,order_id,description.data = base64_encode(fields_in_json)
Fields in json:
{
"public_key": "your_public_key_on_epoint",
"amount": 2.50,
"currency": "AZN",
"language": "az",
"order_id": "order id generated by your system",
"description": "Test payment"
}
signature_string = private_key + data + private_key
signature = base64_encode(sha1(signature_string))
Signature string:
signature_string = d3hjsl38sd8kdfhbcea0be04eafde9e8e2bad2fb092deyJwdWJsaWNfa2V5IjoiaTAwMDAwMDAwMSIsImFtb3VudCI6IjMwLjc1IiwiY3VycmVuY3kiOiJBWk4iLCJkZXNjcmlwdGlvbiI6InRlc3QgcGF5bWVudCIsIm9yZGVyX2lkIjoiMSJ9d3hjsl38sd8kdfhbcea0be04eafde9e8e2bad2fb092d
Example in PHP (Laravel):
$payload = [
'public_key' => 'public_key',
'amount' => 2.50,
'currency' => 'AZN',
'language' => 'az',
'order_id' => 'order id generated by your system',
'description' => 'Test payment',
];
$data = base64_encode(json_encode($payload));
$private_key = 'your_private_key';
$signature = base64_encode(sha1($private_key . $data . $private_key, 1));
$request = Http::post("https://epoint.az/api/1/token/payment", [
'data' => $data,
'signature' => $signature
]);
$response = $request->json();
Response sample:
{
"id": 9998887,
"transaction": "12345",
"rrn": "123",
"short_link": "a1b2",
"bank_order_id": "aaa111",
"total": 2.36,
"card_name": "Name",
"card_mask": "4000********1234",
"description": "test description",
"merchant_order_id": "111222333",
"other_attr": "other attributes",
"created_at": "2024-10-16 12:09:10",
"updated_at": "2024-10-16 15:00:48"
}
2. Initialize Token Payments¶
To initialize token payments you need to call the initTokenPay method with some parameters:
- payment: payment information that you created and got from Epoint
- endpoints: you need to implement Apple and Google Pay endpoints (see below)
- onError: get any errors that happened while initializing or paying
- onSuccess: get success result after payment
<script>
initTokenPay({
payment: {
id: 1,
amount: '1',
},
endpoints: {
apple: {
session: '/epoint/apple/session',
pay: '/epoint/apple',
},
google: {
pay: '/epoint/google',
}
},
onError: function (error) {
console.log({error})
},
onSuccess: function (success) {
console.log({success})
}
});
</script>
Apple Pay implementation¶
You need to implement 2 endpoints for the Epoint token pay SDK for Apple Pay:
- Session: Apple Pay has an additional layer for which you must create an endpoint that gets a session from Epoint and provides it to the Epoint token pay SDK.
- Pay: you need to create an endpoint for completing the payment after the session is successfully created and your user validates the Apple Pay popup (choose card, confirm pay).
3. Apple Pay Session¶
You can get a session by sending a request to /api/1/token/apple/session. Create a POST
endpoint on your backend and just return the response from Epoint.
You need to add 2 parameters to the request: data, signature.
- data: base64 encoded form of your json data like below.
Fields:
public_key,origin.data = base64_encode(fields_in_json)
Fields in json:
{
"public_key": "your_public_key_on_epoint",
"origin": "https://yoursite.az"
}
signature_string = private_key + data + private_key
signature = base64_encode(sha1(signature_string))
Example:
$payload = [
'public_key' => $public_key,
'origin' => request()->header('origin')
];
$data = base64_encode(json_encode($payload));
$signature = base64_encode(sha1($private_key . $data . $private_key, 1));
$request = Http::post("$api_url/token/apple/session", [
'data' => $data,
'signature' => $signature
]);
4. Apple Pay Payment¶
You can complete the payment by sending a request to /api/1/token/apple/pay. Create a POST
endpoint on your backend and just return the response from Epoint.
You need to add 2 parameters to the request: data, signature.
- data: base64 encoded form of your json data like below.
Fields:
public_key,id,token,billingContact. You will just addpublic_keymanually; other fields will come from the request (see example).data = base64_encode(fields_in_json)
Fields in json:
{
"public_key": "your_public_key_on_epoint",
"id": "id_from_request",
"token": "token_from_request",
"billingContact": "billingContact_from_request"
}
signature_string = private_key + data + private_key
signature = base64_encode(sha1(signature_string))
Example:
$payload = [
'public_key' => $public_key,
'id' => $request->get('id'),
'token' => $request->get('token'),
'billingContact' => $request->get('billingContact'),
];
$data = base64_encode(json_encode($payload));
$signature = base64_encode(sha1($private_key . $data . $private_key, 1));
$request = Http::post("$api_url/token/apple/pay", [
'data' => $data,
'signature' => $signature
]);
4.1. Google Pay Payment¶
It is the same as with Apple Pay, just the endpoint changes.
You can complete the payment by sending a request to /api/1/token/google/pay. Create a POST
endpoint on your backend and just return the response from Epoint.
You need to add 2 parameters to the request: data, signature.
- data: base64 encoded form of your json data like below.
Fields:
public_key,id,token,billingContact. You will just addpublic_keymanually; other fields will come from the request (see example).data = base64_encode(fields_in_json)
Fields in json:
{
"public_key": "your_public_key_on_epoint",
"id": "id_from_request",
"token": "token_from_request",
"billingContact": "billingContact_from_request"
}
signature_string = private_key + data + private_key
signature = base64_encode(sha1(signature_string))
Example:
$payload = [
'public_key' => $public_key,
'id' => $request->get('id'),
'token' => $request->get('token'),
'billingContact' => $request->get('billingContact'),
];
$data = base64_encode(json_encode($payload));
$signature = base64_encode(sha1($private_key . $data . $private_key, 1));
$request = Http::post("$api_url/token/google/pay", [
'data' => $data,
'signature' => $signature
]);
Finish payment response sample:
{
'status' => 'success',
'message' => 'Payment is finished successfully',
'result' => {}, // response from psp
'redirect_url' => '' // optional -> sometimes not exists
}