Important: The amount should be entered without decimals. For example, 100 represents 1.00 SAR, and 1455 represents 14.55 SAR. The maximum length is 12 digits, including the exponent (e.g., 123456789012 equals 1,234,567,890.12 SAR).
Reference ID: You may pass a Reference ID in the customerReferenceNumber field to attach it to the transaction. Otherwise, set it to null.
Processing a Purchase Request Using In-App Integration
To initiate a payment using the In-App Integration method, follow the steps below. This method leverages the window.inAppPurchase handler to communicate directly within Easypay app.
Example Code:
// Function to make a payment using In-App IntegrationasyncfunctionmakePaymentInApp(amount, customerReferenceNumber) {// Check if the In-App Purchase handler is availableif (window.inAppEasypay) {constpaymentData= [ { method:"PURCHASE", amount: amount,// [Required] Amount to set (e.g., 100 represents 1.00 SAR) customerReferenceNumber: customerReferenceNumber ||null// [Optional] Any string as a reference number } ];try {// Call the In-App Purchase handler with the payment dataconstresponseJson=awaitwindow.inAppEasypay.callHandler('Purchase',...paymentData);// Simplified Error Handlingif (responseJson ==="false"|| responseJson ===null) {console.error("Payment failed: Invalid response from handler.");// Optionally, notify the user about the failurereturn; } else {constpaymentResult=JSON.parse(responseJson);if (paymentResult.is_approved) {console.log("Payment Successful:", paymentResult);// Optionally, proceed with post-payment actions } else {console.warn("Payment Rejected:", paymentResult);// Optionally, notify the user about the rejection } } } catch (error) {console.error("Exception during In-App Payment:", error);// Optionally, implement retry logic or notify the user } } else {console.error("In-App Purchase handler is not available.");// Optionally, fallback to WebSocket Integration or notify the user }}// Example usage:makePaymentInApp(100,"1234");
Refund
To process a refund, provide the transactionUuid of the original transaction you wish to refund.
Processing a Refund Using In-App Integration
To initiate a refund using the In-App Integration method, follow the steps below. This method leverages the window.inAppRefund handler to communicate directly within Easpay app.
Example Code:
// Function to process a refund using In-App IntegrationasyncfunctionprocessRefundInApp(transactionUuid, amount, customerReferenceNumber) {// Check if the In-App Refund handler is availableif (window.inAppEasypay) {constrefundData= [ { method:"REFUND", transactionUuid: transactionUuid,// [Required] Original transaction UUID. amount: amount,// [Required] Amount to refund. customerReferenceNumber: customerReferenceNumber || null // [Optional] Any string as a reference number.
} ];try {// Call the In-App Refund handler with the refund dataconstresponseJson=awaitwindow.inAppEasypay.callHandler('Refund',...refundData);// Simplified Error Handlingif (responseJson ==="false"|| responseJson ===null) {console.error("Refund failed: Invalid response from handler.");// Optionally, notify the user about the failurereturn; } else {constrefundResult=JSON.parse(responseJson);if (refundResult.is_approved) {console.log("Refund Successful:", refundResult);// Optionally, proceed with post-refund actions } else {console.warn("Refund Rejected:", refundResult);// Optionally, notify the user about the rejection } } } catch (error) {console.error("Exception during In-App Refund:", error);// Optionally, implement retry logic or notify the user } } else {console.error("In-App Refund handler is not available.");// Optionally, fallback to WebSocket Integration or notify the user }}// Example usage:processRefundInApp("f5079b9d-b61c-4180-8a4d-9780f7a9cd8f",100,"ORDER1234");
Reconciliation
Processing a Reconcile Using In-App Integration
To initiate a reconciliation using the In-App Integration method, follow the steps below. This method leverages the window.inAppRefund handler to communicate directly within Easpay app.
Example Code:
// Function to reconcile transactions using In-App IntegrationasyncfunctionreconcileInApp() {// Check if the In-App Reconcile handler is availableif (window.inAppEasypay) {constdata= {"method":"reconcile" };try {// Call the In-App Reconcile handler with the reconcile dataconstresponseData=awaitwindow.inAppEasypay.callHandler('Reconciliation', data);// Simplified Error Handlingif (responseData seJson ==="false"|| responseData ===null) {console.error("Reconciliation failed: Invalid response from handler.");// Optionally, notify the user about the failurereturn; } else {if (responseData .is_balanced !==undefined&&responseData .is_balanced.value) {console.log("Reconciliation Successful:", responseData);// Optionally, proceed with post-reconciliation actions } else {console.warn("Reconciliation Failed:", responseData);// Optionally, notify the user about the failure } } } catch (error) {console.error("Exception during In-App Reconciliation:", error);// Optionally, implement retry logic or notify the user } } else {console.error("In-App Reconcile handler is not available.");// Optionally, fallback to WebSocket Integration or notify the user }}// Example usage:reconcileInApp();
Receipt Management
Printing the Last Transaction Receipt
// Function to print the last transaction receipt using In-App IntegrationfunctionprintLastReceiptInApp() {// Check if the PrintLastResult handler is availableif (window.PrintLastResult) {constmessage=JSON.stringify({ method:"PrintLastResult" });try {// Send the print request to Easypaywindow.PrintLastResult.postMessage(message);console.log("Print request sent to Easypay."); } catch (error) {console.error("Failed to send print request:", error);// Optionally, notify the user about the failure } } else {console.error("PrintLastResult handler is not available.");// Optionally, fallback to WebSocket Integration or notify the user }}// Example usage:printLastReceiptInApp();
Summary of Core Functionalities In-App Integration