File tree 4 files changed +28
-4
lines changed
webhooks/trolley/handlers
4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -348,9 +348,12 @@ export class AdminService {
348
348
currentVersion : number ,
349
349
) {
350
350
let setDatePaidNull = false ;
351
- if (
352
- ( oldPaymentStatus === PaymentStatus . PAID ||
353
- oldPaymentStatus === PaymentStatus . PROCESSING ) &&
351
+ if ( [
352
+ PaymentStatus . PAID ,
353
+ PaymentStatus . PROCESSING ,
354
+ PaymentStatus . RETURNED ,
355
+ PaymentStatus . FAILED ,
356
+ ] . includes ( oldPaymentStatus as PaymentStatus ) &&
354
357
newPaymentStatus === PaymentStatus . OWED
355
358
) {
356
359
setDatePaidNull = true ;
Original file line number Diff line number Diff line change @@ -34,7 +34,11 @@ export class PaymentHandler {
34
34
paymentId ,
35
35
payload . status . toUpperCase ( ) as payment_status ,
36
36
payload . status . toUpperCase ( ) ,
37
- { failureMessage : payload . failureMessage } ,
37
+ {
38
+ failureMessage : payload . failureMessage ,
39
+ returnedNote : payload . returnedNote ,
40
+ errors : payload . errors ?. join ( ', ' ) ,
41
+ } ,
38
42
) ;
39
43
40
44
return ;
@@ -56,6 +60,7 @@ export class PaymentHandler {
56
60
INNER JOIN public.payment_release_associations pra
57
61
ON pra.payment_id = p.payment_id
58
62
WHERE pra.payment_release_id::text = ${ paymentId }
63
+ FOR UPDATE
59
64
`
60
65
) . map ( ( w ) => w . id ) ;
61
66
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ export interface PaymentProcessedEventData {
23
23
fees : string ;
24
24
targetAmount : string ; // net amount
25
25
failureMessage : string | null ;
26
+ errors ?: string [ ] ;
27
+ returnedNote ?: string ;
26
28
memo : string | null ;
27
29
batch : {
28
30
id : string ;
Original file line number Diff line number Diff line change @@ -138,6 +138,20 @@ export class PaymentsService {
138
138
metadata ?: JsonObject ,
139
139
) {
140
140
const prismaClient = transaction || this . prisma ;
141
+
142
+ const failedOrReturnedRelease = await prismaClient . payment_releases . findFirst ( {
143
+ where : {
144
+ payment_release_id : paymentId ,
145
+ status : { in : [ payment_status . RETURNED , payment_status . FAILED ] } ,
146
+ }
147
+ } ) ;
148
+
149
+ if ( failedOrReturnedRelease ) {
150
+ throw new Error (
151
+ `Not processing payment release ${ paymentId } because it was already marked as '${ failedOrReturnedRelease . status } '.` ,
152
+ ) ;
153
+ }
154
+
141
155
try {
142
156
const r = await prismaClient . payment_releases . updateMany ( {
143
157
where : {
You can’t perform that action at this time.
0 commit comments