def _pay_using_profile(self, payment_profile, amount): ''' Complete the Checkout using a payment_profile. Only available to the registered users of the website. :param payment_profile: Active record of payment profile :param amount: Decimal amount to charge the card for ''' PaymentTransaction = Pool().get('payment_gateway.transaction') if payment_profile.party != self.party: self.raise_user_error( "Payment profile'd owner is %s, but the customer is %s" % ( payment_profile.party.name, self.party.name, ) ) payment_transaction = PaymentTransaction( party=self.party, address=self.invoice_address, payment_profile=payment_profile, amount=amount, currency=self.currency, gateway=payment_profile.gateway, sale=self, ) payment_transaction.save() PaymentTransaction.capture([payment_transaction])
def process_pending_payments(self): """Process waiting payments for corresponding sale. """ PaymentTransaction = Pool().get('payment_gateway.transaction') if self.payment_processing_state == "waiting_for_auth": for payment in self.sorted_payments: payment.authorize() self.payment_processing_state = None elif self.payment_processing_state == "waiting_for_capture": # Transactions waiting for capture. txns = PaymentTransaction.search([ ('sale_payment.sale', '=', self.id), ]) # Settle authorized transactions PaymentTransaction.settle(filter( lambda txn: txn.state == 'authorized', txns )) # Capture other transactions PaymentTransaction.capture(filter( lambda txn: txn.state == "draft", txns )) self.payment_processing_state = None else: # Weird! Why was I called if there is nothing to do return self.save()
def process_pending_payments(self): """Process waiting payments for corresponding sale. """ PaymentTransaction = Pool().get('payment_gateway.transaction') if self.payment_processing_state == "waiting_for_auth": for payment in self.sorted_payments: payment.authorize() else: # Transactions waiting for capture. txns = PaymentTransaction.search([ ('sale_payment.sale', '=', self.id), ]) # Settle authorized transactions PaymentTransaction.settle( filter(lambda txn: txn.state == 'authorized', txns)) # Capture other transactions PaymentTransaction.capture( filter(lambda txn: txn.state == "draft", txns)) self.payment_processing_state = None self.save()
def capture(self): """ Captures the given amount from this transaction """ PaymentTransaction = Pool().get('payment_gateway.transaction') PaymentTransaction.capture(self.payment_transactions)
def _pay_using_profile(self, payment_profile, amount): ''' Complete the Checkout using a payment_profile. Only available to the registered users of the website. :param payment_profile: Active record of payment profile :param amount: Decimal amount to charge the card for ''' PaymentTransaction = Pool().get('payment_gateway.transaction') if payment_profile.party != self.party: self.raise_user_error( "Payment profile'd owner is %s, but the customer is %s" % ( payment_profile.party.name, self.party.name, )) payment_transaction = PaymentTransaction( party=self.party, address=self.invoice_address, payment_profile=payment_profile, amount=amount, currency=self.currency, gateway=payment_profile.gateway, sale=self, ) payment_transaction.save() PaymentTransaction.capture([payment_transaction])
def capture_and_pay_using_transaction(self, profile_id, gateway_id, amount): """ Create a payment transaction, capture paymnet and then pay using the transaction :param profile_id: Payment profile id :param gateway_id: Payment gateway id :param amount: Amount to be deducted """ PaymentTransaction = Pool().get('payment_gateway.transaction') Date = Pool().get('ir.date') transaction = PaymentTransaction( party=self.party, credit_account=self.party.account_receivable, address=self.invoice_address, gateway=gateway_id, payment_profile=profile_id, amount=amount, currency=self.currency, description=self.description, date=Date.today(), ) transaction.save() PaymentTransaction.capture([transaction]) if transaction.state in ('completed', 'posted'): self.pay_using_transaction(transaction) else: self.raise_user_error('Payment capture failed')
def transition_redeem(self): """ Transition where PaymentTransaction is created and associated with current gift card. """ PaymentTransaction = Pool().get('payment_gateway.transaction') Date = Pool().get('ir.date') transaction, = PaymentTransaction.create([{ 'description': self.start.description, 'date': Date.today(), 'party': self.start.party.id, 'address': self.start.address, 'amount': self.start.amount, 'currency': self.start.currency.id, 'gateway': self.start.gateway.id, 'gift_card': self.start.gift_card.id, }]) PaymentTransaction.capture([transaction]) return 'done'
def capture(self): """ Captures the given amount from this transaction """ PaymentTransaction = Pool().get('payment_gateway.transaction') PaymentTransaction.capture( filter( lambda txn: txn.state in ('draft', 'authorized', 'in-progress'), self.payment_transactions))
def capture(self): """ Captures the given amount from this transaction """ PaymentTransaction = Pool().get('payment_gateway.transaction') PaymentTransaction.capture( filter( lambda txn: txn.state in ('draft', 'authorized', 'in-progress'), self.payment_transactions ) )
def process(cls, sale, payment_method_id): """Begins the payment processing. Returns a response object if a redirect to third party website is required, else processes the payment. :param sale: Browse Record of the Sale :param payment_method_id: ID of payment method """ Sale = Pool().get('sale.sale') try_to_authorize = ( request.nereid_website.payment_mode == 'auth_if_available' ) payment_method = cls(payment_method_id) allowed_gateways = cls._get_available_gateways( sale.invoice_address.country ) if payment_method not in allowed_gateways: current_app.logger.error("Payment method %s is not valid" % payment_method.name) abort(403) payment_method_obj = Pool().get(payment_method.model.model) Sale.write([sale], {'payment_method': payment_method.id}) if try_to_authorize and hasattr(payment_method_obj, 'authorize'): return payment_method_obj.authorize(sale) else: return payment_method_obj.capture(sale)
def process(cls, sale, payment_method_id): """Begins the payment processing. Returns a response object if a redirect to third party website is required, else processes the payment. :param sale: Browse Record of the Sale :param payment_method_id: ID of payment method """ Sale = Pool().get('sale.sale') try_to_authorize = ( request.nereid_website.payment_mode == 'auth_if_available') payment_method = cls(payment_method_id) allowed_gateways = cls._get_available_gateways( sale.invoice_address.country) if payment_method not in allowed_gateways: current_app.logger.error("Payment method %s is not valid" % payment_method.name) abort(403) payment_method_obj = Pool().get(payment_method.model.model) Sale.write([sale], {'payment_method': payment_method.id}) if try_to_authorize and hasattr(payment_method_obj, 'authorize'): return payment_method_obj.authorize(sale) else: return payment_method_obj.capture(sale)
def transition_pay(self): """ Creates a new payment transaction and pay invoice with it """ PaymentTransaction = Pool().get('payment_gateway.transaction') profile = self.start.payment_profile if self.start.method == 'credit_card' and ( not self.start.use_existing_card ): profile = self.create_payment_profile() transaction = self.create_payment_transaction(profile=profile) transaction.save() # Capture Transaction PaymentTransaction.capture([transaction]) # Pay invoice using above captured transaction self.start.invoice.pay_using_transaction(transaction) return 'end'
def transition_pay(self): """ Creates a new payment transaction and pay invoice with it """ PaymentTransaction = Pool().get('payment_gateway.transaction') if self.start.transaction_type == 'charge': profile = self.start.payment_profile if self.start.method == 'credit_card' and ( not self.start.use_existing_card ): profile = self.create_payment_profile() transaction = self.create_payment_transaction(profile=profile) transaction.save() # Capture Transaction PaymentTransaction.capture([transaction]) if transaction.state in ('completed', 'posted'): # Pay invoice using above captured transaction self.start.invoice.pay_using_transaction(transaction) else: self.failed.message = \ "Payment capture failed, refer transaction logs" return 'failed' elif self.start.transaction_type == 'refund': refund_transaction = self.start.transaction.create_refund( self.start.amount ) PaymentTransaction.refund([refund_transaction]) if refund_transaction.state in ('completed', 'posted'): self.start.invoice.pay_using_transaction(refund_transaction) else: self.failed.message = \ "Payment refund failed, refer transaction logs" return 'failed' return 'end'