Skip to main content

Create a Checkout

Below is an example of how to create a PlanPay checkout through an API request. Keep the following in mind:

  • The checkout has been created using the development sandbox endpoint for the checkout API.
  • All required properties have been filled with example data. The meaning of these properties is explained in the Checkout API Schema tables.
  • An Authorization header is included in the request, following the instructions provided in the API keys section.
  • Please note that this is just an example, and many of the properties shown are optional. For a full list of available configurations, see the checkout schema tables.
info

Check out the Authentication and Authorization section to learn how to generate the Authorization header.

type
string
Default: "plan"
Value: "plan"

A property that specifies the type of checkout requested. Only plan is currently supported.

merchantId
required
string [ 5 .. 256 ] characters ^((?! ).)*$

The merchant's unique ID provided by PlanPay. Must match the merchant ID value from the Authorization header provided with the request. Example: 8b4f37d2e6a1.

externalCode
string [ 5 .. 128 ] characters ^((?! ).)*$

Merchants can use externalCode to identify a specific sub-merchant. For example, a merchant may have properties in different locations, such as Sydney with an externalCode of SYD and New York with an externalCode of NYC. The externalCode must match one of the sub-merchant externalCode values that they have configured via the portal.

merchantOrderId
required
string [ 1 .. 256 ] characters ^((?! ).)*$

The unique order ID in the merchant's order database. Example: YCPNY-J6P7VZ.

currencyCode
required
string = 3 characters ^((?! ).)*$

The ISO 4217 currency code used for the transaction. Example: provide USD for United States dollar.

redirectURL
required
string <uri> [ 5 .. 2048 ] characters ^((?! ).)*$

A URL on the merchant's website to redirect the customer back to once the transaction has been completed or rejected. Should be a HTTPS URL. Example: https://www.yourcompany.com/shopping-cart/outcome?saleId=YCPNY-J6P7VZ.

callbackURL
string <uri> [ 5 .. 2048 ] characters ^((?! ).)*$

Deprecated as of 2023-04-18. Use merchant-level webhook instead.

expiry
number >= 0
Default: 1440

You can set an optional expiry time for the checkout object, which determines how long it will remain valid and able to complete a checkout, expressed in whole minutes. If no expiry time is provided, the default value is 1440 minutes (one day). Example: 60 (for 1 hour).

required
Array of objects non-empty

This property holds an array of checkout item objects that collectively define the items included in a checkout, along with their respective costs, quantities, and other relevant details.

{
  • "type": "plan",
  • "merchantId": "string",
  • "externalCode": "string",
  • "merchantOrderId": "string",
  • "currencyCode": "str",
  • "redirectURL": "http://example.com",
  • "callbackURL": "http://example.com",
  • "expiry": 1440,
  • "items": [
    ]
}

Next, let's take a look at an example HTTP request for creating a checkout.

POST https://portal.sbx.planpay.com/api/v2/checkout HTTP/1.1
Content-Type: application/json
Accept: application/json
Authorization: Basic YTFiMmMzZDRlNWY2Om5rbDNxeTd2OXJ4MnN3OG16NWZkMWFqMGM2Z2I0ZXBo

{
"merchantId": "8b4f37d2e6a1",
"merchantOrderId": "YCPNY-J6P7VZ",
"currencyCode": "AUD",
"redirectURL": "https://www.yourcompany.com/shopping-cart/outcome?saleId=YCPNY-J6P7VZ",
"items": [
{
"sku": "SKU-31789",
"merchantProductURL": "https://www.yourcompany.com/flight/ZX6658",
"quantity": 2,
"description": "Flight ZX6658 - SYD to LAX",
"costPerItem": 100.00,
"minimumDepositPerItem": {
"unit": "currency",
"value": 10.00
},
"depositRefundable": true,
"redemptionDate": "2022-07-31",
"paymentDeadline": 15,
"refundPolicies": [
{
"type": "percentage_refundable_days_within_redemption_date",
"daysWithinRedemptionDate": 20,
"refundablePercentage": 50
},
{
"type": "percentage_refundable_days_within_redemption_date",
"daysWithinRedemptionDate": 30,
"refundablePercentage": 75
},
{
"type": "percentage_refundable_days_within_redemption_date",
"daysWithinRedemptionDate": 60,
"refundablePercentage": 100
}
]
}
]
}
info

The base URL of the API will vary depending on the environment for the request. In the example above, the .sbx prefix was included in the URL because this was the sandbox environment. For the production environment, use https://portal.planpay.com/api/v2/checkout without the prefix. Make sure to use the correct URL for your environment.

Interpreting the API response and loading the widget

The API responses fall into the following categories.

Response categoryHTTP statusResponse body
Success200+Checkout object
Validation failure400+Error response
Service failure500+Error response

If the API response is success or validation failure (i.e., < 500), you SHOULD attempt to display the widget. A simplified response example is shown below.

HTTP/1.1 201 OK
Content-Type: application/json

{
"id": "n1083c79a35b",
// ...other properties
}
tip

The id in the response example above is the unique checkout ID that must be used when loading the checkout widget.

Deposits and refund policies

When a customer books a service or product, the merchant may require a deposit to secure the reservation. In some cases, this deposit may be non-refundable. The refundability of the deposit can be determined by the depositRefundable parameter in the request to create the checkout. In addition to the deposit, the merchant may also define refund policies that determine how much of the total paid amount is refundable in case of a cancellation. This section covers how these two mechanisms interact, and how the applicable refund policy is determined based on the current time and the daysWithinRedemptionDate parameter.

If depositRefundable is false in the request to create the checkout, the non-refundable amount will be whichever is greater, the non-refundable amount from the deposit or the non-refundable amount according to the policy in effect. Any remaining paid amount would be refunded to the customer buy by default, or the merchant can optionally override these settings depending on the scenario.

Suppose a merchant defines the following refund policies:

  • Policy A: 75% refundable to customer within 60 days
  • Policy B: 50% refundable to customer within 30 days

If a customer requests a refund 40 days before the redemption date, Policy A will be in effect because the current time is within the 60-day window but before the 30 day window. On the other hand, if the customer requests a refund 20 days before the redemption date, Policy B will be in effect because the current time is within the 30-day window. This assumes that the non-refundable amount according to the applicable policy is less than any non-refundable deposit amount.

The applicable policy is always determined based on the smallest daysWithinRedemptionDate that is greater than or equal to the current time.

Refund Policy Schedule

This decision tree shows the refund policy schedule for the scenario described on this page.

Non-Refundable Amount Decision Tree

info

Learn how to cancel and refund a plan in our training video Processing Cancellations and Refunds.