Payment Intents

A `PaymentIntent` resource is used to track and handle different states of the payment until it succeeds.

The Payment Intent Resource

A PaymentIntent resource is used to track and handle different states of the payment until it succeeds. To learn how to receive credit/debit card payments using PaymentIntent, you can check this section. To learn how to receive PayMaya payments using PaymentIntent, you can check this section.

More Details

Creating a Payment Intent

/**
 * These are the required properties
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {number} data.attributes.amount Amount to be collected by the PaymentIntent.
 * @param {string[]} data.attributes.payment_method_allowed The list of payment method types that the PaymentIntent is allowed to use. Possible value is card for now.
 * @param {string} data.attributes.currency Three-letter ISO currency code, in uppercase. PHP is the only supported currency as of the moment.
 */
const result = await paymongo.paymentIntents.create(data);

Payload

{
  data: {
    attributes: {
      amount: 10000, // 10000 or 100 in money value is the smallest allowed amount.
      currency: 'PHP', // Three-letter ISO currency code. Only supports PHP for now.
      payment_method_allowed: ['card'] // The only available value for now is 'card'.
    }
  }
}

Retrieving a Payment Intent

/**
 * @param {string} id PaymentIntent id
 */
const result = await paymongo.paymentIntents.retrieve(id);

Attach to PaymentIntent

/**
 * These are the required properties
 * @param {string} id PaymentIntent id.
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {string} data.attributes.payment_method Id of PaymentMethod to attach to the PaymentIntent.
 */
const result = await paymongo.paymentIntents.attach(id, data);

Payload

{
  data: {
    attributes: {
      payment_method: 'abc123'
    }
  }
}

Capture a PaymentIntent

/**
 * @param {string} secret API private key
 * @param {string} id PaymentIntent id
 */
const result = await paymongo.paymentIntents.capture(id);

Cancel a PaymentIntent

/**
 * @param {string} secret API private key
 * @param {string} id PaymentIntent id
 */
const result = await paymongo.paymentIntents.cancel(id);

Last updated