Skip to content

Commit

Permalink
fix: fixing Paypal payments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanmtz committed Sep 19, 2023
1 parent 17d7dfe commit 5c4f9c5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
18 changes: 14 additions & 4 deletions modules/orders/orderBuilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
Expand Down Expand Up @@ -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
})
Expand Down
12 changes: 10 additions & 2 deletions modules/orders/orderCancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion modules/orders/orderPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion modules/orders/orderRefund.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/tasks/taskUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5c4f9c5

Please sign in to comment.