Installment Tracker

Handle the installment_tracker object in the order.updated webhook event and process approved, pending, and rejected installment decisions.

The installment_tracker object tracks the issuer bank's decision on an installment request. It is returned inside the order.updated webhook event with one of three statuses: approved, rejected, or pending.

Approved Installment

"installment_tracker": {
  "id": "70414",
  "status": "A",
  "message": null
}

Rejected Installment

"installment_tracker": {
  "id": "70321",
  "status": "R",
  "message": "Error Message"
}

Pending Installment

"installment_tracker": {
  "id": "70321",
  "status": "P",
  "message": null
}
💡

Check the status field to determine your next action: process the order on A, retry or wait on P, and surface the message to your support team on R.

Handle installment tracker updates

Use the installment_tracker object in your order.updated handler to decide whether to fulfill the order, wait for another update, or escalate the rejection reason.

async function handleOrderUpdated(webhook) {
  try {
    const installmentTracker = webhook?.data?.installment_tracker;

    if (!installmentTracker) {
      console.log('No installment tracker found for this event.');
      return { status: 'ignored' };
    }

    const { id, status, message } = installmentTracker;

    switch (status) {
      case 'A':
        // Mark the order as ready for fulfillment after the issuer bank approves the installment request.
        console.log(`Installment approved for tracker ${id}`);
        return { status: 'approved', tracker_id: id };

      case 'P':
        // Keep the order in a waiting state until Amwal sends the next update.
        console.log(`Installment pending for tracker ${id}`);
        return { status: 'pending', tracker_id: id };

      case 'R':
        // Record the rejection reason so your operations or support team can review it.
        console.error(`Installment rejected for tracker ${id}: ${message || 'No rejection message provided'}`);
        return {
          status: 'rejected',
          tracker_id: id,
          message: message || 'No rejection message provided'
        };

      default:
        console.warn(`Unknown installment status for tracker ${id}: ${status}`);
        return { status: 'unknown', tracker_id: id, raw_status: status };
    }
  } catch (error) {
    console.error('Failed to process installment tracker:', error.message);
    return { status: 'error', message: error.message };
  }
}

const webhookPayloads = [
  {
    event_type: 'order.updated',
    data: {
      installment_tracker: {
        id: '70414',
        status: 'A',
        message: null
      }
    }
  },
  {
    event_type: 'order.updated',
    data: {
      installment_tracker: {
        id: '70321',
        status: 'P',
        message: null
      }
    }
  },
  {
    event_type: 'order.updated',
    data: {
      installment_tracker: {
        id: '70322',
        status: 'R',
        message: 'Issuer bank rejected the installment request'
      }
    }
  },
  {
    event_type: 'order.updated',
    data: {}
  }
];

async function runExamples() {
  for (const payload of webhookPayloads) {
    const result = await handleOrderUpdated(payload);
    console.log('Processing result:', result);
  }
}

runExamples();

Expected output:

Installment approved for tracker 70414
Processing result: { status: 'approved', tracker_id: '70414' }
Installment pending for tracker 70321
Processing result: { status: 'pending', tracker_id: '70321' }
Installment rejected for tracker 70322: Issuer bank rejected the installment request
Processing result: {
  status: 'rejected',
  tracker_id: '70322',
  message: 'Issuer bank rejected the installment request'
}
No installment tracker found for this event.
Processing result: { status: 'ignored' }

Field Reference

Field

Type

Description

id

string

Unique identifier for the installment tracker.

status

string

A = Approved | P = Pending | R = Rejected

message

string | null

null when the status is approved or pending. Contains the rejection reason when the status is R.