diff --git a/demo/app/pages/home.component.ts b/demo/app/pages/home.component.ts index 81801d3..1f84ef8 100644 --- a/demo/app/pages/home.component.ts +++ b/demo/app/pages/home.component.ts @@ -192,6 +192,9 @@ export class HomeComponent implements AfterViewInit, OnInit { console.log('onClick'); this.resetStatus(); }, + onInit: (data, actions) => { + console.log('onInit', data, actions); + } }; } diff --git a/projects/ngx-paypal-lib/src/lib/components/paypal.component.ts b/projects/ngx-paypal-lib/src/lib/components/paypal.component.ts index 6c0e517..220fb86 100644 --- a/projects/ngx-paypal-lib/src/lib/components/paypal.component.ts +++ b/projects/ngx-paypal-lib/src/lib/components/paypal.component.ts @@ -25,6 +25,8 @@ import { IOnShippingChangeActions, IOnShippingChangeData, IPayPalConfig, + IInitCallbackData, + IOnInitCallbackActions, } from '../models/paypal-models'; import { PayPalScriptService } from '../services/paypal-script.service'; @@ -246,6 +248,11 @@ export class NgxPaypalComponent implements OnChanges, OnDestroy, AfterViewInit { config.onClick(); } }, + onInit: (data: IInitCallbackData, actions: IOnInitCallbackActions) => { + if(config.onInit){ + config.onInit(data, actions); + } + } }).render(`#${this.payPalButtonContainerId}`); }); } diff --git a/projects/ngx-paypal-lib/src/lib/models/paypal-models.ts b/projects/ngx-paypal-lib/src/lib/models/paypal-models.ts index e37223b..93eec72 100644 --- a/projects/ngx-paypal-lib/src/lib/models/paypal-models.ts +++ b/projects/ngx-paypal-lib/src/lib/models/paypal-models.ts @@ -66,6 +66,12 @@ export interface IPayPalConfig { * Cancel handler */ onCancel?: (data: ICancelCallbackData, actions: any) => void; + + /** + * Init handler. + * can be used for validation, see: https://developer.paypal.com/docs/checkout/integration-features/validation/# + */ + onInit?: (data: IInitCallbackData, actions: IOnInitCallbackActions) => void; } export type TrueFalse = 'true' | 'false'; @@ -149,6 +155,15 @@ export interface IOnApproveCallbackActions { }; } +export interface IOnInitCallbackActions { + enable: () => void; + disable: () => void; +} + +export interface IInitCallbackData { + +} + export interface IPayPalButtonStyle { label?: 'paypal' | 'checkout' | 'pay' | 'installment'; size?: 'small' | 'medium' | 'large' | 'responsive';