Skip to content

Tokenize Payment

This endpoint is for generating a payment token that works on all payment gateways.

Note: If you intend to use the sandbox, you should use the following base URI: https://youcanpay.com/sandbox/api/

Parameters

ParameterTypeDescription
pri_keyrequiredMerchant account's private key
order_idrequiredThe order ID corresponding to the transaction, used to track which order the transaction is for on your store.
amountrequiredInteger representing the payment amount in minor units
currencyrequiredISO-4217 currency code.
success_urloptionalThis URL is returned when the payment is successfully processed.
error_urloptionalThis URL is returned when payment is failed.
metadataoptionalAn object containing data related to the transaction. We use this for many things including monitoring and fraud prevention. The schema is completely flexible.
customeroptionalAn object containing customer data

Returns

Returns a token ID that can later be used to complete the payment.

Request

Endpoint: https://youcanpay.com/api/tokenize

Method: POST

bash
$ curl --location --request POST 'https://youcanpay.com/api/tokenize' \
  --header 'Accept: application/json' \
  --form 'amount="500"' \
  --form 'currency="MAD"' \
  --form 'pri_key="pri_key_for_test"' \
  --form 'order_id="12"' \
  --form 'success_url="https://yourdomain.com/orders-status/success"' \
  --form 'error_url="https://yourdomain.com/orders-status/failed"' \
  --form 'metadata[cart.id]="uuid"' \
  --form 'metadata[type]="checkout"'

Response

The response object

json
{
    "transaction_id": "840f1c8a-6554-45d5-a1ad-f8a48f928dcf",
    "token": "cp500014337"
}