PayTabs SDK makes the integration with the PayTabs payment gateway very easy by providing a ready-made payment screen that handles the card entry and, billing & shipping information and completes the missing details.
This article is dedicated to walking you through how to initiate the payment/request payload using the configuration options and parameters that have already been clarified in the previous step, "Step 2 - Configure the integration method".
After making sure of configuring this SDK as you wish, you will need to import the SDK package Core Component in your code first to start, as shown below:
Implementing this option will enable you to apply a discount for a specific bank card/s via giving card prefixes from 4 to 10 digits. To be able to do this, please follow the below instructions:
- Make sure you import PaymentSDKConfiguration Component.
- Configure the billing & shipping information for this payment, noting that the shipping information is optional. To know more about this, please check our 3.1 React Native SDK | Manage Shipping and Billing details and 2.1 React Native SDK | Configuration Options & Parameters solution articles.
let billingDetails = new PaymentSDKBillingDetails( name= "First Last Name", email= "[email protected]", phone= "+966 56 808 ####", addressLine= "address line", city= "city", state= "state", countryCode= "SA", // country ISO alpha 2 zip= "22333"); let shippingDetails = new PaymentSDKShippingDetails( name= "First Last Name", email= "[email protected]", phone= "+966 56 808 ####", addressLine= "address line", city= "city", state= "state", countryCode= "SA", // ISO alpha 2 zip= "22333");
Now configure the discount, note that you can apply one or more discounts via implementing the discount PaymentSDKCardDiscount object:
export default class PaymentSDKCardDiscount { constructor(discountCards, discountValue, discountTitle, isPercentage) { this.discountCards = discountCards; this.discountValue = discountValue; this.discountTitle = discountTitle; this.isPercentage = isPercentage; } }
discountCards {string[]} - An array of strings representing the cards that the discount can be applied to. A list of Strings, each string must have between 4 and 10 digits, and can't be empty. ['4111', '40001']
discountValue {number} - The value of the discount. This could be a flat amount or a percentage depending on the value of 'isPercentage'. discountTitle String title/name that will be displayed to the customer. isPercentage A boolean indicates whether the discount value is a percentage (true) or a flat amount (false). let cardDiscount1 = new PaymentSDKCardDiscount(); cardDiscount1.discountCards = ['4111', '40001']; cardDiscount1.discountValue = 10; cardDiscount1.discountTitle = 'Discount 10% on 4111,40001 cards'; cardDiscount1.isPercentage = true; let cardDiscount2 = new PaymentSDKCardDiscount(); cardDiscount2.discountCards = ['42222', '40002']; cardDiscount2.discountValue = 5; cardDiscount2.discountTitle = 'Discount 5 EGP on 42222,40002 cards'; cardDiscount2.isPercentage = false;
Then create an object from
PaymentSDKConfiguration
and fill it out with your credentials and payment details. don't forget to set the discount via "cardDiscounts" parameters using the array created in the previous step. To know more about what is the exact values that should be passed here, please check our 2.1 React Native SDK | Configuration Options & Parameters, and 2.2 React Native SDK | The PaymentSDKConfiguration Object solution articles.Only then you will be ready to start/initiate the payment by passing your PaymentSDKConfiguration object to the
startCardPayment
function in which the then() function will catch the payment response. To know more about this please check our 2.2 React Native SDK | The PaymentSDKConfiguration Object and Step 5 - React Native SDK | Handle the payment response solution articles.
RNPaymentSDKLibrary.startCardPayment(JSON.stringify(configuration)).then( result => { if(result["PaymentDetails"] != null) { // Handle transaction details let paymentDetails = result["PaymentDetails"] console.log(paymentDetails) } else if(result["Event"] == "CancelPayment") { // Handle events console.log("Cancel Payment Event") } }, function(error) { // Handle error console.log(error) });
Discount title dialog, will show onle two titles, if you have set more than two then you will have to select the "See All" to display the full list:
Once you press the See All, a sheet will display showing all applied discounts configured.If the customer uses a bank card that does not match any of the discount filters, the discount will not applied and the customer will pay the full amount.
⌂ To get familiar with the whole process and the other steps, kindly navigate to our "The React Native SDK Integration Manual" solution article.
⇦ And to navigate to the previous step in the integration process "Step 2 - Configure the integration method" click here.
⇦ And to get familiar with the rest of the steps regarding the current step "Step 3 - Initiating the payment" click here.
⇨ Or you can navigate to the next step in the integration process "Step 4 - Accepting the payment" kindly click here.