From 408f26e9280fa347fa04d301a6cf28daa39a2dc6 Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 16 Feb 2024 18:30:22 +0100 Subject: [PATCH] fix notifications of payment disputes Stripe has sent us at least one callback erroneously containing `"status": "needs_response"` for an unchallengeable dispute. --- www/callbacks/stripe.spt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/www/callbacks/stripe.spt b/www/callbacks/stripe.spt index 976ebdaf2..54af17d2d 100644 --- a/www/callbacks/stripe.spt +++ b/www/callbacks/stripe.spt @@ -87,6 +87,10 @@ elif event_object_type == 'charge.dispute': # Notify the person who initiated the payment payer = Participant.from_id(payin.payer) if dispute.status in ('needs_response', 'lost'): + try: + due_by = dispute.evidence_details.due_by + except AttributeError: + due_by = 0 try: payer.notify( 'payin_disputed', @@ -97,7 +101,10 @@ elif event_object_type == 'charge.dispute': payin_amount=payin.amount, payin_ctime=payin.ctime, dispute_reason=dispute.reason, - dispute_can_be_withdrawn=dispute.status == 'needs_response', + dispute_can_be_withdrawn=( + dispute.status == 'needs_response' and + due_by > utcnow().timestamp() + ), mandate_url=route.get_mandate_url(), ) except DuplicateNotification: