From 42570c01d09ebad98871a8437c01304bcda5d8f1 Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 2 Aug 2023 16:53:15 +0200 Subject: [PATCH] feat: update methods --- src/lib/sdk/billing.ts | 27 +++++++++++++++++++++++++-- src/lib/stores/stripe.ts | 4 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 2bc1c35e5..03c9cfc1f 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -530,14 +530,37 @@ export class Billing { params ); } - async updatePaymentMethod( + + async setPaymentMethod( paymentMethodId: string, providerMethodId: string | PaymentMethod + ): Promise { + const path = `/account/payment-methods/${paymentMethodId}/provider`; + const params = { + paymentMethodId, + providerMethodId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'patch', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + + async updatePaymentMethod( + paymentMethodId: string, + expiryMonth: string, + expiryYear: string ): Promise { const path = `/account/payment-methods/${paymentMethodId}`; const params = { paymentMethodId, - providerMethodId + expiryMonth, + expiryYear }; const uri = new URL(this.client.config.endpoint + path); return await this.client.call( diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index 2a2d679e0..316a1f687 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -81,7 +81,7 @@ export async function submitStripeCard(name?: string) { }); if (setupIntent && setupIntent.status === 'succeeded') { - const method = await sdk.forConsole.billing.updatePaymentMethod( + const method = await sdk.forConsole.billing.setPaymentMethod( paymentMethod.$id, setupIntent.payment_method ); @@ -118,7 +118,7 @@ export async function updateStripeCard(selectedPaymentMethod?: string) { }); if (setupIntent && setupIntent.status === 'succeeded') { - const method = await sdk.forConsole.billing.updatePaymentMethod( + const method = await sdk.forConsole.billing.setPaymentMethod( paymentMethod.$id, setupIntent.payment_method );