Skip to content

Commit

Permalink
added check if there is a connected account for the site to calculate…
Browse files Browse the repository at this point in the history
… fee and set transfer to data
  • Loading branch information
rhimmelbauer committed Oct 9, 2024
1 parent b27d7a4 commit bc1409a
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/vendor/processors/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ def stripe_update_object_metadata(self, stripe_object_class, object_id, metadata
# Stripe Object Builders
##########
def build_transfer_data(self):
if not self.get_stripe_connect_account():
return None

return {
'destination': self.get_stripe_connect_account(),
# Not required if you are using the application_fee parameter
Expand Down Expand Up @@ -645,29 +648,32 @@ def build_subscription(self, subscription, payment_method_id):
price = subscription.offer.get_current_price_instance()
sub_discount = 0
promotion_code = None

# Stripe Fees are not adjusted by the discount until discount duration has been implemented
stripe_base_fee = self.get_stripe_base_fee_amount(price.cost)
stripe_recurring_fee = self.get_recurring_fee_amount(price.cost)
application_fee = self.get_application_fee_amount(price.cost)
total_fee_percentage = None
has_connected_account = self.get_stripe_connect_account()

if hasattr(self.invoice, 'coupon_code') and (coupon_code := self.invoice.coupon_code.first()):
promotion_code = coupon_code.meta['stripe_id']

if coupon_code.does_offer_apply(price.offer):
sub_discount = coupon_code.get_discounted_amount(price.offer)

if (price.cost - sub_discount) < (stripe_base_fee + stripe_recurring_fee + application_fee):
self.transaction_info["errors"] = {
"user_message": f"Invoice total: ${(price.cost - sub_discount):.2f} is less than the fee's ${(stripe_base_fee + stripe_recurring_fee + application_fee):.2f} needed to be collected"
}
self.transaction_succeeded = False
return None
# Stripe Fees are not adjusted by the discount until discount duration has been implemented
if has_connected_account:
stripe_base_fee = self.get_stripe_base_fee_amount(price.cost)
stripe_recurring_fee = self.get_recurring_fee_amount(price.cost)
application_fee = self.get_application_fee_amount(price.cost)

if (price.cost - sub_discount) < (stripe_base_fee + stripe_recurring_fee + application_fee):
self.transaction_info["errors"] = {
"user_message": f"Invoice total: ${(price.cost - sub_discount):.2f} is less than the fee's ${(stripe_base_fee + stripe_recurring_fee + application_fee):.2f} needed to be collected"
}
self.transaction_succeeded = False
return None

total_fee_percentage = self.calculate_fee_percentage(
price.cost - sub_discount,
stripe_base_fee + stripe_recurring_fee + application_fee
)
total_fee_percentage = self.calculate_fee_percentage(
price.cost - sub_discount,
stripe_base_fee + stripe_recurring_fee + application_fee
)

return {
'customer': self.invoice.profile.meta['stripe_id'],
Expand Down

0 comments on commit bc1409a

Please sign in to comment.