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
@@ -226,7 +227,7 @@ def poll_status(self):
226227 response = response .json ()
227228
228229 if response ['results' ]:
229- logger .info ('Polled for %s. Creating Payment' , self .pk )
230+ logger .info ('Polled for %s. Found a Payment. ' , self .pk )
230231 return Payment .objects .create_or_update_from_raw_data (
231232 response ['results' ][- 1 ]
232233 )
@@ -323,6 +324,10 @@ def create_or_update_from_raw_data(self, raw_data):
323324 mp_id = raw_data ['id' ],
324325 defaults = payment_data ,
325326 )
327+ if created :
328+ logger .info ('New payment created.' )
329+ else :
330+ logger .info ('Payment already registered locally, nothing created.' )
326331
327332 if payment .status == 'approved' and \
328333 payment .status_detail == 'accredited' :
@@ -473,7 +478,14 @@ def process(self):
473478 return
474479
475480 mercadopago_service = self .owner .service
476- raw_data = mercadopago_service .get_payment_info (self .resource_id )
481+ try :
482+ raw_data = mercadopago_service .get_payment_info (self .resource_id )
483+ except json .JSONDecodeError :
484+ # XXX: Actually, we need to write our own client that returns the
485+ # real error (at least status code).
486+ self .status = Notification .STATUS_ERROR
487+ self .save ()
488+ return
477489
478490 if raw_data ['status' ] != 200 :
479491 logger .warning (
You can’t perform that action at this time.
0 commit comments