Skip to main content

Create a Checkout

To create a checkout with the Payfect API, you will need to make a POST request to the /checkouts endpoint. In this request, you will need to include all relevant checkout information, such as the currency, and the invoice items.

Endpoint

POST /checkouts/

Fields

Field NameTypeRequiredDescription
client_reference_idStringNoClient reference id.
currencyStringYesCurrency code (usdt).
invoice_itemsArrayYesList of invoice items.
success_urlStringNoURL to redirect on success.
cancel_urlStringNoURL to redirect on cancel.
callback_urlStringNoURL to send a callback notification upon successful completion of the charge.
payment_method_dataObjectNoData regarding the payment method chosen for the transaction.

Example Request Body

{
"client_reference_id": "5ae50223-e455-4a72-a48d-fe7d85800e64",
"currency": "usdt",
"invoice_items": [{
"price_data": {
"product_data": {
"name": "Standard Plan",
"description": "A standard plan",
"images": [
"https://google.com.tw/images/123"
],
},
"currency": "usdt",
"unit_amount": "20.5",
},
"quantity": 1,
}],
"success_url": "https://example.com/success",
"cancel_url": "https://example.com/cancel",
"callback_url": "https://example.com/callback",
"payment_method_data": {
"type": "cryptopaymentmethoddetail",
"paymentMethodDetail": {
"currency": "usdt",
"network": "tron"
}
}
}

Response Structure

The response for the Create a Checkout API call returns a JSON object containing several fields. Below is a detailed description of each field:

Field NameTypeDescription
idStringUnique identifier for the checkout session.
merchantObjectContains merchant's id and name.
nameCollectionBooleanIndicates if the customer name is collected.
emailCollectionBooleanIndicates if the customer email is collected.
phoneNumberCollectionBooleanIndicates if the customer phone number is collected.
shippingAddressCollectionObjectDetails of the shipping address collection.
invoiceItemsArrayArray of invoice items included in the checkout. Each item contains id, price, priceData, quantity and amount.
amountTotalStringTotal amount of the checkout session.
statusStringCurrent status of the checkout session. See Status Values below for more details.
createdAtStringTimestamp of session creation.
updatedAtStringTimestamp of the last update.
clientReferenceIdStringClient reference ID if provided.
currencyStringCurrency code of the session (e.g., 'usdt').
successUrlStringURL to redirect to on success.
cancelUrlStringURL to redirect to on cancel.
expiresAtStringExpiration timestamp for the session.
paymentIntentStringUnique identifier for the payment intent.
paymentMethodTypesArrayList of available payment method types (e.g., 'crypto', 'card').
paymentMethodOptionsObjectOptions available for the payment methods.
urlStringURL of the checkout session.
metadataObjectAdditional metadata related to the checkout.
isLivemodeBooleanIndicates if the session is in live mode.

Status Values

The status field in the response indicates the current state of the checkout session. Possible values include:

  • open: The session is currently open and awaiting completion.
  • complete: The session has been successfully completed.
  • expired: The session has expired and is no longer valid.

Example Response

{
"id": "ed8d24aa-a860-426b-8e56-87cb9f55a081",
"merchant": {
"id": "bf065cc8-343d-4419-be7d-ed2190f1df4d",
"name": "頑碼資訊有限公司"
},
"nameCollection": false,
"emailCollection": false,
"phoneNumberCollection": false,
"shippingAddressCollection": null,
"invoiceItems": [
{
"id": "ee05d205-e4cc-42bd-8897-03c92674c57a",
"price": "3bababfe-5ba8-4afb-84ca-d62c6933704b",
"quantity": 1,
"amount": "20.00"
}
],
"amountTotal": "20.00",
"status": "open",
"createdAt": "1690532072.288761",
"updatedAt": "1690532073.498443",
"clientReferenceId": null,
"currency": "usdt",
"successUrl": "https://example.com/success",
"cancelUrl": "https://example.com/cancel",
"expiresAt": "1703939166000",
"paymentIntent": "b7c30e83-5439-47b2-ac4d-81c64c1d0174",
"paymentMethodTypes": [
"crypto",
"card"
],
"paymentMethodOptions": {
"crypto": [
{
"currency": {
"value": "usdt",
"name": "Tether",
"logo": "/static/images/cryptos/usdt.png"
},
"networks": [
{
"value": "tron",
"name": "Tron (TRC20)"
}
]
}
],
"card": null
},
"url": "https://buy-dev.payfect.finance/checkouts/ed8d24aa-a860-426b-8e56-87cb9f55a081",
"metadata": null,
"isLivemode": false
}

Example

curl -X POST https://api.payfect.finance/api/v1/checkouts/ \
-H 'Authorization: Api-Key 5a31f3a4-279c-11ee-be56-0242ac120002' \
-H 'Content-Type: application/json' \
-d '{
"client_reference_id": "6befb0e4-e9a0-4151-8999-8b67eae19553",
"currency": "CNY",
"invoice_items": [{
"price_data": {
"currency": "TWD",
"product_data": {
"name": "Standard Plan",
"description": "A standard plan",
"images": ["https://i.imgur.com/EHyR2nP.png"]
},
"unit_amount": "20"
},
"quantity": 1
}],
"success_url": "https://example.com/success",
"cancel_url": "https://example.com/cancel",
"callback_url": "https://example.com/callback",
"payment_method_data": {
"type": "cryptopaymentmethoddetail",
"paymentMethodDetail": {
"currency": "TWD",
"network": "tron"
}
}
}'