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

# Create a checkout

> Create a Checkout by providing an amount and get the payment link.

## Create a Checkout

<Note>Don't forget to replace `<YOUR_SECRET_KEY_HERE>` with your [API Secret Key](/pay-v2/api-keys "API Secret Key")</Note>

<Tip>
  For more details about the Checkout Create endpoint, refer to its [API
  Reference.](/pay-v2/api-reference/checkouts/create "API Reference.")
</Tip>

<CodeGroup>
  ```curl cURL theme={null}
  curl --request POST \
    --url https://pay.chargily.net/test/api/v2/checkouts \
    --header 'Authorization: Bearer <YOUR_SECRET_KEY_HERE>' \
    --header 'Content-Type: application/json' \
    --data '{
    "amount": 2000,
    "currency": "dzd",
    "success_url": "https://your-cool-website.com/payments/success"
  }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://pay.chargily.net/test/api/v2/checkouts"

  payload = {
      "amount": 2000,
      "currency": "dzd",
      "success_url": "https://your-cool-website.com/payments/success"
  }
  headers = {
      "Authorization": "Bearer <YOUR_SECRET_KEY_HERE>",
      "Content-Type": "application/json"
  }

  response = requests.request("POST", url, json=payload, headers=headers)

  print(response.text)
  ```

  ```javascript JavaScript theme={null}
  const options = {
    method: "POST",
    headers: {
      Authorization: "Bearer <YOUR_SECRET_KEY_HERE>",
      "Content-Type": "application/json",
    },
    body: '{"amount":2000,"currency":"dzd","success_url":"https://your-cool-website.com/payments/success"}',
  };

  fetch("https://pay.chargily.net/test/api/v2/checkouts", options)
    .then((response) => response.json())
    .then((response) => console.log(response))
    .catch((err) => console.error(err));
  ```

  ```php PHP theme={null}
  <?php

  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://pay.chargily.net/test/api/v2/checkouts",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "{\n  \"amount\": 2000,\n  \"currency\": \"dzd\",\n  \"success_url\": \"https://your-cool-website.com/payments/success\"\n}",
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer <YOUR_SECRET_KEY_HERE>",
      "Content-Type: application/json"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```go GO theme={null}
  package main

  import (
  	"fmt"
  	"strings"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://pay.chargily.net/test/api/v2/checkouts"

  	payload := strings.NewReader("{\n  \"amount\": 2000,\n  \"currency\": \"dzd\",\n  \"success_url\": \"https://your-cool-website.com/payments/success\"\n}")

  	req, _ := http.NewRequest("POST", url, payload)

  	req.Header.Add("Authorization", "Bearer <YOUR_SECRET_KEY_HERE>")
  	req.Header.Add("Content-Type", "application/json")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.post("https://pay.chargily.net/test/api/v2/checkouts")
    .header("Authorization", "Bearer <YOUR_SECRET_KEY_HERE>")
    .header("Content-Type", "application/json")
    .body("{\n  \"amount\": 2000,\n  \"currency\": \"dzd\",\n  \"success_url\": \"https://your-cool-website.com/payments/success\"\n}")
    .asString();
  ```
</CodeGroup>

## Response

If everything worked, you should get a response like this:

```json json theme={null}
{
  "id": "01hj5n7cqpaf0mt2d0xx85tgz8",
  "entity": "checkout",
  "livemode": false,
  "amount": 2000,
  "currency": "dzd",
  "fees": 0,
  "fees_on_merchant": 0,
  "fees_on_customer": 0,
  "pass_fees_to_customer": null,
  "chargily_pay_fees_allocation": "customer",
  "status": "pending",
  "locale": "ar",
  "description": null,
  "metadata": null,
  "success_url": "https://your-cool-website.com/payments/success",
  "failure_url": null,
  "payment_method": null,
  "invoice_id": null,
  "customer_id": "01hj150206g0jxnh5r2yvvdrna",
  "payment_link_id": null,
  "created_at": 1703144567,
  "updated_at": 1703144567,
  "shipping_address": null,
  "collect_shipping_address": 0,
  "discount": null,
  "amount_without_discount": null,
  "checkout_url": "https://pay.chargily.dz/test/checkouts/01hj5n7cqpaf0mt2d0xx85tgz8/pay"
}
```

Which is the [Checkout](/pay-v2/api-reference/checkouts/checkout-object "Checkout") object you just created.

You can see in the Response a parameter called `checkout_url`:

```json theme={null}
"checkout_url": "https://pay.chargily.dz/test/checkouts/01hj5n7cqpaf0mt2d0xx85tgz8/pay"
```

This is the URL you can redirect your customer to, to complete the payment.

Now, when your customer goes to the payment link and successfully pays, how can your website or app be notified about this? This is important for handling post-payment actions, like updating an order status to "paid". We use [Webhooks](/v2/webhooks "Webhooks") for this.

## Next

You will see now how to make your website or application react to a successful payment using [Webhooks](/pay-v2/webhooks "Webhooks").

<Card title="Receive webhooks" icon="link" href="/pay-v2/handle-webhooks">
  You can now create a Checkout using the Price you just created.
</Card>
