# Initialize Payment

To make this request, send an authenticated request to the initiatetrans endpoint.

## Initialize a transaction

<mark style="color:green;">`POST`</mark> `https://api.oneappgo.com/v1/business/initiatetrans`

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| authorization<mark style="color:red;">\*</mark> | String | SECRET\_KEY |

#### Request Body

| Name                                              | Type   | Description                                                                                               |
| ------------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------- |
| amount<mark style="color:red;">\*</mark>          |        | Transaction amount                                                                                        |
| lname<mark style="color:red;">\*</mark>           | String | Customer's last name                                                                                      |
| fname<mark style="color:red;">\*</mark>           | String | Customer's first name                                                                                     |
| customer\_email<mark style="color:red;">\*</mark> | String | Customer's email                                                                                          |
| reference<mark style="color:red;">\*</mark>       | String | Customer's transaction reference                                                                          |
| currency<mark style="color:red;">\*</mark>        | String | NGN, GHS, ZAR or USD                                                                                      |
| redirecturl                                       | String | Redirect URL                                                                                              |
| phone<mark style="color:red;">\*</mark>           | String | Customer phone number                                                                                     |
| meta\_data                                        | object | <p>Addition field such as hascommission, subaccount, trackingid etc.<br>See the sample metadata below</p> |

{% code title="" overflow="wrap" %}
```json
"meta_data": {
    "subaccount": true,
    "trackingid": "T3131122122",
    "inflowcomm": "0.3",  //leave empty if you would like to use default commission fee you set on dashboard. Pass 0 if you do not want to add any charges
    "order_id": 570,
    "cart_id": 335,
    "tx_id": 518,
    "vat": "0",
    "storedata": [
        {
            "name": "Another Clothing",
            "products": [
                {
                    "product_id": 285,
                    "description": "Gorilla T-shirt",
                    "quantity": 1,
                    "amount": 50000
                }
            ] 
        }, 
        {
            "name": "Another Clothing 2",
            "products": [
                {
                    "product_id": 9085,
                    "description": "Gucci Bag",
                    "quantity": 1,
                    "amount": 165000
                }
            ] 
        }
    ]
}
```
{% endcode %}

{% hint style="danger" %}
Your secret keys are to be kept secret and only stored on your servers. Do not pass your secret key to front end language where it can be exploited.
{% endhint %}

Take a look at how you might do this:

{% tabs %}
{% tab title="cURL" %}
```php
curl --location --request POST 'https://api.oneappgo.com/v1/business/initiatetrans' \
--header 'Authorization: Bearer YOUR_SECRET_KEY' \
--form 'reference="fghjkl56789g"' \
--form 'amount="500"' \
--form 'customer_email="example@gmail.com"' \
--form 'currency="NGN"' \
--form 'redirecturl="https://example.com"' \
--form 'fname="John"' \
--form 'phone= "09012345678"'\,
--form 'lname="Doe"'
```
{% endtab %}

{% tab title="NodeJs" %}
```javascript
var https = require('follow-redirects').https;
var fs = require('fs');

var options = {
  'method': 'POST',
  'hostname': 'api.oneappgo.com',
  'path': '/v1/business/initiatetrans',
  'headers': {
    'Authorization': 'Bearer YOUR_SECRET_KEY'
  },
  'maxRedirects': 20
};

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"reference\"\r\n\r\nfghjkl56789g\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"amount\"\r\n\r\n500\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"customer_email\"\r\n\r\nexample@gmail.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"currency\"\r\n\r\nNGN\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"redirecturl\"\r\n\r\nhttps://example.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"fname\"\r\n\r\nJohn\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"lname\"\r\n\r\nDoe\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";

req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');

req.write(postData);

req.end();
```
{% endtab %}

{% tab title="PHP - cURL" %}
```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.oneappgo.com/v1/business/initiatetrans',
  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 => array('reference' => 'fghjkl56789g','amount' => '500','customer_email' => 'example@gmail.com', 'phone' => '09012345678','currency' => 'NGN','redirecturl' => 'https://example.com','fname' => 'John','lname' => 'Doe'),
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer YOUR_SECRET_KEY'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```
{% endtab %}

{% tab title="Python" %}
```python
import requests

url = "https://api.oneappgo.com/v1/business/initiatetrans"

payload={'reference': 'fghjkl56789g',
'amount': '500',
'customer_email': 'example@gmail.com',
'currency': 'NGN',
'redirecturl': 'https://example.com',
'fname': 'John',
'phone': '09012345678',
'lname': 'Doe'}
files=[

]
headers = {
  'Authorization': 'Bearer YOUR_SECRET_KEY'
}

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

print(response.text)

```
{% endtab %}
{% endtabs %}

## Sample response

```json
{
    "status": true,
    "message": "Successful",
    "reference": "2345KDF12",
    "access_token": "6983b68c269f7fgha2beb85625288",
    "authorization_url": "https://pay.1app.online/checkout/6983b68c269f7fgha2beb85625288/63490b1643375660547"
}
```

Once the Authorization URL is successfully generated, redirect your users to the <mark style="background-color:purple;">authorization\_url</mark> so they can pay. After payment is completed, the users are redirected to your website using the <mark style="background-color:purple;">redirect URL</mark> passed with the initialize endpoint.
