File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -211,7 +211,22 @@ def process_webhook_payload(webhook):
211211 id = webhook .id ,
212212 )
213213 webhook .status = ProcessingStatus .UNPARSABLE
214- webhook .internal_notes = "webhooks.paypal.jsondecodeerror"
214+ webhook .internal_notes = (
215+ "webhooks.paypal.services.process_webhook_payload.unparsable_event"
216+ )
217+ webhook .save ()
218+ return
219+
220+ reference = jmespath .search ("resource.id" , payload )
221+ if Transaction .objects .filter (reference = reference ).exists ():
222+ logger .info (
223+ "webhooks.paypal.services.process_webhook_payload.duplicated_transaction" ,
224+ id = webhook .id ,
225+ )
226+ webhook .status = ProcessingStatus .DUPLICATED
227+ webhook .internal_notes = (
228+ "webhooks.paypal.services.process_webhook_payload.duplicated_transaction" ,
229+ )
215230 webhook .save ()
216231 return
217232
@@ -278,8 +293,6 @@ def process_webhook_payload(webhook):
278293
279294 description = " - " .join ([part for part in description_parts if part ])
280295
281- reference = jmespath .search ("resource.id" , payload )
282-
283296 with transaction .atomic ():
284297 bank_fee_category , _ = Category .objects .get_or_create (name = "Tarifas Bancárias" )
285298
Original file line number Diff line number Diff line change @@ -152,3 +152,20 @@ def test_do_not_process_duplicated_webhook_twice(
152152 duplicated_webhook .refresh_from_db ()
153153
154154 assert duplicated_webhook .status == ProcessingStatus .DUPLICATED
155+
156+
157+ @responses .activate
158+ def test_do_not_reprocess_existing_transaction (db , webhook__brl_payload ):
159+ transaction = baker .make (
160+ Transaction ,
161+ reference = "35R35201NA4015510" ,
162+ )
163+
164+ webhook_with_duplicated_transaction = baker .make (
165+ PaypalWebhookPayload ,
166+ payload = webhook__brl_payload ,
167+ )
168+ webhook_with_duplicated_transaction .process ()
169+ webhook_with_duplicated_transaction .refresh_from_db ()
170+
171+ assert webhook_with_duplicated_transaction .status == ProcessingStatus .DUPLICATED
You can’t perform that action at this time.
0 commit comments