Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions projects/ngx-paypal-lib/src/lib/components/paypal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion projects/ngx-paypal-lib/src/lib/models/paypal-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export interface IPayPalConfig {
*/
createOrderOnServer?: (data: any) => Promise<string>;

/**
* 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<string>;

/**
* Advanced configuration
*/
Expand Down Expand Up @@ -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";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use intent: "tokenize" with createBillingAgreement - here's paypal's docs

I didn't add any validation in this PR - the PayPal SDK will complain if we don't pass intent=tokenize and vault=true with createBillingAgreement, though


export type DisbursementMode = "INSTANT" | "DELAYED";

Expand Down