From 5c4f9c513805df82a8d1c321a4c89f4281650e70 Mon Sep 17 00:00:00 2001 From: Alexandre Magno Date: Tue, 19 Sep 2023 17:31:53 +0200 Subject: [PATCH] fix: fixing Paypal payments --- modules/orders/orderBuilds.js | 18 ++++++++++++++---- modules/orders/orderCancel.js | 12 ++++++++++-- modules/orders/orderPayment.js | 5 ++++- modules/orders/orderRefund.js | 5 ++++- modules/tasks/taskUpdate.js | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/modules/orders/orderBuilds.js b/modules/orders/orderBuilds.js index 520eb0766..7d84795e3 100644 --- a/modules/orders/orderBuilds.js +++ b/modules/orders/orderBuilds.js @@ -53,9 +53,15 @@ module.exports = Promise.method(function orderBuilds (orderParameters) { 'order_id': order.dataValues.id } }).then(invoice => { - return order.updateAttributes({ - source_id: invoice.id - }).then(orderUpdated => { + return order.update( + { + source_id: invoice.id + }, + { + where: { + id: order.dataValues.id + } + }).then(orderUpdated => { return orderUpdated }) }) @@ -111,11 +117,15 @@ module.exports = Promise.method(function orderBuilds (orderParameters) { const paymentUrl = paymentData.links[1].href const resultUrl = URL.parse(paymentUrl) const searchParams = new URLSearchParams(resultUrl.search) - return order.updateAttributes({ + return order.update({ source_id: paymentData.id, authorization_id: paymentData.purchase_units && paymentData.purchase_units[0] && paymentData.purchase_units[0].payments && paymentData.purchase_units[0].payments.authorizations[0].id, payment_url: paymentUrl, token: searchParams.get('token') + }, { + where: { + id: order.dataValues.id + } }).then(orderUpdated => { return orderUpdated }) diff --git a/modules/orders/orderCancel.js b/modules/orders/orderCancel.js index faa2fbd06..bbac22e0c 100644 --- a/modules/orders/orderCancel.js +++ b/modules/orders/orderCancel.js @@ -44,9 +44,13 @@ module.exports = Promise.method(function orderCancel (orderParameters) { }).then(payment => { // eslint-disable-next-line no-console console.log('payment response for cancel', payment) - return order.updateAttributes({ + return order.update({ status: 'canceled', paid: 'false' + }, { + where: { + id: order.dataValues.id + } }).then(orderUpdated => { // eslint-disable-next-line no-console console.log('orderUpdated', orderUpdated) @@ -59,9 +63,13 @@ module.exports = Promise.method(function orderCancel (orderParameters) { }).catch(e => { // eslint-disable-next-line no-console console.log('couldnt find payment source cancel anyway, reason:', e) - return order.updateAttributes({ + return order.update({ status: 'canceled', paid: 'false' + }, { + where: { + id: order.dataValues.id + } }).then(orderUpdated => { // eslint-disable-next-line no-console console.log('orderUpdated', orderUpdated) diff --git a/modules/orders/orderPayment.js b/modules/orders/orderPayment.js index 7cd05dcfd..bee0bbd52 100644 --- a/modules/orders/orderPayment.js +++ b/modules/orders/orderPayment.js @@ -36,9 +36,12 @@ module.exports = Promise.method(function orderPayment (orderParameters) { const paymentData = JSON.parse(payment) // eslint-disable-next-line no-console console.log('payment execute result', payment, paymentData) - return order.updateAttributes({ + return order.update({ transfer_id: paymentData.id }, { + where: { + id: order.id + }, include: [models.Task, models.User], returning: true, plain: true diff --git a/modules/orders/orderRefund.js b/modules/orders/orderRefund.js index 886526a53..91dbede38 100644 --- a/modules/orders/orderRefund.js +++ b/modules/orders/orderRefund.js @@ -68,10 +68,13 @@ module.exports = Promise.method(function orderRefund (orderParams) { } }).then(payment => { const paymentData = JSON.parse(payment) - return order.updateAttributes({ + return order.update({ status: 'refunded', refund_id: paymentData.id }, { + where: { + id: order.id + }, include: [models.Task, models.User], returning: true, plain: true diff --git a/modules/tasks/taskUpdate.js b/modules/tasks/taskUpdate.js index 7747b51e8..6e1fb0ff3 100644 --- a/modules/tasks/taskUpdate.js +++ b/modules/tasks/taskUpdate.js @@ -24,7 +24,7 @@ const createSourceAndCharge = Promise.method((customer, orderParameters, order, return task } - await order.updateAttributes({ couponId: couponValidation.id }) + await order.update({ couponId: couponValidation.id }, { where: { id: order.id } }) // This means that the amount of discount provided by coupon is 100% if (couponValidation.orderPrice <= 0.5) {