Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 0a2db2b

Browse files
committed
payPledge: rescue mutation if webhook was faster
1 parent 62cd054 commit 0a2db2b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

graphql/resolvers/RootMutations/payPledge.js

+26
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ module.exports = async (_, args, {pgdb, req, t}) => {
2727
throw new Error(t('api/unexpected'))
2828
}
2929
if (pledge.status === 'SUCCESSFUL') {
30+
// check if the pledge was paid with the same paypal transaction
31+
// happens if the webhook is faster than redirect
32+
const payment = (await transaction.query(`
33+
SELECT
34+
pay.*
35+
FROM
36+
"pledgePayments" pp
37+
JOIN
38+
payments pay
39+
ON pp."paymentId" = pay.id
40+
WHERE
41+
pp."pledgeId" = :pledgeId
42+
`, {
43+
pledgeId: pledge.id
44+
}))[0]
45+
let pspPayload
46+
try {
47+
pspPayload = JSON.parse(pledgePayment.pspPayload)
48+
} catch (e) { }
49+
if (
50+
payment && payment.pspPayload && pspPayload &&
51+
payment.pspPayload.TRANSACTIONID === pspPayload.tx) {
52+
return {
53+
pledgeId: pledge.id
54+
}
55+
}
3056
logger.error('pledge is already paid', { req: req._log(), args, pledge, pledgePayment })
3157
throw new Error(t('api/pledge/alreadyPaid'))
3258
}

0 commit comments

Comments
 (0)