# Generate a checkout URL

{% hint style="info" %} <mark style="color:blue;">The checkout URL is only valid for one-time use only</mark>
{% endhint %}

### URI

&#x20;<mark style="color:blue;background-color:blue;">**POST**</mark>&#x20;

```
https://api.tryduplo.com/v1/checkout/
```

### Parameters

#### Header

<table data-header-hidden><thead><tr><th width="171"></th><th></th></tr></thead><tbody><tr><td><strong>Authorization</strong><br><code>string</code> </td><td>set value to <code>Bearer SECRET_KEY</code></td></tr></tbody></table>

#### Body Param

<table data-header-hidden><thead><tr><th width="267"></th><th></th></tr></thead><tbody><tr><td><strong>business_id</strong>         <br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Merchant Business ID</td></tr><tr><td><strong>customer_firstname</strong>         <br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Customer's first name</td></tr><tr><td><strong>customer_lastname</strong>         <br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Customer's last name</td></tr><tr><td><strong>customer_phone_number</strong>         <br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Customer's phone number</td></tr><tr><td><strong>customer_email</strong>         <br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Customer's email address</td></tr><tr><td><strong>fee_bearer</strong>         <br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Specifies who would bear the transaction fee can only be a customer or business.</td></tr><tr><td><strong>prefered_payment_method</strong><br><code>string</code>   <mark style="color:red;"><code>required</code></mark></td><td>Specifies the payment method for the checkout, this is set to <code>pay-with-transfer</code> by default. Available options include <code>pay-with-transfer</code> or <code>bnpl</code></td></tr><tr><td><strong>shipping_fee</strong>         <br><code>number</code>  <mark style="color:red;"><code>required</code></mark></td><td>Shipping fee, set value to zero (0) if this is not applicaple.</td></tr><tr><td><strong>amount</strong>         <br><code>number</code></td><td>Specifies the exact amount a virtual account should receive</td></tr><tr><td><strong>line_items</strong>         <br><code>array</code>   <mark style="color:red;"><code>required</code></mark></td><td><p>A list of objects that specifies the item(s) the customer is about to pay for  e.g: </p><pre class="language-json"><code class="lang-json">[
    {
        "name": "Bottle water",
        "unit_price": 100,
        "quantity": 2
    }
]
</code></pre></td></tr><tr><td><strong>discount</strong>  <br><code>object</code>  <mark style="color:red;"><code>required</code></mark><br></td><td><p>An object that specify the discount(s) on the item(s) the customer is about to pay for, the value should be set to zero (0) if discount no is applied  e.g: </p><pre class="language-json"><code class="lang-json">{
    "type": "Buy 1 get one free",
    "value": 10
}

</code></pre></td></tr><tr><td><strong>tax</strong>    <br><code>object</code>  <mark style="color:red;"><code>required</code></mark>     <br></td><td><p>Tax objects specify the tax on the item(s) the customer is about to pay for, the value should be set to zero (0) if tax no is applied  e.g: </p><pre class="language-json"><code class="lang-json">{
"type": "Buy 1 get one free",
"value": 10,
"description": "VAT"
} </code></pre></td></tr><tr><td><strong>customer\_ref</strong><br><code>string</code></td><td>A customer reference. Refers to the customer that made the checkout.</td></tr><tr><td><strong>metadata.customer</strong><br><code>list</code></td><td><p>Holds customer when customer details is different from the previously saved info. <br>e.g<br></p><pre><code>"metadata": {
"customer": {
"email": "<bf@yopmail.com>",
"phone\_number": "08022215915",
"first\_name": "Bamidele",
"last\_name": "Faruk"
}
} </code></pre></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr></tbody></table>

{% hint style="info" %} <mark style="color:blue;">The customer will only be allowed to pay the exact amount, any other amount will be rejected.</mark>
{% endhint %}

### Sample request

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```bash
curl --location --request POST 'https://api.tryduplo.com/v1/checkout/' \
--header 'dpmlekdno: swwwje4t343643' \
--data-raw '{
    "business_id": "",
    "customer_firstname": "John",
    "customer_lastname": "Doe",
    "customer_email": "johndoe@yopmail.com",
    "customer_phone_number": "08022213915",
    "amount": "1200",
    "fee_bearer": "customer",
    "preferred_payment_methods": "pay-with-transfer",
    "line_items": [
        {
            "name": "Bottle water",
            "unit_price": 100,
            "quantity": 2
        }
    ],
    "shipping_fee": 50,
    "discount": {
       type: "percentage",
       value: 10,
    }
    "tax": {
      type: "percentage",
      value: 20,
      description: "VAT",
    },
    "redirect_url": "myurl.com"
}'
```

{% endcode %}

{% endtab %}

{% tab title="Node" %}
{% code overflow="wrap" lineNumbers="true" %}

