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.
To refund a transaction means to return/transfer back a transaction amount from your bank account to the customer's bank account. It will be logged as a new separated transaction with this type, and it will be related to the previous "Sale" or "Capture" transaction. In this article, we walk you through how to use and manage the below function:
let transactionCreated = function ($results){ console.log($results); } paytabs.queryTransaction( transactionDetails, cartDetails, transactionCreated );
Refund request is available ONLY for those authenticated "Sale" transactions or authenticated "Capture" transactions
Through out the article we will use the transaction types clarified in our What is "tran_type"? solution article. .
Transaction Reference
The Parameter Tag/Name | transactionDetails |
Example | let transactionDetails = [ transaction.ref, transaction.typ, transaction.cls ]; |
Data Type | Array |
Required | ✔ |
transaction.ref | Indicates the reference to the "Auth" transaction you want to capture |
transaction.typ | refund |
transaction.cls | ecom |
Cart Details
The Parameter Tag/Name | cartDetails |
Example | let cartDetails = [ cart.id, cart.currency, cart.amount, cart.description ]; |
Data Type | Array |
Required | ✔ |
cart.id | Indicates the cart id to the transaction you want to create |
cart.currency | Indicates the currency |
cart.amount | Indicates the amount you want to capture, either the full amount for a full capture or partial one for partial capture. |
cart.description | Indicates the cart/order description at your end to easily relate this transaction to. It might contain the reason for the capture. |
transactionCreated (callable)
The Parameter Tag/Name | transactionCreated |
Example | let transactionCreated = function ($results){ console.log($results); } |
Data Type | callable function |
Required | ✔ |
Purpose | Indicates the function to be run after the payment. |
Validation Rules | - |
Sample Request Payload
To process a capture request, you have to pass a tran_type that MUST be “refund” and the transaction reference of the original "Auth" transaction that you want to refund, as shown in the below sample:
Refund request is available ONLY for those Authenticated Sale transactions or Authenticated Capture transactions
Sample Response Payload
The response PayTabs will send to you will be a JSON object that contains the full details regarding this refund transaction, as shown below:
{ tran_ref: 'TST2229901364852', previous_tran_ref: 'TST2229901364842', tran_type: 'Refund', cart_id: 'RFNDCAP100001', cart_description: 'partial refund test', cart_currency: 'EGP', cart_amount: '70.00', customer_details: { name: 'Mohammed ELRayes', email: '[email protected]', phone: '+201234567890', street1: 'dummy street', city: 'Port Fouad', state: 'PTS', country: 'EG', zip: '42121' }, payment_result: { response_status: 'A', response_code: 'G95537', response_message: 'Authorised', transaction_time: '1970-01-01T00:00:00Z' }, payment_info: { payment_method: 'Visa', card_type: 'Credit', card_scheme: 'Visa', payment_description: '4111 11## #### 1111', expiryMonth: 12, expiryYear: 2022 }, serviceId: 1, profileId: 8***4, merchantId: 3***7, trace: 'PMN****4.63****11.00****EE' }
This means returning/transfer back a transaction amount from your bank account to the customer's bank account. It will be considered a new separated transaction with this type, and it will be related to the previous sale/capture transaction.
⌂ 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 current step "Step 7 - Manage Transactions" kindly click here.
⇦ And to navigate to the previous step in the integration process "Step 6 - Handle the post payment responses" kindly click here.