Process the Transaction Response

Once a transaction request has been sent to the Mastercard Payment Gateway, you will generally receive a response within a very short period. To determine the success of your transaction, as well as obtain other important data from the transaction response, you will need to decode and parse the transaction response.

This page includes sample code snippets. Choose an interface and language, then click Update Code Snippets.

How to Decode the Response , Change Download

When you receive the response to your transaction, it will be encoded or formatted in the same format as the transaction request. To make this data more accessible, you may need to decode this data and store it in an array or similar.

The code snippet shows how to decode the response received from the Mastercard Payment Gateway.

         Select Protocol and Language to view Code Snippet.

From: Sample Code Download  

How to Parse the Response , Change Download

Once you have decoded the transaction response and have it stored in an easily accessible object, you can then parse the response to retrieve or store any of the fields in the transaction response.

Please note that for all API operations, there will always be a "result" field in the response. This field indicates the overall result/status of your transaction. You can use this field to determine different processing options within your application, for example if it is a SUCCESS, then you can record the transaction as being processed successfully. If it returns a FAILURE, you may want to look further at the transaction response and determine if the payer should retry the transaction or execute another process within your application.

The code snippet shows how to parse a field from the decoded transaction response.

         Select Protocol and Language to view Code Snippet.

From: Sample Code Download  

Using the Transaction Response

You should spend some time examining the transaction response parameters for each relevant operation in the API Reference. All of these fields provide valuable information, and many of which you may wish to store locally for accounting, reconciliation and traceability reason. You may also wish to display a receipt number or similar to the payer. For more complex integrations, it may also be useful for you to look further into specific response codes to gather all aspects of the transaction.

It is also a good practice to validate whether the data you supplied for the transaction is the same data used to process the transaction. For example, you should check that amount returned in the transaction response matches the value you sent in the transaction request.
The last step is to test your integration.

Copyright © 2023 Mastercard