def attempt(self): """ Try to perform this payment. """ self.last_attempted_at = datetime.now() # Write attempted date now so if something happens we can see this # payment was interrupted. self.save() try: flow_graph = FlowGraph(self.payer, self.recipient) flow_links = flow_graph.min_cost_flow(self.amount) with transaction.commit_on_success(using='ripple'): for creditline, amount in flow_links: Entry.objects.create_entry( self, creditline.account, -amount * creditline.bal_mult, creditline.limit) self.status = 'completed' self.save() except BaseException as exc: # TODO: Handle collisions better here so we can retry or give the # user an informative error message, rather than the server error page. self.status = 'failed' self.save() if not isinstance(exc, PaymentError): raise
def attempt(self): """ Try to perform this payment. """ self.last_attempted_at = datetime.now() # Write attempted date now so if something happens we can see this # payment was interrupted. self.save() changed_accounts = [] try: flow_graph = FlowGraph(self.payer, self.recipient) flow_links = flow_graph.min_cost_flow(self.amount) with transaction.atomic(using='ripple'): for creditline_id, amount in flow_links: creditline = CreditLine.objects.get(pk=creditline_id) Entry.objects.create_entry(self, creditline.account, -amount * creditline.bal_mult, creditline.limit) changed_accounts.append(creditline.account) self.status = 'completed' self.save() except BaseException as exc: # TODO: Handle collisions better here so we can retry or give the # user an informative error message, rather than the server error page. self.status = 'failed' self.save() if not isinstance(exc, PaymentError): raise # Update cached graphs. for account in changed_accounts: for creditline in (account.pos_creditline, account.neg_creditline): update_creditline_in_cached_graphs(creditline)
def attempt(self): """ Try to perform this payment. """ self.last_attempted_at = datetime.now() # Write attempted date now so if something happens we can see this # payment was interrupted. self.save() changed_accounts = [] try: flow_graph = FlowGraph(self.payer, self.recipient) flow_links = flow_graph.min_cost_flow(self.amount) with transaction.commit_on_success(using="ripple"): for creditline_id, amount in flow_links: creditline = CreditLine.objects.get(pk=creditline_id) Entry.objects.create_entry( self, creditline.account, -amount * creditline.bal_mult, creditline.limit ) changed_accounts.append(creditline.account) self.status = "completed" self.save() except BaseException as exc: # TODO: Handle collisions better here so we can retry or give the # user an informative error message, rather than the server error page. self.status = "failed" self.save() if not isinstance(exc, PaymentError): raise # Update cached graphs. for account in changed_accounts: for creditline in (account.pos_creditline, account.neg_creditline): update_creditline_in_cached_graphs(creditline)