@@ -3,17 +3,20 @@ import type { UserModel } from '../../../../orm/src/models/User'
3
3
import { stripe } from '..'
4
4
5
5
6
- export interface ManageCharge {
7
- addPaymentMethod : ( user : UserModel , paymentMethod : string | Stripe . PaymentMethod ) => Promise < Stripe . PaymentMethod >
6
+ export interface ManagePaymentMethod {
7
+ addPaymentMethod : ( user : UserModel , paymentMethod : string | Stripe . PaymentMethod ) => Promise < Stripe . Response < Stripe . PaymentMethod > >
8
+ updatePaymentMethod : ( user : UserModel , paymentMethodId : string , updateParams : Stripe . PaymentMethodUpdateParams ) => Promise < Stripe . Response < Stripe . PaymentMethod > >
9
+ deletePaymentMethod : ( user : UserModel , paymentMethodId : string ) => Promise < Stripe . Response < Stripe . PaymentMethod > >
10
+ retrievePaymentMethod : ( user : UserModel , paymentMethodId : string ) => Promise < Stripe . Response < Stripe . PaymentMethod > >
8
11
}
9
12
10
- export const managePaymentMethod : ManageCharge = ( ( ) => {
11
- async function addPaymentMethod ( user : UserModel , paymentMethod : string | Stripe . PaymentMethod ) : Promise < Stripe . PaymentMethod > {
13
+ export const managePaymentMethod : ManagePaymentMethod = ( ( ) => {
14
+ async function addPaymentMethod ( user : UserModel , paymentMethod : string | Stripe . PaymentMethod ) : Promise < Stripe . Response < Stripe . PaymentMethod > > {
12
15
if ( ! user . hasStripeId ( ) ) {
13
16
throw new Error ( 'Customer does not exist in Stripe' )
14
17
}
15
18
16
- let stripePaymentMethod : Stripe . PaymentMethod
19
+ let stripePaymentMethod
17
20
18
21
if ( typeof paymentMethod === 'string' ) {
19
22
stripePaymentMethod = await stripe . paymentMethod . retrieve ( paymentMethod )
@@ -27,10 +30,10 @@ export const managePaymentMethod: ManageCharge = (() => {
27
30
} )
28
31
}
29
32
30
- return stripePaymentMethod
33
+ return stripePaymentMethod as Stripe . Response < Stripe . PaymentMethod >
31
34
}
32
35
33
- async function deletePaymentMethod ( user : UserModel , paymentMethodId : string ) : Promise < Stripe . PaymentMethod > {
36
+ async function deletePaymentMethod ( user : UserModel , paymentMethodId : string ) : Promise < Stripe . Response < Stripe . PaymentMethod > > {
34
37
if ( ! user . hasStripeId ( ) ) {
35
38
throw new Error ( 'Customer does not exist in Stripe' )
36
39
}
@@ -44,7 +47,7 @@ export const managePaymentMethod: ManageCharge = (() => {
44
47
return await stripe . paymentMethod . detach ( paymentMethodId )
45
48
}
46
49
47
- async function updatePaymentMethod ( user : UserModel , paymentMethodId : string , updateParams : Stripe . PaymentMethodUpdateParams ) : Promise < Stripe . PaymentMethod > {
50
+ async function updatePaymentMethod ( user : UserModel , paymentMethodId : string , updateParams : Stripe . PaymentMethodUpdateParams ) : Promise < Stripe . Response < Stripe . PaymentMethod > > {
48
51
if ( ! user . hasStripeId ( ) ) {
49
52
throw new Error ( 'Customer does not exist in Stripe' )
50
53
}
@@ -58,7 +61,7 @@ export const managePaymentMethod: ManageCharge = (() => {
58
61
return await stripe . paymentMethod . update ( paymentMethodId , updateParams )
59
62
}
60
63
61
- async function retrievePaymentMethod ( user : UserModel , paymentMethodId : string ) : Promise < Stripe . PaymentMethod > {
64
+ async function retrievePaymentMethod ( user : UserModel , paymentMethodId : string ) : Promise < Stripe . Response < Stripe . PaymentMethod > > {
62
65
if ( ! user . hasStripeId ( ) ) {
63
66
throw new Error ( 'Customer does not exist in Stripe' )
64
67
}
0 commit comments