Skip to content

Commit

Permalink
Merge pull request pinax#302 from xfxf/master
Browse files Browse the repository at this point in the history
Adds tax_percent parameter to actions.subscribe()
  • Loading branch information
paltman authored Dec 21, 2016
2 parents acc400e + 66c9e3a commit 6615388
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/reference/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ Args:
source for the customer, otherwise the current default source
will be used
- coupon: if provided, a coupon to apply towards the subscription
- tax_percent: if provided, add percentage as tax

Returns: the `pinax.stripe.models.Subscription` object that was created

Expand Down Expand Up @@ -462,4 +463,4 @@ Updates the status of a `pinax.stripe.models.Transfer` object from Stripe API

Args:

- transfer: a `pinax.stripe.models.Transfer` object to update
- transfer: a `pinax.stripe.models.Transfer` object to update
9 changes: 9 additions & 0 deletions docs/user-guide/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ active subscription if the `pinax.stripe.middleware.ActiveSubscriptionMiddleware
is installed.


### PINAX_STRIPE_SUBSCRIPTION_TAX_PERCENT

Defaults to `None`

If you wish to charge tax on a subscription, set this value to an integer
specifying the percentage of tax required (i.e. 10% would be '10'). This is
used by `pinax.stripe.views.SubscriptionCreateView`


## Stripe Account Settings Panel

![](images/stripe-account-panel.png)
Expand Down
4 changes: 3 additions & 1 deletion pinax/stripe/actions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def cancel(subscription, at_period_end=True):
sync_subscription_from_stripe_data(subscription.customer, sub)


def create(customer, plan, quantity=None, trial_days=None, token=None, coupon=None):
def create(customer, plan, quantity=None, trial_days=None, token=None, coupon=None, tax_percent=None):
"""
Creates a subscription for the given customer
Expand All @@ -37,6 +37,7 @@ def create(customer, plan, quantity=None, trial_days=None, token=None, coupon=No
source for the customer, otherwise the current default source
will be used
coupon: if provided, a coupon to apply towards the subscription
tax_percent: if provided, add percentage as tax
Returns:
the data representing the subscription object that was created
Expand All @@ -53,6 +54,7 @@ def create(customer, plan, quantity=None, trial_days=None, token=None, coupon=No
subscription_params["plan"] = plan
subscription_params["quantity"] = quantity
subscription_params["coupon"] = coupon
subscription_params["tax_percent"] = tax_percent
resp = cu.subscriptions.create(**subscription_params)

return sync_subscription_from_stripe_data(customer, resp)
Expand Down
1 change: 1 addition & 0 deletions pinax/stripe/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PinaxStripeAppConf(AppConf):
SEND_EMAIL_RECEIPTS = True
SUBSCRIPTION_REQUIRED_EXCEPTION_URLS = []
SUBSCRIPTION_REQUIRED_REDIRECT = None
SUBSCRIPTION_TAX_PERCENT = None

class Meta:
prefix = "pinax_stripe"
Expand Down
7 changes: 6 additions & 1 deletion pinax/stripe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import stripe

from .actions import events, exceptions, customers, subscriptions, sources
from .conf import settings
from .forms import PlanForm, PaymentMethodForm
from .mixins import LoginRequiredMixin, CustomerMixin, PaymentsContextMixin
from .models import Invoice, Card, Subscription
Expand Down Expand Up @@ -102,12 +103,16 @@ class SubscriptionCreateView(LoginRequiredMixin, PaymentsContextMixin, CustomerM
template_name = "pinax/stripe/subscription_create.html"
form_class = PlanForm

@property
def tax_percent(self):
return settings.PINAX_STRIPE_SUBSCRIPTION_TAX_PERCENT

def set_customer(self):
if self.customer is None:
self._customer = customers.create(self.request.user)

def subscribe(self, customer, plan, token):
subscriptions.create(customer, plan, token=token)
subscriptions.create(customer, plan, token=token, tax_percent=self.tax_percent)

def form_valid(self, form):
self.set_customer()
Expand Down

0 comments on commit 6615388

Please sign in to comment.