From 8047c9ad5203f9d6b53a663907c5f07c24fe565b Mon Sep 17 00:00:00 2001 From: Aabhas Jindal Date: Tue, 11 Jul 2023 18:25:50 +0100 Subject: [PATCH] feat(cashfree-pg): support cordova-plugin-cashfree-pg 1.0.2 (#4572) Co-authored-by: aabhas_jindal --- docs/SUMMARY.md | 1 + docs/plugins/cashfree-pg/README.md | 21 ++ .../plugins/cashfree-pg/index.ts | 276 ++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 docs/plugins/cashfree-pg/README.md create mode 100644 src/@awesome-cordova-plugins/plugins/cashfree-pg/index.ts diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index c893b1a93..4802745d8 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -217,6 +217,7 @@ * [Browser Tab](plugins/browser-tab.md) * [Dynamsoft Barcode Scanner](plugins/dynamsoft-barcode-scanner.md) * [GCDWebServer](plugins/gcdwebserver.md) + * [Cashfree PG](plugins/cashfree-pg/README.md) * [Installation](installation.md) * [FAQ](faq.md) diff --git a/docs/plugins/cashfree-pg/README.md b/docs/plugins/cashfree-pg/README.md new file mode 100644 index 000000000..c1d1b8182 --- /dev/null +++ b/docs/plugins/cashfree-pg/README.md @@ -0,0 +1,21 @@ +# Cashfree PG + +``` +$ ionic cordova plugin add cordova-plugin-cashfree-pg +$ npm install @awesome-cordova-plugins/cashfree-pg +``` + +## [Usage Documentation](https://danielsogl.gitbook.io/awesome-cordova-plugins/plugins/cashfree-pg/) + +Plugin Repo: [https://github.com/cashfree/cordova-plugin-cashfree](https://github.com/cashfree/cordova-plugin-cashfree.git) +SDK Usage Documentation: [https://docs.cashfree.com/docs/cordova-integration](https://docs.cashfree.com/docs/cordova-integration) + +Cordova Plugin that wraps Cashfree PG SDK for Android and iOS + +## Supported platforms + + - Android + - iOS + + + diff --git a/src/@awesome-cordova-plugins/plugins/cashfree-pg/index.ts b/src/@awesome-cordova-plugins/plugins/cashfree-pg/index.ts new file mode 100644 index 000000000..1aa07569f --- /dev/null +++ b/src/@awesome-cordova-plugins/plugins/cashfree-pg/index.ts @@ -0,0 +1,276 @@ +import { Injectable } from '@angular/core'; +import { Cordova, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core'; +export enum CFEnvironment { + PRODUCTION = 'PRODUCTION', + SANDBOX = 'SANDBOX', +} + +export class CFSession { + payment_session_id: string; + orderID: string; + environment: string; + + constructor(sessionID: string, orderID: string, environment: CFEnvironment) { + if (sessionID === null || sessionID.trim() === '') { + throw new Error('sessionID cannot be empty'); + } + if (orderID === null || orderID.trim() === '') { + throw new Error('orderID cannot be empty'); + } + if (environment === null || environment.trim() === '') { + throw new Error('environment cannot be empty'); + } + this.payment_session_id = sessionID; + this.orderID = orderID; + this.environment = CFEnvironment[environment]; + } +} + +export enum CFPaymentModes { + CARD = 'CARD', + UPI = 'UPI', + NB = 'NB', + WALLET = 'WALLET', + EMI = 'EMI', + PAY_LATER = 'PAY_LATER', + PAYPAL = 'PAYPAL', +} + +export interface CFPaymentComponent { + hashset: Set; +} + +export class CFPaymentComponentBuilder { + private hashset: Set = new Set(); + + private enableAllModes() { + this.hashset.add(CFPaymentModes.CARD); + this.hashset.add(CFPaymentModes.UPI); + this.hashset.add(CFPaymentModes.NB); + this.hashset.add(CFPaymentModes.WALLET); + this.hashset.add(CFPaymentModes.EMI); + this.hashset.add(CFPaymentModes.PAY_LATER); + this.hashset.add(CFPaymentModes.PAYPAL); + } + + build(): CFPaymentComponent { + if (this.hashset.size === 0) { + this.enableAllModes(); + } + return { + hashset: this.hashset, + }; + } + + add(cfPaymentModes: CFPaymentModes) { + this.hashset.add(cfPaymentModes); + return this; + } +} + +export interface CFTheme { + navigationBarBackgroundColor: string; + navigationBarTextColor: string; + buttonBackgroundColor: string; + buttonTextColor: string; + backgroundColor: string; + primaryTextColor: string; + secondaryTextColor: string; +} + +export class CFThemeBuilder { + private navigationBarBackgroundColor = '#6A3FD3'; + private navigationBarTextColor = '#FFFFFF'; + private buttonBackgroundColor = '#6A3FD3'; + private buttonTextColor = '#FFFFFF'; + private backgroundColor = '#FFFFFF'; + private primaryTextColor = '#11385b'; + private secondaryTextColor = '#808080'; + + setNavigationBarBackgroundColor(value: string) { + this.navigationBarBackgroundColor = value; + return this; + } + + setNavigationBarTextColor(value: string) { + this.navigationBarTextColor = value; + return this; + } + + setButtonBackgroundColor(value: string) { + this.buttonBackgroundColor = value; + return this; + } + + setButtonTextColor(value: string) { + this.buttonTextColor = value; + return this; + } + + setPrimaryTextColor(value: string) { + this.primaryTextColor = value; + return this; + } + + setSecondaryTextColor(value: string) { + this.secondaryTextColor = value; + return this; + } + + setBackgroundColor(value: string) { + this.backgroundColor = value; + return this; + } + + build(): CFTheme { + return { + navigationBarBackgroundColor: this.navigationBarBackgroundColor, + navigationBarTextColor: this.navigationBarTextColor, + buttonBackgroundColor: this.buttonBackgroundColor, + backgroundColor: this.backgroundColor, + buttonTextColor: this.buttonTextColor, + primaryTextColor: this.primaryTextColor, + secondaryTextColor: this.secondaryTextColor, + }; + } +} + +export type CFWebTheme = CFTheme; + +export class CFWebThemeBuilder { + private navigationBarBackgroundColor = '#6A3FD3'; + private navigationBarTextColor = '#FFFFFF'; + + setNavigationBarBackgroundColor(value: string) { + this.navigationBarBackgroundColor = value; + return this; + } + + setNavigationBarTextColor(value: string) { + this.navigationBarTextColor = value; + return this; + } + + build(): CFWebTheme { + const cfTheme = new CFThemeBuilder().build(); + return { + buttonBackgroundColor: cfTheme.buttonBackgroundColor, + buttonTextColor: cfTheme.buttonTextColor, + navigationBarBackgroundColor: this.navigationBarBackgroundColor, + navigationBarTextColor: this.navigationBarBackgroundColor, + secondaryTextColor: cfTheme.secondaryTextColor, + backgroundColor: cfTheme.backgroundColor, + primaryTextColor: cfTheme.buttonTextColor, + }; + } +} + +export interface CheckoutPayment { + version: string; +} + +export class CFDropCheckoutPayment implements CheckoutPayment { + private readonly session: CFSession; + private readonly components: string[] = Array.from(new CFPaymentComponentBuilder().build().hashset); + private readonly theme: CFTheme = new CFThemeBuilder().build(); + version: string; + + constructor(session: CFSession, components: CFPaymentComponent | null, theme: CFTheme | null) { + this.session = session; + if (components !== null) { + this.components = Array.from(components.hashset); + } + if (theme !== null) { + this.theme = theme; + } + } + + getSession() { + return this.session; + } + + getComponents() { + return this.components; + } + + getTheme() { + return this.theme; + } +} + +export class CFWebCheckoutPayment implements CheckoutPayment { + private readonly session: CFSession; + private readonly theme: CFWebTheme = new CFWebThemeBuilder().build(); + version: string; + + constructor(session: CFSession, theme: CFWebTheme | null) { + this.session = session; + if (theme !== null) { + this.theme = theme; + } + } + + getSession() { + return this.session; + } + + getTheme() { + return this.theme; + } +} + +interface CFResult { + orderID: string; +} + +interface CFError { + orderID: string; + status: string; + message: string; + code: string; + type: string; +} +interface CFResult { + orderID: string; +} +export interface CFCallback { + onVerify: (result: CFResult) => void; + onError: (error: CFError) => void; +} + +@Plugin({ + pluginName: 'CFPaymentGateway', + plugin: 'cordova-plugin-cashfree-pg', + pluginRef: 'CFPaymentGateway', + repo: 'https://github.com/cashfree/cordova-plugin-cashfree', + platforms: ['Android', 'iOS'], +}) +@Injectable() +export class CFPaymentGateway extends AwesomeCordovaNativePlugin { + /** + * Initiate Drop Payment. + * @param {CFDropCheckoutPayment} [dropObject] dropPaymentObject information + */ + @Cordova() + doDropPayment(dropObject: CFDropCheckoutPayment) { + return; + } + + /** + * Initiate Web Checkout Payment. + * @param {CFWebCheckoutPayment} [webCheckoutPayment] webCheckoutPaymentObject information + */ + @Cordova() + doWebCheckoutPayment(webCheckoutPayment: CFWebCheckoutPayment) { + return; + } + + /** + * Set Callback. + * @param {CFCallback} [cfCallback] callbacks for payment. + */ + @Cordova() + setCallback(cfCallback: CFCallback) { + return; + } +}