This page will help you with Level - API integration flow.

PayChangu provides you access to your resources through RESTful endpoints. so you can test the API. You would also be able to access your test API credential and keys from here

HTTP Request Sample

We would provide cURL request sample, just so you can quickly test each endpoint on your terminal or command line. Need a quick how-to for making cURL requests? just use an HTTP client such as Postman, like the rest of us!

Requests and Responses

Both request body data and response data are formatted as JSON. Content type for responses are always of the type application/json. You can use the PayChangu API in test mode, which does not affect your live data. The API key you use to authenticate the request determines whether the request is live mode or test mode

Initiate Transaction

Parameter

Required

Description

secret_key string

Yes

This is important for creating payment links

callback_url url

Optional

This is your IPN url, it is important for receiving payment notification. Successful transactions redirects to this url after payment. {tx_ref} is returned, so you don't need to pass it with your url

return_url url

Optional

URL to redirect to when a transaction is completed. This is useful for 3DSecure payments so we can redirect your customer back to a custom page you want to show them.

tx_ref string

Optional

Your transaction reference. This MUST be unique for every transaction.

first_name string

Yes

This is the first_name of your customer.

last_name string

Yes

This is the last_name of your customer.

email string

Yes

This is the email address of your customer. Transaction notification will be sent to this email address

currency string

Yes

Currency to charge in. [ 'MWK', 'GBP', 'USD' ]

amount int32

Yes

Amount to charge the customer.

customization array

Yes

{
"title":"Title of payment",
"description":"Description of payment",
"logo":"https://domain.com/logo.png"
}

meta array

Optional

You can pass extra information here.

curl -X POST "https://in.paychangu.com/api/payment"
-H "Accept: application/json"
-H "Authorization: Bearer {secret_key}"
-d "{
    "amount": "100",
    "currency": "MWK",
    "email": "[email protected]",
    "first_name":"Kelvin",
    "last_name":"Banda",
    "callback_url": "https://webhook.site/9d0b00ba-9a69-44fa-a43d-a82c33c36fdc",
    "return_url": "https://webhook.site",
    "tx_ref": '' + Math.floor((Math.random() * 1000000000) + 1),
    "customization": {
      "title": "Test Payment",
      "description": "Payment Description",
      "logo": "https://assets.piedpiper.com/logo.png"
    },
    "meta": {
      "uuid": "uuid",
      "response": "Response"
    }
}"

Response

{
    "message": "Payment link created",
    "status": "success",
    "data": {
        "checkout_url": "https://in.paychangu.com/payment/09229936784"
    }
}

Now when you pass the returned link to the user, they will be provided with our checkout page to complete the payment like the one below:

What happens when the user completes the transaction on the page?
When the user enters their payment details, PayChangu would validate then charge the card. Once the charge is completed we would:

  1. Call your specified redirect_url and post the response to you. We will also append your transaction ID (transaction_id), transaction reference (tx_ref) and the transaction status.

  2. Call your webhook URL (if one is set).

  3. Send an email to you and your customer on the successful payment.

Before you give value to the customer, please make a server-side call to our Transaction verification endpoint to confirm the status of the transaction.

Validate a Transaction

Below is a sample code of how to implement server-side validation.

curl -X GET "https://in.paychangu.com/api/verify-payment/{tx_ref}"
-H "Accept: application/json"
-H "Authorization: Bearer {secret_key}"

Response
Here's a sample verification response

{
    "message": "Payment details",
    "status": "success",
    "data": {
        "first_name": "Kelvin",
        "last_name": "Phiri",
        "email": "[email protected]",
        "currency": "MWK",
        "amount": "10,000.00",
        "charge": "400.00",
        "mode": "test",
        "type": "API",
        "status": "success",
        "reference": "20193542126",
        "tx_ref": "2346vrcdssdadffx",
        "customization": {
            "title": "Test Payment",
            "description": "Payment Description",
            "logo": "https://logo.png"
        },
        "meta": {
            "uuid": "uuid",
            "response": "Response"
        },
        "created_at": "2022-01-12T10:43:09.000000Z",
        "updated_at": "2022-01-12T10:43:09.000000Z"
    }
}