/
default-payment-options.ts
53 lines (44 loc) 路 1.37 KB
/
default-payment-options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Stripe from 'stripe'
type StripeConfig = {
stripeSecretKey: string
apiVersion: '2020-08-27'
}
type StripeProvider = {name: 'stripe'; paymentClient: Stripe}
type StripeProviderFunction = (options: StripeConfig) => StripeProvider
type Paypal = 'paypal-client'
type PaypalProvider = {name: 'paypal'; paymentClient: Paypal}
type PaypalProviderFunction = (options: {
paypalSecretKey: string
}) => PaypalProvider
type PaymentProviderOptions = StripeProvider | PaypalProvider
export type PaymentOptions = {
providers: {
stripe?: StripeProvider
paypal?: PaypalProvider
}
}
// define providers here for now,
// but eventually they can go in a `providers/` directory
export const StripeProvider: StripeProviderFunction = (config) => {
const stripeClient = new Stripe(config.stripeSecretKey, {
apiVersion: config.apiVersion,
})
return {
name: 'stripe',
paymentClient: stripeClient,
}
}
// Two concepts for the providers:
// 1. We have the Payment Provider Functions (factories?) that take a few config values
// 2. We have the Payment Provider Options which are the resulting object of the above function
export const defaultPaymentOptions = (options: {
stripeProvider?: StripeProvider
paypalProvider?: PaypalProvider
}): PaymentOptions => {
return {
providers: {
stripe: options.stripeProvider,
paypal: options.paypalProvider,
},
}
}