From 1f3cbe7bf1a5ee84a500ba803862ed75c779725b Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Tue, 6 Oct 2020 18:26:09 +0200 Subject: [PATCH] hotfix(medusa-plugin-brightpearl): remove AUTH/CAPTURE Removes the AUTH/CAPTURE flow; as it creates an issue when a user wants to delete an authorized order. The order will at that point have a payment and can thereby not be deleted. By simply using the RECEIPT payment type we avoid this issue and make it possible to do extended authorization periods. --- .../src/services/brightpearl.js | 33 ++----------------- .../src/subscribers/order.js | 2 +- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js index 580e40234f..c9f00fb6af 100644 --- a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js @@ -462,35 +462,6 @@ class BrightpearlService extends BaseService { ) return salesOrderId }) - .then(async (salesOrderId) => { - const paymentMethod = fromOrder.payment_method - const paymentType = "AUTH" - const payment = { - transactionRef: `${paymentMethod._id}.${paymentType}`, // Brightpearl cannot accept an auth and capture with same ref - transactionCode: fromOrder._id, - paymentMethodCode: this.options.payment_method_code || "1220", - orderId: salesOrderId, - currencyIsoCode: fromOrder.currency_code, - paymentDate: new Date(), - paymentType, - } - - // Only if authorization type - if (paymentType === "AUTH") { - const today = new Date() - const authExpire = today.setDate(today.getDate() + 7) - payment.amountAuthorized = await this.totalsService_.getTotal( - fromOrder - ) - payment.authorizationExpiry = new Date(authExpire) - } else { - // For captured - } - - await client.payments.create(payment) - - return salesOrderId - }) .then((salesOrderId) => { return this.orderService_.setMetadata( fromOrder._id, @@ -500,7 +471,7 @@ class BrightpearlService extends BaseService { }) } - async createCapturedPayment(fromOrder) { + async createPayment(fromOrder) { const client = await this.getClient() const soId = fromOrder.metadata && fromOrder.metadata.brightpearl_sales_order_id @@ -508,7 +479,7 @@ class BrightpearlService extends BaseService { return } - const paymentType = "CAPTURE" + const paymentType = "RECEIPT" const paymentMethod = fromOrder.payment_method const payment = { transactionRef: `${paymentMethod._id}.${paymentType}`, // Brightpearl cannot accept an auth and capture with same ref diff --git a/packages/medusa-plugin-brightpearl/src/subscribers/order.js b/packages/medusa-plugin-brightpearl/src/subscribers/order.js index 8c0045f311..d3c08b8139 100644 --- a/packages/medusa-plugin-brightpearl/src/subscribers/order.js +++ b/packages/medusa-plugin-brightpearl/src/subscribers/order.js @@ -22,7 +22,7 @@ class OrderSubscriber { } registerCapturedPayment = (order) => { - return this.brightpearlService_.createCapturedPayment(order) + return this.brightpearlService_.createPayment(order) } registerShipment = async (data) => {