Payment In-App Integration
Purchase
Processing a Purchase Request Using In-App Integration
// Function to make a payment using In-App Integration
async function makePaymentInApp(amount, customerReferenceNumber) {
// Check if the In-App Purchase handler is available
if (window.inAppEasypay) {
const paymentData = [
{
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 data
const responseJson = await window.inAppEasypay.callHandler('Purchase', ...paymentData);
// Simplified Error Handling
if (responseJson === "false" || responseJson === null) {
console.error("Payment failed: Invalid response from handler.");
// Optionally, notify the user about the failure
return;
} else {
const paymentResult = 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
Processing a Refund Using In-App Integration
Reconciliation
Processing a Reconcile Using In-App Integration
Receipt Management
Summary of Core Functionalities In-App Integration
Functionality
In-App Integration
Last updated