PayTabs Node.js Package makes integration with the PayTabs payment gateway very easy by providing a ready-made payment class that handles the card entry, and billing & shipping information and completes the missing details. 



This article is dedicated to walking you through how to handle the payment response sent from PayTabs after the payment. Handling the response right will empower you to make sure to handle the user experience according to the payment status as well as and updating the order status in your database.


In this article, you will be going to know how to handle the post-payment response:



via The IPN response


The Instant Payment Notification (IPN) is the payment status notification to the configured URL, and it is a pure server-to-server connection (i.e: It is not a browser-based request).

As soon as a transaction is created or altered, IPN will instantly send a notification to the merchant’s specified IPN Listener URL, which can have any code that will assist in updating ERP or dependent systems. Alternatively, you may wish to save this information in your local database.


To get the best out of this, it's highly recommended to check our How to configure Instant payment notification (IPN)  solution article.



What you need to do is to manage the IPN URL, and for that, you need to check our 3.5 - Manage the Return and Callback URLs solution article. The next main step would be to initiate a route to receive this [POST] response according to your business needs.


You should know that since the request is coming from an external system, the CSRF token needs to be excepted



via The Callback URL response


The callback response is a server-to-server POST response that is sent (to a pre-defined HTTPS URL) with the full detailed transaction information once the payment process comes to an end (whether the customer cancels, pays, or fails to pay), as shown below. It doesn't depend on the customer's actions, and the response will be sent anyway.


{
  "tran_ref": "TST202860000xxxxx",
   "cart_id": "cart_11111",
   "cart_description": "Description of the items",
   "cart_currency": "SAR",
   "cart_amount": "12.3",
   "customer_details": {
     "name": "wajih last",
     "email": "[email protected]",
     "phone": "0522222222",
     "street1": "address street",
     "city": "dubai",
     "state": "DU", 
     "country": "AE", 
     "ip": "92.98.175.138" 
   },
   "shipping_details": {
     "name": "wajih last1",
     "email": "[email protected]",
     "phone": "971555555555",
     "street1": "street2",
     "city": "dubai",  
     "state": "DU",  
     "country": "AE", 
     "ip": "92.98.175.138" 
   },
   "payment_result": {
     "response_status": "A",
     "response_code": "G77803",
     "response_message": "Authorised",
     "transaction_time": "2020-10-12T04:43:23Z"
   },
   "payment_info": {
     "card_type": "Credit",
     "card_scheme": "Visa",
     "payment_description": "4111 11## #### 1111"
   }


Since it's a server-to-server call, the callback URL MIUST be an available, accessible, and public URL



What you need to do is to manage the IPN URL, and for that, you need to check our 3.6 - Manage the Return and Callback URLs solution article. The next main step would be to initiate a route to receive this [POST] response according to your business needs.


You should know that since the request is coming from an external system, the CSRF token needs to be excepted



Verify the IPN/Callback Response


It's highly recommended to verify the Return response first. Verifying the received object is a mandatory step to ensure that the request source is Paytabs itself. To know how to perform this, kindly check our How to verify the response received from PayTabs? (Signature Verification) solution article.







⌂ To get familiar with the whole process and the other steps, kindly navigate to our "The Node.js Packge Integration Manual" solution article.

 And to get familiar with the rest of the steps regarding the previuos step "Step 5 - Handle the payment response" kindly click here.

 And to navigate to the next step in the integration process "Step 7 - Manage Transactions" kindly click here.