1.0.4 • Published 2 months ago

paytabs-ionic-native v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

paytabs-ionic-native

Version

PayTabs Ionic Native library is a wrapper for the native PayTabs Android and iOS SDKs, It helps you integrate with PayTabs seamlessly.

Library Support:

  • iOS
  • Android

Install

npm install paytabs-ionic-native@latest --save --force
npx cap sync

Follow the below steps to complete the installation

  • iOS
    • Navigate to the iOS folder and run the following command:
    pod install

Usage

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

Pay with Card

  1. Configure the billing & shipping info, the shipping info is optional
let billingDetails: PaymentSDKBillingDetails = {
    name: 'John Smith',
    email: 'email@domain.com',
    phone: '+201111111111',
    addressLine: 'Address line',
    city: 'Dubai',
    state: 'Dubai',
    countryCode: 'AE',
    zip: '1234'
};

const shippingDetails: PaymentSDKShippingDetails = {
    name: 'John Smith',
    email: 'email@domain.com',
    phone: '+201111111111',
    addressLine: 'Address line',
    city: 'Dubai',
    state: 'Dubai',
    countryCode: 'AE',
    zip: '1234'
};
  1. Create object of PaymentSDKConfiguration and fill it with your credentials and payment details.
  let configuration: PaymentSDKConfiguration = {
    profileID: '*profile ID*',
    serverKey: '*server key*',
    clientKey: '*client key*',
    cartID: '12345',
    currency: 'USD',
    cartDescription: 'Flowers',
    merchantCountryCode: 'ae',
    merchantName: 'Flowers Store',
    amount: 20,
    screenTitle: 'Pay with Card',
    billingDetails,
    shippingDetails,
};

Options to show billing and shipping info

       configuration.showBillingInfo = true
configuration.showShippingInfo = true    
  1. Start payment by calling startCardPayment method and handle the transaction details
    const result = await PayTabsIonic.startCardPayment(configuration);

then you can handle the result like that:

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

Pay with Apple Pay

  1. Follow the guide Steps to configure Apple Pay to learn how to configure ApplePay with PayTabs.

  2. Do the steps 1 and 2 from Pay with Card although you can ignore Billing & Shipping details and Apple Pay will handle it, also you must pass the merchant name and merchant identifier.

let configuration: PaymentSDKConfiguration = {
    profileID: '*your profile id*',
    serverKey: '*server key*',
    clientKey: '*client key*',
    cartID: '12345',
    currency: 'USD',
    cartDescription: 'Flowers',
    merchantCountryCode: 'ae',
    merchantName: 'Flowers Store',
    amount: 20,
    screenTitle: 'Pay with Card',
    merchantName: 'Flowers Store'
    merchantIdentifier = 'merchant.com.bundleID'
};
  1. To simplify ApplePay validation on all user's billing info, pass simplifyApplePayValidation parameter in the configuration with true.
configuration.simplifyApplePayValidation = true
  1. Call startApplePayPayment to start payment
    const result = await PayTabsIonic.startApplePayPayment(configuration);
this.handleResult(result);

Pay with Samsung Pay

Pass Samsung Pay token to the configuration and call startCardPayment

configuration.samsungToken = "token"

Pay with Alternative Payment Methods

It becomes easy to integrate with other payment methods in your region like STCPay, OmanNet, KNet, Valu, Fawry, UnionPay, and Meeza, to serve a large sector of customers.

  1. Do the steps 1 and 2 from Pay with Card.

  2. Choose one or more of the payment methods you want to support.

configuration.alternativePaymentMethods = [PaymentSDKConstants.AlternativePaymentMethod.stcPay]
  1. Start payment by calling startAlternativePaymentMethod method and handle the transaction details
    const result = await PayTabsIonic.startAlternativePaymentMethod(configuration);
this.handleResult(result);

Enums

Those enums will help you in customizing your configuration.

  • Tokenise types

The default type is none

exports.TokeniseType = Object.freeze({
    "none": "none", // tokenise is off
    "merchantMandatory": "merchantMandatory", // tokenise is forced
    "userMandatory": "userMandatory", // tokenise is forced as per user approval
    "userOptinoal": "userOptional" // tokenise if optional as per user approval
});
configuration.tokeniseType = cordova.plugins.CordovaPaymentPlugin.TokeniseType.userOptinoal
  • Token formats

The default format is hex32

exports.TokeniseFromat = Object.freeze({
    "none": "1",
    "hex32": "2",
    "alphaNum20": "3",
    "digit22": "3",
    "digit16": "5",
    "alphaNum32": "6"
});
configuration.tokeniseFormat = cordova.plugins.CordovaPaymentPlugin.TokeniseFromat.hex32
  • Transaction types

The default type is sale

const TransactionType = Object.freeze({
    "sale": "sale",
    "authorize": "auth"
});
configuration.transactionType = cordova.plugins.CordovaPaymentPlugin.TransactionType.sale
  • Alternative payment methods
AlternativePaymentMethod = Object.freeze({
    "unionPay": "unionpay",
    "stcPay": "stcpay",
    "valu": "valu",
    "meezaQR": "meezaqr",
    "omannet": "omannet",
    "knetCredit": "knetcredit",
    "knetDebit": "knetdebit",
    "fawry": "fawry"
});
configuration.alternativePaymentMethods = [cordova.plugins.CordovaPaymentPlugin.AlternativePaymentMethod.stcPay, ...]

API

startCardPayment(...)

startCardPayment(options
:
PaymentSDKConfiguration
) =>
Promise<any>
ParamType
optionsPaymentSDKConfiguration

Returns: Promise<any>


startTokenizedCardPayment(...)

startTokenizedCardPayment(options
:
PaymentSDKTokenizationArgument
) =>
Promise<any>
ParamType
optionsPaymentSDKTokenizationArgument

