Skip to main content

Create a CheckoutSession

Creates a CheckoutSession resource.


Endpoint

POST /checkout_sessions

Sample code

const payrexSecretApiKey = '';

const payrex = require('payrex-node')(payrexSecretApiKey);

// Create a CheckoutSession
const checkoutSession = await payrex.checkoutSessions.create({
currency: 'PHP',
// URL where your customer will be redirected after a successful payment.
success_url: 'https://your-website.com/some-url',
// URL where your customer will be redirected if they decide not to proceed with a payment
cancel_url: 'https://your-website.com/some-url',
payment_methods: ['gcash', 'card', 'maya'],
line_items: [{
name: 'Item 1',
// Amount is in cents. The sample below is 100.00.
amount: 10000,
quantity: 1,
// optional
image: 'Publicly accessible image URL'
}]
});

Parameters

customer_reference_id optional

A unique reference of the CheckoutSession aside from the id attribute. This can be an order ID, a cart ID, or similar, and can be used to reconcile the CheckoutSession with your internal system.


currency REQUIRED

A three-letter ISO currency code in uppercase. As of the moment, we only support PHP.


line_items REQUIRED

This attribute holds your customer's list of items to pay.

Show child attributes

name REQUIRED

The name of the line item. The name attribute describes the line item. It could be a product name or the service that you offer.


amount REQUIRED

The amount of the line item in a single unit. This could also be considered as a unit price.

This is a positive integer in the smallest currency unit, cents. If the line item should be ₱ 120.50, the amount should be 12050.


quantity REQUIRED

The quantity of the line item. The quantity will be multiplied by the line_item.amount to compute the final amount of the CheckoutSession.


description optional

Additional details of the line_item. If you want to add long details to the line_item, use this attribute.


image optional

The image of the line_item. This should be a publicly accessible URL. If this is not provided, PayRex will provide a default image.


metadata optional

A set of key-value pairs you can attach to the CheckoutSession and the resources created by the CheckoutSession, e.g., PaymentIntent, Payment. This can be useful for storing additional information about the PaymentIntent in a hash format.

success_url REQUIRED

The URL where your customer will be redirected after a successful payment


cancel_url REQUIRED

The URL where your customer will be redirected if they decide not to continue with the payment


expires_at optional

An epoch timestamp.

The time when the CheckoutSession will expire. Once the CheckoutSession expires, your customer can no longer complete the payment.

If this attribute is not passed, the CheckoutSession will expire in 24 hours.


payment_methods REQUIRED

The list of payment methods allowed to be processed by the CheckoutSession. Possible values are card and gcash.


description optional

An arbitrary string attached to the PaymentIntent. Useful reference when viewing paid Payment from PayRex Dashboard.


submit_type optional

This is a string that will show as the text for the pay button of the CheckoutSession. You can use this to customize the action text of the pay button.

Default value is pay.

payment_method_options optional

A set of key-value pairs that can modify the behavior of the payment method attached to the payment intent of the checkout session.

Show child attributes

card hash

Show child attribute

capture_type string

Describes the capture_type of a card payment. Possible values are automatic or manual. This is used for hold then capture feature. Please refer to this guide for more details.


allowed_bins array

Restricts the allowed card BINs for a card payment. Please refer to this guide for more details.

Returns

Returns a CheckoutSession resource.