Triggers the native checkout flow for payment processing.
Payment transaction details, including the transaction ID and amount.
The checkout result, containing transaction status (success, failure, or pending) and transaction details.
Simple usage
import { CheckoutModule, isSuccess, isErrorResponse } from '@grabjs/superapp-sdk';
// Initialize the checkout module
const checkout = new CheckoutModule();
// Trigger checkout with response params
const transactionResponse = await createTransaction(); // Call POST /grabpay/partner/v4/charge/init from Grab API to create a transaction
const response = await checkout.triggerCheckout(transactionResponse);
// Handle the response
if (isSuccess(response)) {
console.log('Transaction ID:', response.result.transactionID);
switch (response.result.status) {
case 'success':
console.log('Transaction successful');
break;
case 'failure':
console.log('Transaction failed:', response.result.errorMessage, response.result.errorCode);
break;
case 'pending':
console.log('Transaction pending');
break;
case 'userInitiatedCancel':
console.log('User cancelled the checkout');
break;
}
} else if (isErrorResponse(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
JSBridge module for triggering native payment flows.
Remarks
Invokes the native Grab checkout/pay component to process payments. This code must run on the Grab SuperApp's WebView to function correctly.
Example
ES Module:
Example
CDN (UMD):