Returns: Promise<any>


start3DSecureTokenizedCardPayment(...)

start3DSecureTokenizedCardPayment(options
:
PaymentSDKConfiguration, savedCardInfo
:
PaymentSDKSavedCardInfo, token
:
string
) =>
Promise<any>
ParamType
optionsPaymentSDKConfiguration
savedCardInfoPaymentSDKSavedCardInfo
tokenstring

Returns: Promise<any>


startPaymentWithSavedCards(...)

startPaymentWithSavedCards(options
:
PaymentSDKConfiguration, support3ds
:
boolean
) =>
Promise<any>
ParamType
optionsPaymentSDKConfiguration
support3dsboolean

Returns: Promise<any>


startApplePayPayment(...)

startApplePayPayment(options
:
PaymentSDKConfiguration
) =>
Promise<any>
ParamType
optionsPaymentSDKConfiguration

Returns: Promise<any>


queryTransaction(...)

queryTransaction(options
:
PaymentSDKQueryConfiguration
) =>
Promise<any>
ParamType
optionsPaymentSDKQueryConfiguration

Returns: Promise<any>


startAlternativePaymentMethod(...)

startAlternativePaymentMethod(options
:
PaymentSDKConfiguration
) =>
Promise<any>
ParamType
optionsPaymentSDKConfiguration

Returns: Promise<any>


Interfaces

PaymentSDKConfiguration

PaymentSDKConfiguration: payment request configuration

PropTypeDescription
profileIDstringmerchant profile id
serverKeystringmerchant server key
clientKeystringmerchant client key
transactionTypestringtransaction type: refer to TransactionType enum
transactionClassstringtransaction class: refer to TransactionClass enum
cartIDstringorder or cart id
currencystringpayment currency
amountnumberamount
cartDescriptionstringorder or cart description
languageCodestringuser interface language code(en, ar, ..)
forceShippingInfobooleanvalidate shipping info
showBillingInfobooleanvalidate billing info
showShippingInfobooleanhandle missing shipping info by showing shipping info section
billingDetailsPaymentSDKBillingDetailsconfigured billing details
shippingDetailsPaymentSDKShippingDetailsconfigured shipping details
merchantCountryCodestringmerchant country code
screenTitlestringtitle of the screen
merchantNamestringmerchant name
serverIPstringserver ip
tokeniseTypestringtokenise type: refer to TokeiseType enum
tokenFormatstringtoken format: refer to TokeiseFormat enum
hideCardScannerstringoption to hide or show card scanner button
merchantApplePayIdentifierstringmerchant Apple Pay bundle id
simplifyApplePayValidationstringminimize the validation on Apple Pay billing and shipping info
supportedApplePayNetworksstringsupported Apple Pay networks
tokenstringreturned token
isDigitalProductbooleanis digital product
transactionReferencestringreturned transaction reference
samsungTokenstringsamsung Token
themePaymentSDKThemecustomized theme
alternativePaymentMethodsstringlist of alternative payment methods

PaymentSDKBillingDetails

PaymentSDKBillingDetails

PropTypeDescription
namestringbilling: customer name
emailstringbilling: customer email
phonestringbilling: customer phone
addressLinestringbilling: customer address line
citystringbilling: customer city
statestringbilling: customer state
countryCodestringbilling: customer country code
zipstringbilling: customer zip code

PaymentSDKShippingDetails

PaymentSDKShippingDetails

PropTypeDescription
namestringshipping: customer name
emailstringshipping: customer email
phonestringshipping: customer phone
addressLinestringshipping: customer address line
citystringshipping: customer city
statestringshipping: customer state
countryCodestringshipping: customer country code
zipstringshipping: customer zip code

PaymentSDKTheme

PaymentSDKTheme

PropTypeDescription
primaryColorstringtheme: primary color
primaryFontColorstringtheme: primary font color
primaryFontstringtheme: primary font
secondaryColorstringtheme: secondary color
secondaryFontColorstringtheme: secondary font color
secondaryFontstringtheme: secondary font
strokeColorstringtheme: stroke color
strokeThincknessnumbertheme: primary color
inputsCornerRadiusnumbertheme: input corner radius
buttonColorstringtheme: button color
buttonFontColorstringtheme: button font color
buttonFontstringtheme: button font
titleFontColorstringtheme: title font color
titleFontstringtheme: title font
backgroundColorstringtheme: background color
placeholderColorstringtheme: placeholder color
logoImagestringtheme: logo

PaymentSDKTokenizationArgument

PaymentSDKTokenizationArgument: tokenization configuration

PropTypeDescription
configurationsPaymentSDKConfigurationpayment configurations
tokenstringtrx token
transactionReferencestringtransaction reference

PaymentSDKSavedCardInfo

PaymentSDKSavedCardInfo

PropTypeDescription
maskedCardstringmaskedCard: Card mask
cardTypestringcardType: card type (visa, mc...)

PaymentSDKQueryConfiguration

PaymentSDKQueryConfiguration: query request configuration

PropTypeDescription
serverKeystringmerchant server key
clientKeystringmerchant client key
merchantCountryCodestringmerchant country code
profileIDstringmerchant profile id
transactionReferencestringreturned transaction reference

PaymentSDKCardDiscount

PaymentSDKCardDiscount: add discount to the payment

PropTypeDescription
discountCardsstringa list of card prefixes
discountValuestringthe discount value
discountTitlestringthe title of the discount
isPercentagestringtrue if the discount value is percentage
        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
    }
];

Demo application

Check our complete example.

PayTabs

Support | Terms of Use | Privacy Policy

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

4 months ago

1.0.0

2 years ago

0.0.1

3 years ago