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 a05723d..c51e794 100644 --- a/projects/ngx-paypal-lib/src/lib/components/paypal.component.ts +++ b/projects/ngx-paypal-lib/src/lib/components/paypal.component.ts @@ -256,6 +256,14 @@ export class NgxPaypalComponent implements OnChanges, OnDestroy, AfterViewInit { }); }; + const createBillingAgreement = () => { + return this.ngZone.run(() => { + if (config.createBillingAgreement) { + return config.createBillingAgreement(); + } + }); + }; + const buttonsConfig = { style: config.style, fundingSource: undefined, @@ -323,6 +331,8 @@ export class NgxPaypalComponent implements OnChanges, OnDestroy, AfterViewInit { // The onShippingChange callback cannot be used with subscriptions // so we only add it if it is set ...(config.onShippingChange && { onShippingChange }), + // only add createBillingAgreement if it is set + ...(config.createBillingAgreement && { createBillingAgreement }), }; let fundSource = undefined; 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 643b8bb..e296679 100644 --- a/projects/ngx-paypal-lib/src/lib/models/paypal-models.ts +++ b/projects/ngx-paypal-lib/src/lib/models/paypal-models.ts @@ -19,6 +19,12 @@ export interface IPayPalConfig { */ createOrderOnServer?: (data: any) => Promise; + /** + * Use when creating a billing agreement for recurring payments - a legacy feature similar to subscriptions. + * See https://developer.paypal.com/docs/api/payments.billing-agreements/v1/ + */ + createBillingAgreement?: () => Promise; + /** * Advanced configuration */ @@ -293,7 +299,7 @@ export type ShippingPreference = export type PaypalLandingPage = "LOGIN" | "BILLING"; -export type OrderIntent = "CAPTURE" | "AUTHORIZE" | "subscription"; +export type OrderIntent = "CAPTURE" | "AUTHORIZE" | "subscription" | "tokenize"; export type DisbursementMode = "INSTANT" | "DELAYED";