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 PayTab Ionic SDK in your code first to start, as shown below:
    

import 'paytabs-ionic-native';
import { PaymentSDKBillingDetails, PaymentSDKShippingDetails, PaymentSDKConfiguration, PayTabsIonic } from 'paytabs-ionic-native';
Generic



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:


  1. Make sure you import PaymentSDKConfiguration class.

  2. 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 Ionic SDK | Manage Shipping and Billing details and 2.1 Ionic SDK | Configuration Options & Parameters solution article. 

        

    var billingDetails = new BillingDetails(
        "billing name", 
        "billing email", 
        "billing phone",
            "address line", 
            "country", 
            "city", 
            "state", 
            "zip code"
    );
            
    var shippingDetails = new ShippingDetails(
        "shipping name", 
         "shipping email", 
         "shipping phone",
         "address line", 
         "country", 
         "city", 
         "state", 
         "zip code"
    );

      

  3. Now configure the discount, note that you can apply one or more discounts using a list of  PaymentSdkCardDiscount:
      

    export interface PaymentSDKCardDiscount {
      discountCards: string[];
      discountValue: number;
      discountTitle: string;
      isPercentage: boolean;
    }
    JavaScript
    discountCards
    An array of Strings, each string must have between 4 and 10 digits, and can't be empty.
    ['41111','400000']
    JavaScript
    discountValue
     The value Number 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
    Boolean: true discountValue is a percentage, false is amount

        

    let discounts: PaymentSDKCardDiscount[] = [
        {
            discountCards: ['4111'],
            discountValue: 5,
            discountTitle: '5% Discount on VISA cards starting with 4111',
            isPercentage: true
        },
        {
            discountCards: ['4000', '41111'],
            discountValue: 10,
            discountTitle: '10 USD Discount on VISA card starts with 4000,41111',
            isPercentage: false
        }
    ];



  4. Then create an object from PaymentSDKConfiguration and fill it out with your credentials. Of course, don't forget to set the discount via the "cardDiscounts" parameter 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 Ionic SDK | Configuration Options & Parameters and 2.2 Ionic SDK | The PaymentSDKConfiguration Object solution articles,  Also for all available alternative payment methods please check 2.3 Ionic SDK | Enums solution articles.

        

    import 'paytabs-ionic-native';
    import { PayTabsIonic, PaymentSDKConfiguration  } from 'paytabs-ionic-native';
    
    let configuration: PaymentSDKConfiguration = {
              profileID: '*profile ID*',
              serverKey: '*server key*',
              clientKey: '*client key*',
              cartID: '12345',
              currency: 'USD',
              cartDescription: 'Flowers',
              merchantCountryCode: 'ae', //2 chars iso country code
              merchantName: 'Flowers Store',
              amount: 20,
              screenTitle:'Pay with Card',
              billingDetails,
              shippingDetails,
              cardDiscounts: PaymentSDKCardDiscount;
    );



  5. Only then you will be ready to start/initiate the payment by passing your PaymentSDKConfiguration to the startAlternativePaymentMethod function in which the callback event and the setState method will handle/alter the payment response. To know more about this please check our 2.2 Ionic SDK | The PaymentSDKConfiguration Object and Step 5 - Ionic SDK | Handle the payment response solution articles.

        

    const result = await PayTabsIonic.startAlternativePaymentMethod(configuration);
    
    this.handleResult(result);
    
    handleResult(result: any) {
              if (result.status == 'success') {
                // Handle transaction details here.
                const transactionDetails = result.data;
                console.log('responseCode: ' + transactionDetails.paymentResult.responseCode);
                console.log('transactionTime: ' + transactionDetails.paymentResult.transactionTime);
                console.log('responseMessage: ' + transactionDetails.paymentResult.responseMessage);
                console.log('transactionReference: ' + transactionDetails.transactionReference);
                console.log('token: ' + transactionDetails.token);
              } else if (result.status == 'error') {
                // Handle error here the code and message.
              } else if (result.status == 'event') {
                // Handle events here.
              }
    }

    

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 Ionic 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.