This repository was archived by the owner on Nov 6, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 1+ import json
12import logging
23
34import requests
@@ -273,7 +274,7 @@ def poll_status(self):
273274 response = response .json ()
274275
275276 if response ['results' ]:
276- logger .info ('Polled for %s. Creating Payment' , self .pk )
277+ logger .info ('Polled for %s. Found a Payment. ' , self .pk )
277278 return Payment .objects .create_or_update_from_raw_data (
278279 response ['results' ][- 1 ]
279280 )
@@ -327,6 +328,10 @@ def create_or_update_from_raw_data(self, raw_data):
327328 mp_id = raw_data ['id' ],
328329 defaults = payment_data ,
329330 )
331+ if created :
332+ logger .info ('New payment created.' )
333+ else :
334+ logger .info ('Payment already registered locally, nothing created.' )
330335
331336 if payment .status == 'approved' and \
332337 payment .status_detail == 'accredited' :
@@ -477,7 +482,14 @@ def process(self):
477482 return
478483
479484 mercadopago_service = self .owner .service
480- raw_data = mercadopago_service .get_payment_info (self .resource_id )
485+ try :
486+ raw_data = mercadopago_service .get_payment_info (self .resource_id )
487+ except json .JSONDecodeError :
488+ # XXX: Actually, we need to write our own client that returns the
489+ # real error (at least status code).
490+ self .status = Notification .STATUS_ERROR
491+ self .save ()
492+ return
481493
482494 if raw_data ['status' ] != 200 :
483495 logger .warning (
You can’t perform that action at this time.
0 commit comments