PATRON.
Backend Integration
• 15 Minutes Setup

Building a Single Discount Cart Checkout Integration

Learn how to validate subscriber perk eligibility via server API and apply flat or percentage discounts to an order subtotal during backend checkout processing.

Select Tech Framework:

Step 1: Execute Member Validation POST Query (JS)

Call POST /api/merchant/qr-validate with your secret API key:

const response = await fetch('https://www.patron.com.ng/api/merchant/qr-validate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ptr_test_YOUR_API_KEY'
  },
  body: JSON.stringify({
    member_identifier: 'test.student@patron-sandbox.ng',
    perk_id: 'prk_student_20'
  })
});

const data = await response.json();

Step 2: Calculate Cart Subtotal Discount

Calculate the discount deduction and update order totals:

function calculateFinalTotal(orderSubtotalNaira, perk) {
  let discountNaira = 0;
  
  if (perk.discount_percent) {
    discountNaira = orderSubtotalNaira * (perk.discount_percent / 100);
  }
  
  const finalOrderTotal = orderSubtotalNaira - discountNaira;
  return { finalOrderTotal, discountNaira };
}

Step 3: Confirm Purchase Completion via Webhook

When the order is paid, post audit figures to POST /api/merchant/purchase-webhook:

await fetch('https://www.patron.com.ng/api/merchant/purchase-webhook', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ptr_test_YOUR_API_KEY'
  },
  body: JSON.stringify({
    merchant_email: 'store@merchant.com',
    redemption_id: data.redemption_id,
    order_total: 25000,
    discount_amount_applied: 5000
  })
});