fix(medusa-payment-stripe): adds missing await in updateSession

This commit is contained in:
Sebastian Rindom
2020-08-27 09:47:56 +02:00
parent 6b5d50fddf
commit 0cebcd2521
@@ -53,7 +53,8 @@ class StripeProviderService extends PaymentService {
async retrieveSavedMethods(customer) { async retrieveSavedMethods(customer) {
if (customer.metadata && customer.metadata.stripe_id) { if (customer.metadata && customer.metadata.stripe_id) {
const methods = await this.stripe_.paymentMethods.list({ const methods = await this.stripe_.paymentMethods.list({
customer: customer.metadata.stripe_id, type: "card" customer: customer.metadata.stripe_id,
type: "card",
}) })
return methods.data return methods.data
@@ -96,8 +97,6 @@ class StripeProviderService extends PaymentService {
const { customer_id, region_id } = cart const { customer_id, region_id } = cart
const { currency_code } = await this.regionService_.retrieve(region_id) const { currency_code } = await this.regionService_.retrieve(region_id)
console.log(customer_id)
let stripeCustomerId let stripeCustomerId
if (!customer_id) { if (!customer_id) {
const { id } = await this.stripe_.customers.create({ const { id } = await this.stripe_.customers.create({
@@ -106,7 +105,6 @@ class StripeProviderService extends PaymentService {
stripeCustomerId = id stripeCustomerId = id
} else { } else {
const customer = await this.customerService_.retrieve(customer_id) const customer = await this.customerService_.retrieve(customer_id)
console.log(customer)
if (!(customer.metadata && customer.metadata.stripe_id)) { if (!(customer.metadata && customer.metadata.stripe_id)) {
const { id } = await this.stripe_.customers.create({ const { id } = await this.stripe_.customers.create({
email: customer.email, email: customer.email,
@@ -120,7 +118,7 @@ class StripeProviderService extends PaymentService {
const amount = await this.totalsService_.getTotal(cart) const amount = await this.totalsService_.getTotal(cart)
const paymentIntent = await this.stripe_.paymentIntents.create({ const paymentIntent = await this.stripe_.paymentIntents.create({
customer: stripeCustomerId, customer: stripeCustomerId,
amount: amount * 100, // Stripe amount is in cents amount: parseInt(amount * 100), // Stripe amount is in cents
currency: currency_code, currency: currency_code,
setup_future_usage: "on_session", setup_future_usage: "on_session",
capture_method: "manual", capture_method: "manual",
@@ -152,9 +150,9 @@ class StripeProviderService extends PaymentService {
async updatePayment(data, cart) { async updatePayment(data, cart) {
try { try {
const { id } = data const { id } = data
const amount = this.totalsService_.getTotal(cart) const amount = await this.totalsService_.getTotal(cart)
return this.stripe_.paymentIntents.update(id, { return this.stripe_.paymentIntents.update(id, {
amount: amount * 100, amount: parseInt(amount * 100),
}) })
} catch (error) { } catch (error) {
throw error throw error
@@ -164,8 +162,7 @@ class StripeProviderService extends PaymentService {
async deletePayment(data) { async deletePayment(data) {
try { try {
const { id } = data const { id } = data
return this.stripe_.paymentIntents.cancel(id) return this.stripe_.paymentIntents.cancel(id).catch((err) => {
.catch(err => {
if (err.statusCode === 400) { if (err.statusCode === 400) {
return return
} }
@@ -215,7 +212,7 @@ class StripeProviderService extends PaymentService {
const { id } = paymentData const { id } = paymentData
try { try {
return this.stripe_.refunds.create({ return this.stripe_.refunds.create({
amount: amount * 100, amount: parseInt(amount * 100),
payment_intent: id, payment_intent: id,
}) })
} catch (error) { } catch (error) {