Skip to content

Commit

Permalink
Merge pull request #455 from renderbox/develop
Browse files Browse the repository at this point in the history
Release v0.4.16
  • Loading branch information
rhimmelbauer authored Jul 12, 2024
2 parents 5d17e3f + d1bb51d commit 0dd6645
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ universal = true

[project]
name = "django-vendor"
version = "0.4.15"
version = "0.4.16"

authors = [
{ name="Grant Viklund", email="[email protected]" },
Expand Down
22 changes: 17 additions & 5 deletions src/vendor/processors/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,28 @@ def build_setup_intent(self, payment_method_id):

def build_subscription(self, subscription, payment_method_id):
price = subscription.offer.get_current_price_instance()
sub_discount = 0
promotion_code = None

stripe_base_fee = self.get_stripe_base_fee_amount(self.invoice.total)
stripe_recurring_fee = self.get_recurring_fee_amount(self.invoice.total)
application_fee = self.get_application_fee_amount(self.invoice.total)
# 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 = self.calculate_fee_percentage(self.invoice.total, stripe_base_fee + stripe_recurring_fee + application_fee)
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)

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'],
'promotion_code': self.invoice.coupon_code.first().meta['stripe_id'] if hasattr(self.invoice, 'coupon_code') and self.invoice.coupon_code.count() else None,
'promotion_code': promotion_code,
'items': [{'price': subscription.offer.meta['stripe']['prices'][str(price.pk)]}],
'default_payment_method': payment_method_id,
'metadata': {'site': self.invoice.site},
Expand Down

0 comments on commit 0dd6645

Please sign in to comment.