Merge branch 'master' of github.com:medusajs/medusa

This commit is contained in:
Sebastian Rindom
2020-08-25 18:27:01 +02:00
6 changed files with 35 additions and 14 deletions

View File

@@ -36,7 +36,16 @@ export default async (req, res) => {
region.currency_code
)
res.status(200).json({ paymentMethods: data })
// Adyen does not behave 100% correctly in regards to allowed methods
// Therefore, we sanity filter before sending them to the storefront
const { paymentMethods, groups } = data
const methods = paymentMethods.filter((pm) =>
allowedMethods.includes(pm.type)
)
res
.status(200)
.json({ paymentMethods: { paymentMethods: methods, groups } })
} catch (err) {
throw err
}

View File

@@ -24,7 +24,7 @@ class AdyenService extends BaseService {
})
this.adyenPaymentApi = axios.create({
baseURL: "https://pal-test.adyen.com/pal/servlet/Payment/v53",
baseURL: "https://pal-test.adyen.com/pal/servlet/Payment/v52",
headers: {
"Content-Type": "application/json",
"x-API-key": this.options_.api_key,
@@ -154,7 +154,7 @@ class AdyenService extends BaseService {
const { pspReference, amount } = data
try {
const captured = this.adyenPaymentApi.post("/capture", {
const captured = await this.adyenPaymentApi.post("/capture", {
originalReference: pspReference,
modificationAmount: amount,
merchantAccount: this.options_.merchant_account,
@@ -187,7 +187,7 @@ class AdyenService extends BaseService {
const { pspReference, amount } = data
try {
return this.adyenPaymentApi.post("/capture", {
return this.adyenPaymentApi.post("/refund", {
originalReference: pspReference,
merchantAccount: this.options_.merchant_account,
modificationAmount: amount,
@@ -206,7 +206,7 @@ class AdyenService extends BaseService {
const { pspReference } = paymentData
try {
return this.adyenPaymentApi.post("/capture", {
return this.adyenPaymentApi.post("/cancel", {
originalReference: pspReference,
merchantAccount: this.options_.merchant_account,
})

View File

@@ -3,11 +3,12 @@ export default async (req, res) => {
try {
const customerService = req.scope.resolve("customerService")
let customer = await customerService.retrieve(id)
customer = customerService.decorate(customer, [
"email",
"first_name",
"last_name",
])
customer = await customerService.decorate(
customer,
["email", "payment_methods", "has_account", "shipping_addresses"],
["orders"]
)
res.json({ customer })
} catch (err) {
throw err

View File

@@ -3,9 +3,14 @@ export default async (req, res) => {
try {
const orderService = req.scope.resolve("orderService")
const customerService = req.scope.resolve("customerService")
let order = await orderService.retrieve(id)
order = await orderService.decorate(order, [], ["region"])
order = await orderService.decorate(order, [], ["region", "customer"])
if (order.customer_id) {
order.customer = await customerService.retrieve(order.customer_id)
}
res.json({ order })
} catch (error) {

View File

@@ -5,7 +5,13 @@ export default async (req, res) => {
const data = await profileService.retrieve(profile_id)
res.status(200).json({ shipping_profile: data })
const profile = await profileService.decorate(
data,
["name"],
["products", "shipping_options"]
)
res.status(200).json({ shipping_profile: profile })
} catch (err) {
throw err
}

View File

@@ -333,13 +333,13 @@ class ShippingProfileService extends BaseService {
const requiredFields = ["_id", "metadata"]
let decorated = _.pick(profile, fields.concat(requiredFields))
if (expandFields.includes("products")) {
if (expandFields.includes("products") && profile.products) {
decorated.products = await Promise.all(
profile.products.map(pId => this.productService_.retrieve(pId))
)
}
if (expandFields.includes("shipping_options")) {
if (expandFields.includes("shipping_options") && profile.shipping_options) {
decorated.shipping_options = await Promise.all(
profile.shipping_options.map(oId =>
this.shippingOptionService_.retrieve(oId)