def check(self): response = document2dict(api.check_notification(self.code)) try: transaction = Transaction(response=response['transaction']) transaction.save() payment = Payment.objects.get(reference=transaction.reference) payment.method_type = int( response['transaction']['paymentMethod']['type']) payment.method_code = int( response['transaction']['paymentMethod']['code']) payment.save() self.checked = choices.CHECKED_YES_SUCCESS[0] self.save() except: error_str = "" if type(response["errors"]["error"]) != list: response["errors"]["error"] = [response["errors"]["error"]] for error in response["errors"]["error"]: error_payment = ErrorNotification() error_payment.code = int(error['code']) error_payment.notification = self error_payment.save() error_str += "[%s: %s]" % (error_payment.code, error_payment.get_code_display()) self.checked = choices.CHECKED_YES_FAILURE[0] self.save() raise Exception(error_str)
def submit(self, redirect_url): ''' Sends self as a Payment through PagSeguro API. Payment instance MUST BE SAVED before calling this method. ''' if not self.id: #Temporary to identify which problem caused the crash. raise ValidationError #creating a reference if its None if self.reference is None: self.reference = configs.PAGSEGURO_REFERENCE_PREFIX + str(self.id) document = Document() document.appendChild(self.to_element(document, redirect_url)) response = document2dict(api.submit_payment(document)) try: self.code = response['checkout']['code'] self.answered_on = datetime.datetime.now() self.save() except: error_str = "" if type(response["errors"]["error"]) != list: response["errors"]["error"] = [response["errors"]["error"]] for error in response["errors"]["error"]: error_payment = ErrorPayment() error_payment.code = int(error['code']) error_payment.payment = self error_payment.save() error_str += "[%s: %s]" % (error_payment.code, error_payment.get_code_display()) raise Exception(error_str)
def check(self): response = document2dict(api.check_notification(self.code)) try: transaction = Transaction(response=response['transaction']) transaction.save() payment = Payment.objects.get(reference=transaction.reference) payment.method_type = int(response['transaction']['paymentMethod']['type']) payment.method_code = int(response['transaction']['paymentMethod']['code']) payment.save() self.checked = choices.CHECKED_YES_SUCCESS[0] self.save() except: error_str = "" if type(response["errors"]["error"]) != list: response["errors"]["error"] = [response["errors"]["error"]] for error in response["errors"]["error"]: error_payment = ErrorNotification() error_payment.code = int(error['code']) error_payment.notification = self error_payment.save() error_str += "[%s: %s]" % (error_payment.code, error_payment.get_code_display()) self.checked = choices.CHECKED_YES_FAILURE[0] self.save() raise Exception(error_str)
def query(cls, initial_date, final_date, page=None, max_page_results=None): ''' A wrapper to api.query_transactions that converst the result into dict using xmlreader.document2dict ''' return document2dict( api.query_transactions(initial_date, final_date, page, max_page_results))
def check(self): response = document2dict(api.check_transaction(self.code)) self.parse(response['transaction']) # override to get the last event of the transaction on pagseguro self.date = datetime.datetime.strptime( response['transaction']['lastEventDate'].split('.')[0], PAGSEGURO_DATETIME_FORMAT) self.save()
def query(cls, initial_date, final_date, page=None, max_page_results=None): ''' A wrapper to api.query_transactions that converst the result into dict using xmlreader.document2dict ''' return document2dict(api.query_transactions(initial_date, final_date, page, max_page_results))
def check(self): response = document2dict(api.check_transaction(self.code)) self.parse(response['transaction']) # override to get the last event of the transaction on pagseguro self.date = datetime.datetime.strptime(response['transaction']['lastEventDate'].split('.')[0], PAGSEGURO_DATETIME_FORMAT) self.save()