Initiate payment
This action allows you to initiate payment for your products.
Initialization API call
Authentication information:
All requests to the Payunit REST API must be authenticated. payunit supports two forms of authentication, both using HTTP basic authentication, which uses the following username/password schemes:
- API USER et API PASSWORD
- Application token
BASE_URL : https://gateway.payunit.net (opens in a new tab)
Http headers : HTTP header specifications for all API calls.
HTTP Header | Description |
---|---|
Content-Type | supported content type is application/json |
Authorization | Http basic Auth is Base 64 encoded and formatted as follows: Basic Base64(api_user:api_password) |
x-api-key | Your application token |
mode | Live or test. Your application's current mode |
Request to initialize a checkout transaction on Payunit
curl --location --request POST '{{base_url}}/api/gateway/checkout/initialize' \
--header 'x-api-key: live_xxxxxxxxxxxxxxx' \
--header 'mode: live' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic xxxxxxxxxx' \
--data-raw '{
"cancel_url": "https://example.com/cancel",
"success_url": "https://example.com/success",
"notify_url": "https://example.com/notify",
"currency": "XAF",
"mode": "payment",
"transaction_id": "{{$randomPassword}}",
"total_amount": 10,
"items": [
{
"price_description": {
"unit_amount": 1
},
"product_description": {
"name": "Practical Frozen Pizza",
"image_url": "https://loremflickr.com/640/480",
"about_product": "Animi minima voluptate quis placeat reiciendis hic fugiat."
},
"quantity": 10
}
],
"meta": {
"phone_number_collection": false,
"address_collection": false
}
}
'
End point: {BASE_URL}/api/gateway/checkout/initialize
Request method: POST
All URLs must utilize HTTPS protocol { success_url,cancel_url,notify_url,image_url }; otherwise, the requests will not be successful.
Request body :
Paramètre | Mandatory | Description |
---|---|---|
total_amount | Yes | The amount to be paid by the user |
transaction_id | Yes | The unique identifier that identifies the transaction in your system, example SDK-4587295 |
mode | Yes | Your initiation mode |
currency | Yes | The currency you want to use: XAF |
success_url | Yes | The url or endpoint where the customer will be redirected at the end of the payment process in the event of success |
cancel_url | Yes | The url or endpoint where the customer will be redirected at the end of the payment process if the transaction is cancelled |
notify_url | No | Notification webhook of the payment result to your server by payunit |
payment_country | No | Alpha country code used to display only providers of that country. eg: CM |
items | Yes | The array of various payment products |
price_description | Yes | Product pricing information |
unit_amount | Yes | Product unit price |
product_description | Yes | Information about the product itself |
name | Yes | Product name |
image_url | Yes | Product image url |
about_product | No | Product description |
quantity | Yes | Product quantity |
meta | Yes | Paiement configurations |
phone_number_collection | Yes | Determines whether the checkout form should retrieve the customer's phone number |
address_collection | Yes | Determines whether the checkout form should retrieve the customer's address |
Response body:
{
"status": "SUCCESS",
"statusCode": 200,
"message": "payment initiate",
"data": {
"redirect": "http://payunit-staging-checkout.s3-website.us-east-2.amazonaws.com/PU_payment_ea7159f0-1075-4c48-ac5a-7c92f60cac0c"
}
}
Parameter | Description |
---|---|
status | The transaction status. |
statusCode | The Transaction status code |
message | The API return message. |
data | Data returned by the API |
redirect | The payment link |
The payment link generated is only valid for 15 minutes.
You can either redirect to that link or use the make payment
API to make a payment in your current checkout session.