The Modem Pay SDK provides straightforward methods to manage Payment Intents beyond creating them, allowing you to cancel, retrieve, and list Payment Intents easily.


Cancel a Payment Intent

If a payment session is no longer needed, you can cancel a Payment Intent. Once canceled, the Payment Intent can’t be completed, which is useful for handling expired or abandoned payments.

Parameters:

  • id (string): The unique identifier of the Payment Intent you wish to cancel.
const paymentIntent = await modempay.paymentIntents.cancel(
    "49ac6595-beba-480f-bc3d-33e5d4162c4c"
);

Response: Returns the canceled Payment Intent object, updating its status to "cancelled".

{
  ...
  "status": "cancelled"
}

Retrieve a Payment Intent

To check the current status or details of an existing Payment Intent, you can retrieve it by the secret. This is especially useful for confirming the progress or outcome of a payment attempt.

Parameters:

  • intent_secret (string): The unique secret of the Payment Intent you’re retrieving.
const paymentIntent = await modempay.paymentIntents.retrieve(
    "bfa7eb3ea516ee15f80915a922c00242a77629eb5b1efe34048b83a61925bbf5"
);

Response: Returns the Payment Intent object, including attributes such as:

  • status: Shows if the intent is "initialized", "processing", "successful", etc.
  • amount, currency, description: Reflects the payment details initially set.
  • link: The unique payment link for the intent.
  • customer: Linked customer details, if available.

List Payment Intents

To view a collection of recent Payment Intents, use the list method. This is ideal for tracking activity, viewing recent payment attempts, or obtaining an overview of intents by status.

Parameters:

  • limit (number, optional): The number of Payment Intents to retrieve (default is typically 10).
const paymentIntents = await modempay.paymentIntents.list({ limit: 10 });

Response:

{
  "data": [],
  "meta": {
    "total": 31
  }
}