Checkout
Initialize payment

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 HeaderDescription
Content-Typesupported content type is application/json
AuthorizationHttp basic Auth is Base 64 encoded and formatted as follows: Basic Base64(api_user:api_password)
x-api-keyYour application token
modeLive 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ètreMandatoryDescription
total_amountYesThe amount to be paid by the user
transaction_idYesThe unique identifier that identifies the transaction in your system, example SDK-4587295
modeYesYour initiation mode
currencyYesThe currency you want to use: XAF
success_urlYesThe url or endpoint where the customer will be redirected at the end of the payment process in the event of success
cancel_urlYesThe url or endpoint where the customer will be redirected at the end of the payment process if the transaction is cancelled
notify_urlNoNotification webhook of the payment result to your server by payunit
payment_countryNoAlpha country code used to display only providers of that country. eg: CM
itemsYesThe array of various payment products
price_descriptionYesProduct pricing information
unit_amountYesProduct unit price
product_descriptionYesInformation about the product itself
nameYesProduct name
image_urlYesProduct image url
about_productNoProduct description
quantityYesProduct quantity
metaYesPaiement configurations
phone_number_collectionYesDetermines whether the checkout form should retrieve the customer's phone number
address_collectionYesDetermines 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"
  }
}
ParameterDescription
statusThe transaction status.
statusCodeThe Transaction status code
messageThe API return message.
dataData returned by the API
redirectThe 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.

Last updated on April 5, 2024