Adds Adyen payment provider

This commit is contained in:
olivermrbl
2020-08-06 12:12:31 +02:00
parent 4c9b876407
commit 20c8dc23a1
30 changed files with 1047 additions and 16 deletions
+3 -3
View File
@@ -51,7 +51,7 @@ export default ({ rootDirectory, container, app }) => {
registerModels(pluginDetails, container)
registerServices(pluginDetails, container)
registerMedusaApi(pluginDetails, container)
registerApi(pluginDetails, app)
registerApi(pluginDetails, app, rootDirectory)
registerCoreRouters(pluginDetails, container)
registerSubscribers(pluginDetails, container)
})
@@ -111,10 +111,10 @@ function registerCoreRouters(pluginDetails, container) {
/**
* Registers the plugin's api routes.
*/
function registerApi(pluginDetails, app) {
function registerApi(pluginDetails, app, rootDirectory = "") {
try {
const routes = require(`${pluginDetails.resolve}/api`).default
app.use("/", routes())
app.use("/", routes(rootDirectory))
return app
} catch (err) {
return app
+11 -6
View File
@@ -817,13 +817,13 @@ class CartService extends BaseService {
return null
}
const data = await this.paymentProviderService_.updateSession(
pSession,
cart
)
// const data = await this.paymentProviderService_.updateSession(
// pSession,
// cart
// )
return {
provider_id: pSession.provider_id,
data,
data: {},
}
})
)
@@ -981,13 +981,18 @@ class CartService extends BaseService {
newMethods.push(option)
}
const finalMethods = newMethods.map(m => {
const { _id, ...rest } = m
return rest
})
return this.cartModel_
.updateOne(
{
_id: cart._id,
},
{
$set: { shipping_methods: newMethods },
$set: { shipping_methods: finalMethods },
}
)
.then(result => {
+36 -1
View File
@@ -179,6 +179,28 @@ class OrderService extends BaseService {
return order
}
/**
* Gets an order by metadata key value pair.
* @param {string} key - key of metadata
* @param {string} value - value of metadata
* @return {Promise<Order>} the order document
*/
async retrieveByMetadata(key, value) {
const order = await this.orderModel_
.findOne({ metadata: { [key]: value } })
.catch(err => {
throw new MedusaError(MedusaError.Types.DB_ERROR, err.message)
})
if (!order) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Order with metadata ${key}: ${value} was not found`
)
}
return order
}
/**
* Checks the existence of an order by cart id.
* @param {string} cartId - cart id to find order
@@ -321,6 +343,7 @@ class OrderService extends BaseService {
customer_id: cart.customer_id,
cart_id: cart._id,
currency_code: region.currency_code,
metadata: cart.metadata,
}
const orderDocument = await this.orderModel_.create([o], {
@@ -501,7 +524,19 @@ class OrderService extends BaseService {
provider_id
)
await paymentProvider.capturePayment(data)
const captureData = await paymentProvider.capturePayment(data)
// If Adyen is used as payment provider, we need to check the
// validity of the capture request
if (
captureData.data.pspReference &&
captureData.data.response !== "[capture-received]"
) {
throw new MedusaError(
MedusaError.Types.INVALID_ARGUMENT,
"Could not process capture"
)
}
return this.orderModel_.updateOne(
{
-4
View File
@@ -29,10 +29,6 @@ class OrderSubscriber {
await this.customerService_.addAddress(order.customer_id, address)
})
this.eventBus_.subscribe("order.placed", async order => {
await this.cartService_.delete(order.cart_id)
})
}
}