diff --git a/src/vendor/processors/stripe.py b/src/vendor/processors/stripe.py index e9a8a02c..654211fa 100644 --- a/src/vendor/processors/stripe.py +++ b/src/vendor/processors/stripe.py @@ -463,7 +463,7 @@ def stripe_get_object(self, stripe_object_class, object_id, expand=None): return stripe_object def stripe_update_object(self, stripe_object_class, object_id, object_data): - object_data['sid'] = object_id + object_data['id'] = object_id stripe_object = self.stripe_call(stripe_object_class.modify, object_data) if self.transaction_succeeded: @@ -668,10 +668,13 @@ def build_subscription(self, subscription, payment_method_id): } def build_invoice_line_item(self, order_item, invoice_id): + price = order_item.offer.get_current_price_instance() + line_item = { 'customer': self.invoice.profile.meta.get('stripe_id'), 'invoice': invoice_id, - 'price': order_item.offer.meta['stripe'].get('price_id'), + 'quantity': order_item.quantity, + 'price': order_item.offer.meta['stripe']['prices'].get(str(price.pk)), } if order_item.offer.has_trial() or order_item.offer.has_valid_billing_start_date() or order_item.offer.discount(): @@ -683,6 +686,7 @@ def build_invoice(self, currency=DEFAULT_CURRENCY): return { 'customer': self.invoice.profile.meta.get('stripe_id'), 'currency': currency, + 'on_behalf_of': self.get_stripe_connect_account() } ########## @@ -1758,15 +1762,29 @@ def process_payment(self): for order_item in self.invoice.get_one_time_transaction_order_items(): line_item_data = self.build_invoice_line_item(order_item, stripe_invoice.id) stripe_line_item = self.stripe_create_object(self.stripe.InvoiceItem, line_item_data) + + if not stripe_line_item: + return None + stripe_line_items.append(stripe_line_item) - + stripe_invoice.lines = stripe_line_items amount = self.invoice.get_one_time_transaction_total() - payment_intent_data = self.build_payment_intent(amount, stripe_payment_method.id) - stripe_payment_intent = self.stripe_create_object(self.stripe.PaymentIntent, payment_intent_data) - if not stripe_payment_intent: + stripe_base_fee = self.get_stripe_base_fee_amount(amount) + application_fee = self.get_application_fee_amount(amount) + fee_amount = self.convert_decimal_to_integer(stripe_base_fee + application_fee) + + invoice_update = { + 'application_fee_amount': fee_amount, + 'transfer_data': { + "destination": self.get_stripe_connect_account(), + }, + } + + stripe_invoice = self.stripe_update_object(stripe.Invoice, stripe_invoice.id, invoice_update) + if not stripe_invoice: return None self.stripe_call(stripe_invoice.pay, {"payment_method": stripe_payment_method.id})