const cart = await grantex.commerce.createCart({
idempotencyKey: crypto.randomUUID(),
merchant_id: 'mch_shopify_mgx0n6_22',
currency: 'INR',
line_items: [{ variant_id: 'cvar_...', quantity: 1 }],
});
const consent = await grantex.commerce.createConsentRequest({
merchant_id: 'mch_shopify_mgx0n6_22',
passport_type: 'checkout',
max_amount: Number(cart.data['total_amount']),
currency: 'INR',
});
// Redirect the buyer to consent.data['consent_url'] and exchange only after
// the consent is granted.
const passport = await grantex.commerce.exchangeConsentForPassport({
consent_request_id: String(consent.data['consent_request_id']),
});
const payment = await grantex.commerce.createPaymentIntent({
idempotencyKey: crypto.randomUUID(),
merchant_id: 'mch_shopify_mgx0n6_22',
cart_id: String(cart.data['cart_id']),
passport_jwt: String(passport.data['passport_jwt']),
amount_minor_units: Number(cart.data['total_amount']),
currency: 'INR',
provider_key: 'plural',
});
const checkout = await grantex.commerce.createCheckoutLink(
String(payment.data['payment_intent_id']),
{
idempotencyKey: crypto.randomUUID(),
passport_jwt: String(passport.data['passport_jwt']),
success_url: 'https://buyer.example/success',
cancel_url: 'https://buyer.example/cancel',
},
);