> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fintoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Redirect customers to Fintoc

> Redirect customers to Fintoc to complete a payment.

Redirect your customers to Fintoc to complete a payment, then return them to your website. The payment flow follows these steps:

1. **Create a Checkout Session:** Your backend calls the Fintoc API to create a Checkout Session. Include `success_url` and `cancel_url` in the request.
2. **Receive the redirect URL:** The API returns a Checkout Session that contains `redirect_url`.
3. **Redirect your customer:** Send your customer to `redirect_url` to complete the payment in the Fintoc Widget.
4. **Return your customer:** Fintoc redirects your customer to `success_url` or `cancel_url` after the payment flow.

***

## Create a Checkout Session

Create a Checkout Session from your server with your secret key. Include `success_url` and `cancel_url` in the request:

```curl theme={null}
curl --request POST \
     --url https://api.fintoc.com/v1/checkout_sessions \
     --header 'Authorization: YOUR_TEST_SECRET_API_KEY' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data-raw '{
  "amount": 1000,
  "currency": "CLP",
  "cancel_url": "https://merchant.com/987654321",
  "success_url": "https://merchant.com/success",
  "customer_email": "customer@example.com",
  "metadata": {
      "order": "987654321"
    }
}'
```

```node Node theme={null}
// Install Fintoc's Node SDK before running this example: https://github.com/fintoc-com/fintoc-node

const checkoutSession = await fintoc.checkoutSessions.create({
	amount: 1000,
  currency: 'clp',
  customer_email: 'name@example.com',
  cancel_url: 'https://merchant.com/987654321',
  success_url: 'https://merchant.com/success',
  metadata: {
    order: '987654321'
  }
});
```

```python Python theme={null}
# Install Fintoc's Python SDK before running this example: https://github.com/fintoc-com/fintoc-python

checkout_session = client.checkout_sessions.create(
    amount=1000,
    currency='clp',
    customer_email='name@example.com',
    cancel_url='https://merchant.com/987654321',
    success_url='https://merchant.com/success',
    metadata={
        order: '987654321'
    }
)
```

| Parameter        | Example                          | Explanation                                                                                                                   |
| ---------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `amount`         | `1000`                           | Amount to pay in the smallest currency unit. For CLP, `1000` represents CLP 1,000.                                            |
| `currency`       | `CLP`                            | Three-letter ISO 4217 currency code. Checkout Sessions support the currencies available in the customer's country.            |
| `success_url`    | `https://merchant.com/success`   | URL where Fintoc redirects your customer after a successful payment.                                                          |
| `cancel_url`     | `https://merchant.com/987654321` | URL where Fintoc redirects your customer after they cancel the payment.                                                       |
| `customer_email` | `customer@example.com`           | Optional email address associated with the Checkout Session. Fintoc uses this address to notify your customer about a refund. |
| `metadata`       | `{"order": "987654321"}`         | Optional set of key-value pairs for storing additional information about the object.                                          |

### Handle the API response

After you create the Checkout Session, the API returns the session with `redirect_url`. For example:

```json theme={null}
{
  "id": "cs_li5531onlFDi235",
  "created_at": "2025-02-06T18:42:51Z",
  "object": "checkout_session",
  "currency":"CLP",
  "amount": "1000",
  "customer_email":"customer@example.com",
  "expires_at": "2025-02-06T18:52:51Z",
  "mode": "live",
  "status":"created",
  "session_token": "cs_li5531onlFDi235_sec_a4xK32BanKWYn",
  "cancel_url": "https://merchant.com/987654321",
  "success_url": "https://merchant.com/success",
  "metadata": {
      "order": "987654321"
    },
  "business_profile": {},
  "redirect_url": "https://pay.fintoc.com/payment?checkout_session=cs_li5531onlFDi235"
}
```

### Handle post-payment events

Fintoc sends a webhook event when the Checkout Session reaches a final state. Follow the [webhook guide](/guides/resources/webhooks-walkthrough) to receive these events. You can then confirm the order, record the sale, or start a shipping workflow.

Listen for webhook events instead of relying on a client callback. Your customer could close the browser or quit the app before the callback runs. A malicious client could also manipulate the callback.

We recommend handling the following events:

| Event                       | Description                                                                                                                    | Action                                                                                                                 |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| `checkout_session.finished` | Sent when a payment associated with a Checkout Session reaches a final state. The webhook includes the payment's final status. | Depending on the final status of the related payment, confirm the order to the customer or offer to retry the payment. |
| `checkout_session.expired`  | Sent when a customer leaves the payment flow before finishing.                                                                 | Offer the customer another attempt to pay.                                                                             |

<Info>
  **Learn more about webhooks**

  Learn how to create, test, and secure your webhook endpoint in the [webhooks guide](/guides/resources/webhooks-walkthrough).
</Info>
