This shows you how to verify transactions using the transaction ID

After a successful charge, you need to verify with PayChangu that the payment was successful before providing value to your customer on your website. For every transaction, you must supply a transaction ID.

Here are some important things to check when verifying the payment:

  • Verify that the transaction reference matches the one you generated.
  • Verify that the status of the transaction is successful.
  • Verify that the currency of the payment matches the expected currency.
  • Verify that the amount paid is greater than or equal to the expected amount. If the amount is greater, you can provide the customer with the value and refund the excess.

To verify a payment, use the verify transaction endpoint by passing in the transaction ID in the URL. You can obtain the transaction ID from the tx_ref present in the response you receive after creating a transaction or in the webhook payload for any transaction.

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

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

Verification response

Here's a sample verification response

{
    "message": "Payment details",
    "status": "success",
    "data": {
        "first_name": "Mac",
        "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": "2023-07-12T10:22:02.000000Z",
        "updated_at": "2023-07-12T10:22:02.000000Z"
    }
}