Step 5: Analyze the payment result
Objective
- Analyzing the payment result from:
- instant payment notification: IPN (server-to-server call)
- The response sent to the browser.
I. Response structure
The following data is sent by the payment gateway:
PARAMETER | Description |
---|---|
kr-hash-key | Type of key used to sign kr-answer. Can be set to sha256_hmac (browser return) or password (IPN). |
kr-hash-algorithm | Algorithm used to calculate the hash. Its value is sha256_hmac. |
kr-answer | Object containing the payment result, encoded in JSON. |
kr-answer-type | Type the JSON object stored in kr-answer. |
kr-hash | Hash of the JSON object stored in kr-answer. It allows to verify the authenticity of the response. |
II. Analyze the IPN (Instant Payment Notification)
It is imperative to retrieve and analyze the IPN payment data.
- Retrieve the JSON of the IPN
- Check the authenticity of the notification with the kr-hash value
- Check the payment status
More info: NPI Analysis (notification URL).
III. Analyze the response upon the browser return
In the HEAD
, implement the kr-post-url-success initialization parameter to receive the payment result in case of successful payment (Step 4: Display the payment form).
- Retrieve the JSON posted in the browser
- Check the authenticity of the notification with the kr-hash value
- Check the payment status
.
VI. Simplified PHP example
In the sample
folder, the sample files are:
- ipn.php.
- paid.php.
For more information, click on: Example files: ipn.php and paid.php