--- url: https://docs.youcan.shop/youcan-pay/payment/tokenize.md --- # 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 | Parameter | Type | Description | | --- | --- | --- | | `pri_key` | required | Merchant account's private key | | `order_id` | required | The order ID corresponding to the transaction, used to track which order the transaction is for on your store. | | `amount` | required | Integer representing the payment amount in minor units | | `currency` | required | ISO-4217 currency code. | | `success_url` | optional | This URL is returned when the payment is successfully processed. | | `error_url` | optional | This URL is returned when payment is failed. | | `metadata` | optional | An object containing data related to the transaction. We use this for many things including monitoring and fraud prevention. The schema is completely flexible. | | `customer` | optional | An 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" } ```