Skip to content

Commit

Permalink
fix(webhooks): fix signature errors when editing and/or deleting prod…
Browse files Browse the repository at this point in the history
…ucts
  • Loading branch information
wisley7l committed Nov 14, 2023
1 parent 8b21ecb commit fb87d1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 1 addition & 3 deletions functions/routes/ecom/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ exports.post = async ({ appSdk, admin }, req, res) => {
throw err
}
//
// subscription.galaxPayId
// console.log('>Sub: ', JSON.stringify(subscription))
let queryString = `subscriptionGalaxPayIds=${subscription.galaxPayId}`
queryString += '&status=notSend,pendingBoleto,pendingPix&order=payday.desc'

Expand All @@ -356,7 +354,7 @@ exports.post = async ({ appSdk, admin }, req, res) => {
let i = 0
while (i < Transactions?.length) {
const transaction = Transactions[i]
if (transaction.value !== newSubscriptionValue) {
if (transaction.value !== newSubscriptionValue && transaction.galaxPayId !== docSubscription.transactionId) {
await updateTransactionGalaxpay(galaxpayAxios, transaction.galaxPayId, newSubscriptionValue)
.catch(console.error)
}
Expand Down
12 changes: 8 additions & 4 deletions functions/routes/galaxpay/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,23 +548,24 @@ exports.post = async ({ appSdk, admin }, req, res) => {
if (transactionId !== GalaxPayTransaction.galaxPayId) {
const auth = await appSdk.getAuth(storeId)
const order = (await findOrderById(appSdk, storeId, auth, subscriptionId))?.response?.data
let items = order.items

let { itemsAndAmount } = subscriptionDoc
if (itemsAndAmount && itemsAndAmount.items?.length) {
compareDocItemsWithOrder(itemsAndAmount, order.items, order.amount, GalaxPayTransactionValue)
items = itemsAndAmount.items
}

await checkItemsAndRecalculeteOrder(
order.amount,
order.items,
items,
plan,
null,
order.shipping_lines[0],
storeId,
appSdk,
auth
)
itemsAndAmount = createItemsAndAmount(order.amount, order.items)
itemsAndAmount = createItemsAndAmount(order.amount, items)

await collectionTransactions.doc(`${storeId}-${GalaxPayTransaction.galaxPayId}`)
.set(
Expand Down Expand Up @@ -598,7 +599,10 @@ exports.post = async ({ appSdk, admin }, req, res) => {
await updateDocSubscription(collectionSubscription, body, subscriptionId)
}
// Update transaction
await updateTransactionGalaxpay(galaxpayAxios, GalaxPayTransaction.galaxPayId, total)
const { status } = data?.Transactions[0]
if (!status || status === 'notSend' || status === 'pendingBoleto' || status === 'pendingPix') {
await updateTransactionGalaxpay(galaxpayAxios, GalaxPayTransaction.galaxPayId, total)
}
}
} catch (error) {
console.error(error)
Expand Down

0 comments on commit fb87d1c

Please sign in to comment.