Example #1
0
 def handle_payment(self, order_number, total, **kwargs):
     """
     Make submission
     """
     # Using preauth here (two-stage model). You could use payment to
     # perform the preauth and capture in one step.
     method = self.checkout_session.payment_method()
     if self.checkout_session.free_basket():
         self.doInvoice(order_number, total)
     else:
         if method == 'card':
             try:
                 #Generate Invoice
                 invoice = self.doInvoice(order_number, total)
                 # Swap user if in session
                 if self.checkout_session.basket_owner():
                     user = EmailUser.objects.get(
                         id=int(self.checkout_session.basket_owner()))
                 else:
                     user = self.request.user
                 # Check if the system only uses checkout with token for cards
                 if self.checkout_session.checkoutWithToken():
                     resp = bpoint_facade.checkout_with_token(
                         user, invoice.reference, kwargs['bankcard'])
                     if self.checkout_session.invoice_association():
                         invoice.token = resp
                         invoice.save()
                 else:
                     # Store card if user wants to store card
                     if self.checkout_session.store_card():
                         resp = bpoint_facade.checkout_with_token(
                             user, invoice.reference, kwargs['bankcard'],
                             True)
                         if self.checkout_session.invoice_association():
                             invoice.token = resp.token
                             invoice.save()
                     # Get the payment action for bpoint
                     card_method = self.checkout_session.card_method()
                     resp = bpoint_facade.post_transaction(
                         card_method, 'internet', 'single', order_number,
                         invoice.reference, total.incl_tax,
                         kwargs['bankcard'])
                     # Record payment source and event
                     source_type, is_created = models.SourceType.objects.get_or_create(
                         name='Bpoint')
                     # amount_allocated if action is preauth and amount_debited if action is payment
                     source = source_type.sources.model(
                         source_type=source_type,
                         amount_debited=total.incl_tax,
                         currency=total.currency)
                     self.add_payment_source(source)
                     self.add_payment_event('Paid', total.incl_tax)
             except Exception as e:
                 raise
         else:
             #Generate Invoice
             self.doInvoice(order_number, total)
Example #2
0
 def handle_payment(self, order_number, total, **kwargs):
     """
     Make submission
     """
     # Using preauth here (two-stage model). You could use payment to
     # perform the preauth and capture in one step.  
     method = self.checkout_session.payment_method()
     if self.checkout_session.free_basket():
         self.doInvoice(order_number,total)
     else:
         if method == 'card':
             try:
                 #Generate Invoice
                 invoice = self.doInvoice(order_number,total)
                 # Swap user if in session
                 if self.checkout_session.basket_owner():
                     user = EmailUser.objects.get(id=int(self.checkout_session.basket_owner()))
                 else:
                     user = self.request.user
                 # Check if the system only uses checkout with token for cards
                 if self.checkout_session.checkoutWithToken():
                     resp = bpoint_facade.checkout_with_token(user,invoice.reference,kwargs['bankcard'])
                     if self.checkout_session.invoice_association():
                         invoice.token = resp
                         invoice.save()
                 else:
                     # Store card if user wants to store card
                     if self.checkout_session.store_card():
                         resp = bpoint_facade.checkout_with_token(user,invoice.reference,kwargs['bankcard'],True)
                         if self.checkout_session.invoice_association():
                             invoice.token = resp.token
                             invoice.save()
                     # Get the payment action for bpoint
                     card_method = self.checkout_session.card_method()
                     resp = bpoint_facade.post_transaction(card_method,'internet','single',order_number,invoice.reference, total.incl_tax,kwargs['bankcard'])
                     # Record payment source and event
                     source_type, is_created = models.SourceType.objects.get_or_create(
                         name='Bpoint')
                     # amount_allocated if action is preauth and amount_debited if action is payment
                     source = source_type.sources.model(
                         source_type=source_type,
                         amount_debited=total.incl_tax, currency=total.currency)
                     self.add_payment_source(source)
                     self.add_payment_event('Paid', total.incl_tax)
             except Exception as e:
                 raise
         else:
             #Generate Invoice
             self.doInvoice(order_number,total)
