From 768b8a0146858d9cb07a5d8516499f8e7a07b044 Mon Sep 17 00:00:00 2001 From: Mohamed Adly Date: Thu, 3 Jun 2021 10:33:01 +0200 Subject: [PATCH 1/2] add paytabs plugin wrapper --- src/@ionic-native/plugins/paytabs/index.ts | 138 +++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/@ionic-native/plugins/paytabs/index.ts diff --git a/src/@ionic-native/plugins/paytabs/index.ts b/src/@ionic-native/plugins/paytabs/index.ts new file mode 100644 index 0000000000..987944d76d --- /dev/null +++ b/src/@ionic-native/plugins/paytabs/index.ts @@ -0,0 +1,138 @@ +import { Injectable } from '@angular/core'; +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; + +export enum TokeniseType { + none = "none", + merchantMandatory = "merchantMandatory", + userMandatory = "userMandatory", + userOptinoal = "userOptinoal", +} + +export enum TokeniseFromat { + none = "1", + hex32 = "2", + alphaNum20 = "3", + digit22 = "3", + digit16 = "5", + alphaNum32 = "6" +} + +export enum TransactionType { + sale = "sale", + authorize = "auth" +} + +export enum TransactionClass { + ecom = "ecom", + recurring = "recur" +} + +export enum AlternativePaymentMethod { + unionPay = "unionpay", + stcPay = "stcpay", + valu = "valu", + meezaQR = "meezaqr", + omannet = "omannet", + knetCredit = "knetcredit", + knetDebit = "knetdebit", + fawry = "fawry" +} + +export interface PaymentSDKBillingDetails { + name?: string; + email?: string; + phone?: string; + addressLine?: string; + city?: string; + state?: string; + countryCode?: string; + zip? : string; +} + +export interface PaymentSDKShippingDetails { + name?: string; + email?: string; + phone?: string; + addressLine?: string; + city?: string; + state?: string; + countryCode?: string; + zip? : string; +} +export interface PaymentSDKTheme { + primaryColor?: string; + primaryFontColor?: string; + primaryFont?: string; + secondaryColor?: string; + secondaryFontColor?: string; + secondaryFont?: string; + strokeColor?: string; + strokeThinckness?: number; + inputsCornerRadius?: number; + buttonColor?: string; + buttonFontColor?: string; + buttonFont?: string; + titleFontColor?: string; + titleFont?: string; + backgroundColor?: string; + placeholderColor?: string; +} + +export interface PaymentSDKConfiguration { + profileID: string; + serverKey: string; + clientKey: string; + transactionType?: string; + transactionClass?: string; + cartID: string; + currency: string; + amount: number; + cartDescription: string; + languageCode?: string; + forceShippingInfo?: boolean; + showBillingInfo?: boolean; + showShippingInfo?: boolean; + billingDetails?: PaymentSDKBillingDetails; + shippingDetails?: PaymentSDKShippingDetails; + merchantCountryCode: string; + screenTitle?: string; + merchantName?: string; + serverIP?: string; + tokeniseType?: string; + tokenFormat?: string; + hideCardScanner?: string; + merchantApplePayIdentifier?: string; + simplifyApplePayValidation?: string; + supportedApplePayNetworks?: [string]; + token?: string; + transactionReference?: string; + samsungToken?: string; + theme?: PaymentSDKTheme; + alternativePaymentMethods?: [string]; +} + +@Plugin({ + pluginName: 'PayTabs', + plugin: 'com.paytabs.cordova.plugin', + pluginRef: 'com.paytabs.cordova.plugin', + repo: 'https://github.com/paytabscom/paytabs-cordova', + platforms: ['Android', 'iOS'], +}) + +@Injectable() +export class PayTabs extends IonicNativePlugin { + @Cordova() + startCardPayment(configuration: PaymentSDKConfiguration): Promise { + return; + } + + @Cordova() + startApplePayPayment(configuration: PaymentSDKConfiguration): Promise { + return; + } + + @Cordova() + startAlternativePaymentMethod(configuration: PaymentSDKConfiguration): Promise { + return; + } +} \ No newline at end of file From cc18422aef9bb367f99d581c97a21a55c716e1e2 Mon Sep 17 00:00:00 2001 From: Mohamed Adly Date: Tue, 22 Jun 2021 17:48:33 +0200 Subject: [PATCH 2/2] added comments and examples --- src/@ionic-native/plugins/paytabs/index.ts | 490 ++++++++++++++++++--- 1 file changed, 417 insertions(+), 73 deletions(-) diff --git a/src/@ionic-native/plugins/paytabs/index.ts b/src/@ionic-native/plugins/paytabs/index.ts index 987944d76d..042de52f58 100644 --- a/src/@ionic-native/plugins/paytabs/index.ts +++ b/src/@ionic-native/plugins/paytabs/index.ts @@ -1,116 +1,447 @@ import { Injectable } from '@angular/core'; import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; -export enum TokeniseType { - none = "none", - merchantMandatory = "merchantMandatory", - userMandatory = "userMandatory", - userOptinoal = "userOptinoal", -} - -export enum TokeniseFromat { - none = "1", - hex32 = "2", - alphaNum20 = "3", - digit22 = "3", - digit16 = "5", - alphaNum32 = "6" -} - -export enum TransactionType { - sale = "sale", - authorize = "auth" -} - -export enum TransactionClass { - ecom = "ecom", - recurring = "recur" -} - -export enum AlternativePaymentMethod { - unionPay = "unionpay", - stcPay = "stcpay", - valu = "valu", - meezaQR = "meezaqr", - omannet = "omannet", - knetCredit = "knetcredit", - knetDebit = "knetdebit", - fawry = "fawry" +/** +* PaymentSDKConfiguration: payment request configuration +*/ +export interface PaymentSDKConfiguration { + /** + * merchant profile id + */ + profileID: string; + /** + * merchant server key + */ + serverKey: string; + /** + * merchant client key + */ + clientKey: string; + /** + * transaction type: refer to TransactionType enum + */ + transactionType?: string; + /** + * transaction class: refer to TransactionClass enum + */ + transactionClass?: string; + /** + * order or cart id + */ + cartID: string; + /** + * payment currency + */ + currency: string; + /** + * amount + */ + amount: number; + /** + * order or cart description + */ + cartDescription: string; + /** + * user interface language code(en, ar, ..) + */ + languageCode?: string; + /** + * validate shipping info + */ + forceShippingInfo?: boolean; + /** + * validate billing info + */ + showBillingInfo?: boolean; + /** + * handle missing shipping info by showing shipping info section + */ + showShippingInfo?: boolean; + /** + * configured billing details + */ + billingDetails?: PaymentSDKBillingDetails; + /** + * configured shipping details + */ + shippingDetails?: PaymentSDKShippingDetails; + /** + * merchant country code + */ + merchantCountryCode: string; + /** + * title of the screen + */ + screenTitle?: string; + /** + * merchant name + */ + merchantName?: string; + /** + * server ip + */ + serverIP?: string; + /** + * tokenise type: refer to TokeiseType enum + */ + tokeniseType?: string; + /** + * token format: refer to TokeiseFormat enum + */ + tokenFormat?: string; + /** + * option to hide or show card scanner button + */ + hideCardScanner?: string; + /** + * merchant apple pay bundle id + */ + merchantApplePayIdentifier?: string; + /** + * minize the vlaidation on apple pay billing and shipping info + */ + simplifyApplePayValidation?: string; + /** + * supported apple pay networks + */ + supportedApplePayNetworks?: [string]; + /** + * returned token + */ + token?: string; + /** + * returned transaction reference + */ + transactionReference?: string; + /** + * samsung Token + */ + samsungToken?: string; + /** + * customized theme + */ + theme?: PaymentSDKTheme; + /** + * list of alternative payment methods + */ + alternativePaymentMethods?: [string]; } +/** +* PaymentSDKBillingDetails +*/ export interface PaymentSDKBillingDetails { + /** + * billing: customer name + */ name?: string; + /** + * billing: customer email + */ email?: string; + /** + * billing: customer phone + */ phone?: string; + /** + * billing: customer address line + */ addressLine?: string; + /** + * billing: customer city + */ city?: string; + /** + * billing: customer state + */ state?: string; + /** + * billing: customer country code + */ countryCode?: string; - zip? : string; + /** + * billing: customer zip code + */ + zip?: string; } +/** +* PaymentSDKShippingDetails +*/ export interface PaymentSDKShippingDetails { + /** + * shipping: customer name + */ name?: string; + /** + * shipping: customer email + */ email?: string; + /** + * shipping: customer phone + */ phone?: string; + /** + * shipping: customer address line + */ addressLine?: string; + /** + * shipping: customer city + */ city?: string; + /** + * shipping: customer state + */ state?: string; + /** + * shipping: customer country code + */ countryCode?: string; - zip? : string; + /** + * shipping: customer zip code + */ + zip?: string; } + +/** +* PaymentSDKTheme +*/ export interface PaymentSDKTheme { + /** + * theme: primary color + */ primaryColor?: string; + /** + * theme: primary font color + */ primaryFontColor?: string; + /** + * theme: primary font + */ primaryFont?: string; + /** + * theme: secondary color + */ secondaryColor?: string; + /** + * theme: secondary font color + */ secondaryFontColor?: string; + /** + * theme: secondary font + */ secondaryFont?: string; + /** + * theme: stroke color + */ strokeColor?: string; + /** + * theme: primary color + */ strokeThinckness?: number; + /** + * theme: input corner radius + */ inputsCornerRadius?: number; + /** + * theme: button color + */ buttonColor?: string; + /** + * theme: button font color + */ buttonFontColor?: string; + /** + * theme: button font + */ buttonFont?: string; + /** + * theme: title font color + */ titleFontColor?: string; + /** + * theme: title font + */ titleFont?: string; + /** + * theme: background color + */ backgroundColor?: string; + /** + * theme: placeholder color + */ placeholderColor?: string; } -export interface PaymentSDKConfiguration { - profileID: string; - serverKey: string; - clientKey: string; - transactionType?: string; - transactionClass?: string; - cartID: string; - currency: string; - amount: number; - cartDescription: string; - languageCode?: string; - forceShippingInfo?: boolean; - showBillingInfo?: boolean; - showShippingInfo?: boolean; - billingDetails?: PaymentSDKBillingDetails; - shippingDetails?: PaymentSDKShippingDetails; - merchantCountryCode: string; - screenTitle?: string; - merchantName?: string; - serverIP?: string; - tokeniseType?: string; - tokenFormat?: string; - hideCardScanner?: string; - merchantApplePayIdentifier?: string; - simplifyApplePayValidation?: string; - supportedApplePayNetworks?: [string]; - token?: string; - transactionReference?: string; - samsungToken?: string; - theme?: PaymentSDKTheme; - alternativePaymentMethods?: [string]; +/** +* TokeniseType: define the behaviour of of saving card option inside the SDKs. +*/ +export enum TokeniseType { + /** + * none: tokenise is off + */ + none = "none", + /** + * merchantMandatory: tokenise is forced + */ + merchantMandatory = "merchantMandatory", + /** + * userMandatory: tokenise is forced as per user approval + */ + userMandatory = "userMandatory", + /** + * userOptinoal: tokenise if optional as per user approval + */ + userOptinoal = "userOptinoal", } +/** +* TokeniseFromat: the returned token format +*/ +export enum TokeniseFromat { + /** + * none: no format + */ + none = "1", + /** + * hex32: Hex with 32 length + */ + hex32 = "2", + /** + * alphaNum20: alpha numeric 20 length + */ + alphaNum20 = "3", + /** + * digit22: digits with 22 length + */ + digit22 = "3", + /** + * digit16: digits with 16 length + */ + digit16 = "5", + /** + * alphaNum32: alpha numeric 32 length + */ + alphaNum32 = "6" +} + +/** +* TransactionType +*/ +export enum TransactionType { + /** + * sale + */ + sale = "sale", + /** + * authorize / capture option + */ + authorize = "auth" +} + +/** +* TransactionClass +*/ +export enum TransactionClass { + /** + * ecom: default transaction + */ + ecom = "ecom", + /** + * recurring: recurring transaction + */ + recurring = "recur" +} + +/** +* AlternativePaymentMethod +*/ +export enum AlternativePaymentMethod { + /** + * unionpay: for supporting payment with unionpay + */ + unionPay = "unionpay", + /** + * stcpay: for supporting payment with stcpay + */ + stcPay = "stcpay", + /** + * valu: for supporting payment with valu + */ + valu = "valu", + /** + * meezaqr: for supporting payment with meezaqr + */ + meezaQR = "meezaqr", + /** + * omannet: for supporting payment with omannet + */ + omannet = "omannet", + /** + * knetcredit: for supporting payment with knetcredit + */ + knetCredit = "knetcredit", + /** + * knetdebit: for supporting payment with knetdebit + */ + knetDebit = "knetdebit", + /** + * fawry: for supporting payment with fawry + */ + fawry = "fawry" +} + +/** + * @name PayTabs + * @description + * A plugin that allows you to use PayTabs's Native SDKs for Android and iOS. + * + * @usage + * ```typescript + * import { PayTabs } from '@ionic-native/paytabs/ngx'; + * + * constructor(private paytabs: PayTabs) { } + * + * ... + * let billingDetails: PaymentSDKBillingDetails = { + * name: "John Smith", + * email: "email@domain.com", + * phone: "+201111111111", + * addressLine: "Address line", + * city: "Dubai", + * state: "Dubai", + * countryCode: "AE", + * zip: "1234" + * }; + * + * var configuration: PaymentSDKConfiguration = { + * profileID: "*profile id*", + * serverKey: "*server key*", + * clientKey: "*cleint key*", + * cartID: "12345", + * currency: "USD", + * cartDescription: "Flowers", + * merchantCountryCode: "ae", + * merchantName: "Flowers Store", + * amount: 20, + * screenTitle:"Pay with Card", + * billingDetails: billingDetails + * } + * + * this.paytabs.startCardPayment(configuration) + * .then(result => console.log(result)) + * .catch(error => console.error(error)); + * + * this.paytabs.startApplePayPayment(configuration) + * .then(result => console.log(result)) + * .catch(error => console.error(error)); + * + * this.paytabs.startAlternativePaymentMethod(configuration) + * .then(result => console.log(result)) + * .catch(error => console.error(error)); + * + * ``` +*/ @Plugin({ pluginName: 'PayTabs', plugin: 'com.paytabs.cordova.plugin', @@ -121,18 +452,31 @@ export interface PaymentSDKConfiguration { @Injectable() export class PayTabs extends IonicNativePlugin { + /** + * Start Card Payment + * @param params {PaymentSDKConfiguration} payment request configuration + * @return {Promise} returns a promise that resolves with transaction details, or rejects with an error + */ @Cordova() - startCardPayment(configuration: PaymentSDKConfiguration): Promise { + startCardPayment(configuration: PaymentSDKConfiguration): Promise { return; } - + /** + * Start ApplePay Payment + * @param params {PaymentSDKConfiguration} payment request configuration + * @return {Promise} returns a promise that resolves with transaction details, or rejects with an error + */ @Cordova() - startApplePayPayment(configuration: PaymentSDKConfiguration): Promise { + startApplePayPayment(configuration: PaymentSDKConfiguration): Promise { return; } - + /** + * Start Alternative Payment Method + * @param params {PaymentSDKConfiguration} payment request configuration + * @return {Promise} returns a promise that resolves with transaction details, or rejects with an error + */ @Cordova() - startAlternativePaymentMethod(configuration: PaymentSDKConfiguration): Promise { + startAlternativePaymentMethod(configuration: PaymentSDKConfiguration): Promise { return; } } \ No newline at end of file