registers payment/fulfillment providers with correct names
This commit is contained in:
@@ -5,7 +5,7 @@ import { PaymentService } from "medusa-interfaces"
|
|||||||
class StripeProviderService extends PaymentService {
|
class StripeProviderService extends PaymentService {
|
||||||
static identifier = "stripe"
|
static identifier = "stripe"
|
||||||
|
|
||||||
constructor({ customerService, totalsService }, options) {
|
constructor({ customerService, totalsService, regionService }, options) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.options_ = options
|
this.options_ = options
|
||||||
@@ -14,6 +14,8 @@ class StripeProviderService extends PaymentService {
|
|||||||
|
|
||||||
this.customerService_ = customerService
|
this.customerService_ = customerService
|
||||||
|
|
||||||
|
this.regionService_ = regionService
|
||||||
|
|
||||||
this.totalsService_ = totalsService
|
this.totalsService_ = totalsService
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +78,10 @@ class StripeProviderService extends PaymentService {
|
|||||||
* @returns {string} id of payment intent
|
* @returns {string} id of payment intent
|
||||||
*/
|
*/
|
||||||
async createPayment(cart) {
|
async createPayment(cart) {
|
||||||
const { customer_id } = cart
|
const { customer_id, region_id } = cart
|
||||||
|
const { currency_code } = await this.regionService_.retrieve(region_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({
|
||||||
email: cart.email,
|
email: cart.email,
|
||||||
@@ -97,10 +99,11 @@ class StripeProviderService extends PaymentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const amount = 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: amount * 100, // Stripe amount is in cents
|
||||||
|
currency: currency_code
|
||||||
})
|
})
|
||||||
|
|
||||||
return paymentIntent
|
return paymentIntent
|
||||||
|
|||||||
@@ -32,10 +32,6 @@ export default app => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Shipping Options
|
// Shipping Options
|
||||||
route.post(
|
|
||||||
"/:id/shipping-options",
|
|
||||||
middlewares.wrap(require("./create-shipping-options").default)
|
|
||||||
)
|
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/shipping-methods",
|
"/:id/shipping-methods",
|
||||||
middlewares.wrap(require("./add-shipping-method").default)
|
middlewares.wrap(require("./add-shipping-method").default)
|
||||||
|
|||||||
@@ -148,12 +148,14 @@ function registerServices(pluginDetails, container) {
|
|||||||
cradle => new loaded(cradle, pluginDetails.options)
|
cradle => new loaded(cradle, pluginDetails.options)
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
const name = formatRegistrationName(fn)
|
|
||||||
container.register({
|
|
||||||
[name]: asFunction(cradle => new loaded(cradle, pluginDetails.options)),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always register the service with a nice name, if we need to import it
|
||||||
|
// from somewhere
|
||||||
|
const name = formatRegistrationName(fn)
|
||||||
|
container.register({
|
||||||
|
[name]: asFunction(cradle => new loaded(cradle, pluginDetails.options)),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -692,7 +692,15 @@ class CartService extends BaseService {
|
|||||||
if (!region.payment_providers.includes(pSession.provider_id)) {
|
if (!region.payment_providers.includes(pSession.provider_id)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return this.paymentProviderService_.updateSession(pSession, cart)
|
|
||||||
|
const data = await this.paymentProviderService_.updateSession(
|
||||||
|
pSession,
|
||||||
|
cart
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
provider_id: pSession.provider_id,
|
||||||
|
data,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -708,13 +716,20 @@ class CartService extends BaseService {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.paymentProviderService_.createSession(pId, cart)
|
const data = await this.paymentProviderService_.createSession(pId, cart)
|
||||||
|
return {
|
||||||
|
provider_id: pId,
|
||||||
|
data,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Filter null sessions
|
// Filter null sessions
|
||||||
newSessions = newSessions.filter(s => !!s)
|
newSessions = newSessions.filter(s => !!s)
|
||||||
|
|
||||||
|
console.log(sessions)
|
||||||
|
console.log(newSessions)
|
||||||
|
|
||||||
// Update the payment sessions with the concatenated array of updated and
|
// Update the payment sessions with the concatenated array of updated and
|
||||||
// newly created payment sessions
|
// newly created payment sessions
|
||||||
return this.cartModel_
|
return this.cartModel_
|
||||||
|
|||||||
@@ -335,8 +335,9 @@ class ShippingProfileService extends BaseService {
|
|||||||
async fetchCartOptions(cart) {
|
async fetchCartOptions(cart) {
|
||||||
const products = this.getProductsInCart_(cart)
|
const products = this.getProductsInCart_(cart)
|
||||||
const profiles = await this.list({ products: { $in: products } })
|
const profiles = await this.list({ products: { $in: products } })
|
||||||
const optionIds = profiles.reduce((acc, next) =>
|
const optionIds = profiles.reduce(
|
||||||
acc.concat(next.shipping_options)
|
(acc, next) => acc.concat(next.shipping_options),
|
||||||
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
const options = await Promise.all(
|
const options = await Promise.all(
|
||||||
|
|||||||
Reference in New Issue
Block a user