Setup future usage

This commit is contained in:
Sebastian Rindom committed 2020-07-13 17:35:50 +02:00
1 parent eeae2a056c
commit cd989c56a7
20 files changed
+282 -26

No files matched your search

@@ -50,7 +50,22 @@ class StripeProviderService extends PaymentService {
return status
}
async retrieveSavedMethods(customer) {
if (customer.metadata && customer.metadata.stripe_id) {
const methods = await this.stripe_.paymentMethods.list({
customer: customer.metadata.stripe_id, type: "card"
})
return methods.data
}
return Promise.resolve([])
}
async retrieveCustomer(customerId) {
if (!customerId) {
return Promise.resolve()
}
return this.stripe_.customers.retrieve(customerId)
}
@@ -104,6 +119,7 @@ class StripeProviderService extends PaymentService {
customer: stripeCustomerId,
amount: amount * 100, // Stripe amount is in cents
currency: currency_code,
setup_future_usage: "on-session",
capture_method: "manual",
metadata: { cart_id: `${cart._id}` },
})
@@ -29,8 +29,14 @@ class CartSubscriber {
const customer = await this.customerService_.retrieve(customer_id)
const stripeSession = payment_sessions.find(s => s.provider_id === "stripe")
if (!stripeSession) {
return Promise.resolve()
}
const paymentIntent = await this.stripeProviderService_.retrievePayment(
cart
stripeSession.data
)
let stripeCustomer = await this.stripeProviderService_.retrieveCustomer(