The Payment Intent represents an intention to complete a payment. You can create a Payment Intent by specifying key details like the payment amount, the customer, and the payment method.

General Workflow

To create a payment intent, you generally follow these steps:

  1. Specify the amount the customer needs to pay.
  2. Optionally, provide additional information such as the customer details, payment methods, and redirect URLs.
  3. Receive a link to the payment page, where the customer can complete the payment.

Scenarios for Creating a Payment Intent

1. Creating a Payment Intent with Just Amount

In this simplest scenario, you only need to provide the amount that needs to be paid. This is the most basic setup for a payment.

  • Scenario: You want to create a payment intent for a customer to pay GMD 450, but you do not specify a customer or any other optional parameters.
  • Request:
const paymentIntent = await modempay.paymentIntents.create({ amount: 450 });
  • Result: A Payment Intent is created with a link to the payment page, where the customer can complete the payment.
{
  "status": true,
  "message": "Payment intent created successfully. Please proceed to complete the payment.",
  "data": {
    "intent_secret": "8816a8e679d9df252fa80d09ebe21efaa3a8980cb053cb64afeed44c5df696f4",
    "payment_link": "https://test.checkout.modempay.com/6b63ccef-0232-4be1-b53d-be6823767874",
    "amount": 450,
    "currency": "GMD",
    "expires_at": "2025-02-13T12:31:15.601Z",
    "status": "requires_payment_method"
  }
}

2. Creating a Payment Intent with Amount and Customer

In this scenario, in addition to specifying the amount, you also specify the customer who will be making the payment. This helps associate the payment with a particular customer for better tracking.

  • Scenario: You want to create a payment intent for GMD 450 and associate it with a specific customer.
  • Request:
const paymentIntent = await modempay.paymentIntents.create({
    amount: 450,
    customer: "d9bf8831-4db5-4a1c-8aa0-3de72492f330",
});

3. Creating a Payment Intent with Amount, Customer, and Payment Methods

This scenario involves a more specific setup where you specify the amount, associate the intent with a customer, and predefine the payment methods the customer will use. This is useful when you want to guarantee specific methods of payment.

  • Scenario: You want to create a payment intent for GMD 450, associate it with a customer, and specify that the payment should be processed using a particular payment method.
  • Request:
const paymentIntent = await modempay.paymentIntents.create({
    amount: 450,
    customer: "d9bf8831-4db5-4a1c-8aa0-3de72492f330",
    payment_methods: ["card"],
});

4. Creating a Payment Intent with Amount, Customer, and Specific Payment Method ID

In this scenario, you create a Payment Intent specifying a particular customer’s payment method ID. This is useful when you want to charge a customer using a specific saved payment method, such as a stored card or bank account.

  • Scenario: You want to create a payment intent for GMD 450, associate it with a specific customer, and use a specific saved payment method ID from the customer’s account. This setup allows you to charge a saved payment method directly, streamlining the payment process for returning customers.

  • Request:

const paymentIntent = await modempay.paymentIntents.create({
    amount: 450,
    payment_method: "ad47ccb9-687c-475b-90dc-1dd3b4cba68e",
    customer: "d9bf8831-4db5-4a1c-8aa0-3de72492f330",
});

Common Optional Parameters for Creating a Payment Intent

While the amount is the only required parameter for creating a payment intent, you can optionally include other parameters to enhance the payment flow:

  • currency: The currency for the payment (optional). If omitted, the default currency will be used.
  • title: A title for the payment (optional).
  • description: A description of the payment (optional).
  • metadata: Any additional custom data (optional).
  • return_url: A URL to which the customer will be redirected after completing the payment (optional).
  • cancel_url: A URL to which the customer will be redirected if they cancel the payment (optional).
  • payment_methods: A list of accepted payment methods (optional).

Conclusion

Creating a Payment Intent is a straightforward process. By specifying just the amount, or additionally associating the intent with a customer and payment method, you can tailor the payment flow to meet specific needs. Once created, you will receive a unique link that the customer can use to complete the payment. This flexible setup ensures a seamless payment experience.