From 0d9f05a565510c29c3df49b56956c8f4adc3660b Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Mon, 3 Jul 2023 11:53:13 +0200 Subject: [PATCH 1/2] Allow PayPal as a payment method --- src/drive/payments/index.ts | 4 +++- src/drive/payments/types.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/drive/payments/index.ts b/src/drive/payments/index.ts index 515bae3c..3bab80bc 100644 --- a/src/drive/payments/index.ts +++ b/src/drive/payments/index.ts @@ -106,7 +106,9 @@ export class Payments { return this.client.delete('/subscriptions', this.headers()); } - public createCheckoutSession(payload: CreateCheckoutSessionPayload): Promise<{ sessionId: string }> { + public createCheckoutSession( + payload: CreateCheckoutSessionPayload, + ): Promise<{ sessionId: string } | { client_secret: string }> { return this.client.post('/checkout-session', { ...payload }, this.headers()); } diff --git a/src/drive/payments/types.ts b/src/drive/payments/types.ts index 59a13d41..353e0fec 100644 --- a/src/drive/payments/types.ts +++ b/src/drive/payments/types.ts @@ -116,6 +116,7 @@ export interface CreateCheckoutSessionPayload { success_url: string; cancel_url: string; customer_email: string; + payment_method?: string; } export interface FreeTrialAvailable { From f084078ceea24c1f68b4d104b9d7b6b08abbdaf6 Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Wed, 12 Jul 2023 10:49:35 +0200 Subject: [PATCH 2/2] feat: add getPaypalSetupIntent to get the client_secret --- src/drive/payments/index.ts | 18 +++++++++++++++--- src/drive/payments/types.ts | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/drive/payments/index.ts b/src/drive/payments/index.ts index 3bab80bc..6faa8836 100644 --- a/src/drive/payments/index.ts +++ b/src/drive/payments/index.ts @@ -106,12 +106,24 @@ export class Payments { return this.client.delete('/subscriptions', this.headers()); } - public createCheckoutSession( - payload: CreateCheckoutSessionPayload, - ): Promise<{ sessionId: string } | { client_secret: string }> { + public createCheckoutSession(payload: CreateCheckoutSessionPayload): Promise<{ sessionId: string }> { return this.client.post('/checkout-session', { ...payload }, this.headers()); } + public getPaypalSetupIntent({ + priceId, + coupon, + }: { + priceId: string; + coupon?: string; + }): Promise<{ client_secret: string }> { + const query = new URLSearchParams(); + if (priceId !== undefined) query.set('priceId', priceId); + if (coupon !== undefined) query.set('coupon', coupon); + + return this.client.get(`/paypal-setup-intent?${query.toString()}`, this.headers()); + } + /** * Returns the needed headers for the module requests * @private diff --git a/src/drive/payments/types.ts b/src/drive/payments/types.ts index 353e0fec..59a13d41 100644 --- a/src/drive/payments/types.ts +++ b/src/drive/payments/types.ts @@ -116,7 +116,6 @@ export interface CreateCheckoutSessionPayload { success_url: string; cancel_url: string; customer_email: string; - payment_method?: string; } export interface FreeTrialAvailable {