Example #3
0
 def handle_payment(self, order_number, total, **kwargs):
     """
     Make submission
     """
     logger.info('Order #%s: handling payment', order_number)
     # Using preauth here (two-stage model). You could use payment to
     # perform the preauth and capture in one step.
     with transaction.atomic():
         method = self.checkout_session.payment_method()
         # Last point to use the check url to see if the payment should be permitted
         if self.checkout_session.get_last_check():
             self.handle_last_check(self.checkout_session.get_last_check())
         if self.checkout_session.free_basket():
             self.doInvoice(order_number, total)
         else:
             if method == 'card':
                 try:
                     #Generate Invoice
                     invoice = self.doInvoice(order_number, total)
                     # Swap user if in session
                     if self.checkout_session.basket_owner():
                         user = EmailUser.objects.get(
                             id=int(self.checkout_session.basket_owner()))
                     else:
                         user = self.request.user
                     # Get the payment action for bpoint
                     card_method = self.checkout_session.card_method()
                     # Check if the user is paying using a stored card
                     if self.checkout_session.checkoutWithToken():
                         try:
                             token = BpointToken.objects.get(
                                 id=self.checkout_session.checkoutWithToken(
                                 ))
                         except BpointToken.DoesNotExist:
                             raise ValueError(
                                 'This stored card does not exist.')
                         if self.checkout_session.invoice_association():
                             invoice.token = '{}|{}|{}'.format(
                                 token.DVToken,
                                 token.expiry_date.strftime("%m%y"),
                                 token.last_digits)
                             invoice.save()
                         else:
                             bpoint_facade.pay_with_storedtoken(
                                 card_method, 'internet', 'single',
                                 token.id, order_number, invoice.reference,
                                 total.incl_tax)
                     else:
                         # Store card if user wants to store card
                         if self.checkout_session.store_card():
                             resp = bpoint_facade.create_token(
                                 user, invoice.reference,
                                 kwargs['bankcard'], True)
                             if self.checkout_session.invoice_association():
                                 invoice.token = resp
                                 invoice.save()
                             else:
                                 bankcard = kwargs['bankcard']
                                 bankcard.last_digits = bankcard.number[-4:]
                                 resp = bpoint_facade.post_transaction(
                                     card_method, 'internet', 'single',
                                     order_number, invoice.reference,
                                     total.incl_tax, bankcard)
                         else:
                             if self.checkout_session.invoice_association():
                                 resp = bpoint_facade.create_token(
                                     user, invoice.reference,
                                     kwargs['bankcard'])
                                 invoice.token = resp
                                 invoice.save()
                             else:
                                 bankcard = kwargs['bankcard']
                                 bankcard.last_digits = bankcard.number[-4:]
                                 resp = bpoint_facade.post_transaction(
                                     card_method, 'internet', 'single',
                                     order_number, invoice.reference,
                                     total.incl_tax, bankcard)
                     if not self.checkout_session.invoice_association():
                         # Record payment source and event
                         source_type, is_created = models.SourceType.objects.get_or_create(
                             name='Bpoint')
                         # amount_allocated if action is preauth and amount_debited if action is payment
                         if card_method == 'payment':
                             source = source_type.sources.model(
                                 source_type=source_type,
                                 amount_debited=total.incl_tax,
                                 currency=total.currency)
                         elif card_method == 'preauth':
                             source = source_type.sources.model(
                                 source_type=source_type,
                                 amount_allocated=total.incl_tax,
                                 currency=total.currency)
                         self.add_payment_source(source)
                         self.add_payment_event('Paid', total.incl_tax)
                 except Exception as e:
                     traceback.print_exc()
                     raise
             else:
                 #Generate Invoice
                 self.doInvoice(order_number, total)