```javascript
var axios = require('axios');
var data = {
    "business_id": "",
    "customer_firstname": "John",
    "customer_lastname": "Doe",
    "customer_email": "johndoe@yopmail.com",
    "customer_phone_number": "08022213915",
    "amount": "1200",
    "fee_bearer": "customer",
    "preferred_payment_methods": "pay-with-transfer",
    "line_items": [
        {
            "name": "Bottle water",
            "unit_price": 100,
            "quantity": 2
        }
    ],
    "shipping_fee": 50,
    "discount": {
       type: "percentage",
       value: 10,
    }
    "tax": {
      type: "percentage",
      value: 20,
      description: "VAT",
    },
    "redirect_url": "myurl.com"
};

var config = {
  method: 'post',
  url: 'https://api.tryduplo.com/v1/checkout/',
  headers: { 
    'dpmlekdno': 'swwwmewje4t343643'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code overflow="wrap" lineNumbers="true" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.tryduplo.com/v1/checkout/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'
  {
    "business_id": "",
    "customer_firstname": "John",
    "customer_lastname": "Doe",
    "customer_email": "johndoe@yopmail.com",
    "customer_phone_number": "08022213915",
    "amount": "1200",
    "fee_bearer": "customer",
    "preferred_payment_methods": "pay-with-transfer",
    "line_items": [
        {
            "name": "Bottle water",
            "unit_price": 100,
            "quantity": 2
        }
    ],
    "shipping_fee": 50,
    "discount": {
       type: "percentage",
       value: 10,
    }
    "tax": {
      type: "percentage",
      value: 20,
      description: "VAT",
    },
    "redirect_url": "myurl.com"
}
  ',
  CURLOPT_HTTPHEADER => array(
    'dpmlekdno: swwwmewje4t343643'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Duplo Response

```json
{
    "data": {
        "customer_firstname": "Bamidele2",
        "customer_lastname": "Faruk",
        "customer_email": "bf@yopmail.com",
        "customer_phone_number": "08022215915",
        "currency": "NGN",
        "amount": 310,
        "fee": 100,
        "fee_bearer": "customer",
        "preferred_payment_methods": "pay-with-transfer",
        "is_active": true,
        "created_at": "2023-03-29T09:53:14.410Z",
        "updated_at": "2023-03-29T09:53:14.410Z",
        "business_id": "8ed10fcc-1e1c-4ad1-9ed8-e870d6543349",
        "checkout_ref": "che_Zlh9F5N4ei6O",
        "line_items": [
            {
                "name": "Bottle water",
                "unit_price": 200,
                "quantity": 1
            }
        ],
        "shipping_fee": 10,
        "discount": {
            "type": "amount",
            "value": 10
        },
        "tax": {
            "type": "amount",
            "value": 10,
            "description": "VAT"
        },
        "redirect_url": "davidigbigbi.com",
        "reference": "CHEZLH9F5N4EI6O20230329095314",
        "checkout_url": "https://checkout.tryduplo.com?reference=7dab3a284fcfd5900105268211629294:rn4181b518d6eb1ba8e2bde4a01f1abd7e176b8f522446d769b58fae77b17907b5c744fed48c0ded62d5035c8146ca58053fe137db2e608398d96bd6117c5c7695792b91e94901a6e00680e22cf391d363fe1eec04440c9b42220836eb1b820469f3e6026ccc75ac27428940d319e263159e8e38b40ed33b5affd9fcf76b6451aa7abf31cff3fda5a23c24831107f65abf5ab5c09fa77e1bc0561558b3707526278811d9ef9aa63bee40f105fcbeba084985e9a0b318ea557ce78f13e74a77c9a57ecacd8638fca48bb4409199b6623ef0",
        "customer_ref": "cus_HzpBpNoJZHeB",
        "metadata": {
            "customer": {
                "email": "bf@yopmail.com",
                "phone_number": "08022215915",
                "first_name": "Bamidele2",
                "last_name": "Faruk"
            }
        }
    },
    "errors": {},
    "message": "Request successful"
}
```

{% hint style="info" %} <mark style="color:blue;">Once the request is done abstract the checkout\_url gotten from the response and append the following</mark>

* <mark style="color:blue;">type = payment/bnpl (note this is dependent on the type of transaction that was initiated)</mark>
* <mark style="color:blue;">callback\_url</mark>
* <mark style="color:blue;">cancel\_url</mark>

Sample URL:

[https://checkout.tryduplo.com?reference=eabf61d772a54b3bf5f69e116f2df5aa:rn06af819de62e6dd82cdfb176c8f342f0af7bfbaac306cd643abdcb22367535725cc742a063f88be11ea3bfc8bf5754ff842be90448dc21f44792e927cdf2fb7fa1e0a76e13697df18dab130e04434cae1f1cf8d9f608c72717d7a5557de7ac185e2ea8ffbab211ba81aa80666de1d1a773a34acf51bcdfbecff91e2635e97e66aa5887ee1ec0d4a21da7a9c2f750c2d5676589a2333dc1bee397e3112306974b9ab376de719fb9771d77104a2f09b923189348edd0392b3c960e2a145fc02244eca5757fe51b1168195c9dccc90e395fca4aba5c66eb3e92f39761a179413951\&business\_id=2534812c-8659-402b-838d-8eeed66c212a\&type=payment\&callback\_url=https://paid.com\&cancel\_url=https://google.com<br>](https://checkout.tryduplo.com/?reference=eabf61d772a54b3bf5f69e116f2df5aa:rn06af819de62e6dd82cdfb176c8f342f0af7bfbaac306cd643abdcb22367535725cc742a063f88be11ea3bfc8bf5754ff842be90448dc21f44792e927cdf2fb7fa1e0a76e13697df18dab130e04434cae1f1cf8d9f608c72717d7a5557de7ac185e2ea8ffbab211ba81aa80666de1d1a773a34acf51bcdfbecff91e2635e97e66aa5887ee1ec0d4a21da7a9c2f750c2d5676589a2333dc1bee397e3112306974b9ab376de719fb9771d77104a2f09b923189348edd0392b3c960e2a145fc02244eca5757fe51b1168195c9dccc90e395fca4aba5c66eb3e92f39761a179413951\&business_id=2534812c-8659-402b-838d-8eeed66c212a\&type=payment\&callback_url=https://paid.com\&cancel_url=https://google.com)

<mark style="color:blue;">You would have to redirect the customer to the constructed URL in order for the customer to complete the transaction. When the customer transaction status is confirmed the customer will be redirected to your site or to the redirect URL you specified when generating the checkout URL.</mark>
{% endhint %}
