Triggers the native checkout flow for payment processing.
Payment transaction details, including the transaction ID and amount. See TriggerCheckoutRequest.
The checkout result, containing transaction status (success, failure, pending, or userInitiatedCancel) and transaction details. See TriggerCheckoutResponse.
You must create a transaction on your backend (via API POST https://partner-api.grab.com/grabpay/partner/v4/charge/init) before calling this method.
Pass the transaction parameters returned from that API call as the request argument.
Calling this method without a valid pre-created transaction will result in a checkout failure.
Simple usage
import { CheckoutModule, isSuccess, isError } 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 (isError(response)) {
switch (response.status_code) {
case 403:
console.log('No permission to trigger checkout');
// Trigger IdentityModule.authorize() for scope 'mobile.checkout', then reload via ScopeModule.reloadScopes() and try again
break;
default:
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):