diff --git a/docs/reference/actions.md b/docs/reference/actions.md index ad1dd8139..9daf4fd79 100644 --- a/docs/reference/actions.md +++ b/docs/reference/actions.md @@ -78,6 +78,7 @@ Args: `settings.PINAX_STRIPE_DEFAULT_PLAN`. - charge_immediately: whether or not the user should be immediately charged for the subscription. Defaults to `True`. +- quantity: the quantity of the subscription. Defaults to `1`. Returns: `pinax.stripe.models.Customer` object that was created diff --git a/pinax/stripe/actions/customers.py b/pinax/stripe/actions/customers.py index 5899a2d78..4d4cf5459 100644 --- a/pinax/stripe/actions/customers.py +++ b/pinax/stripe/actions/customers.py @@ -27,7 +27,7 @@ def can_charge(customer): return False -def create(user, card=None, plan=settings.PINAX_STRIPE_DEFAULT_PLAN, charge_immediately=True): +def create(user, card=None, plan=settings.PINAX_STRIPE_DEFAULT_PLAN, charge_immediately=True, quantity=1): """ Creates a Stripe customer. @@ -39,6 +39,7 @@ def create(user, card=None, plan=settings.PINAX_STRIPE_DEFAULT_PLAN, charge_imme plan: a plan to subscribe the user to charge_immediately: whether or not the user should be immediately charged for the subscription + quantity: the quantity (multiplier) of the subscription Returns: the pinax.stripe.models.Customer object that was created @@ -49,6 +50,7 @@ def create(user, card=None, plan=settings.PINAX_STRIPE_DEFAULT_PLAN, charge_imme email=user.email, source=card, plan=plan, + quantity=quantity, trial_end=trial_end ) try: diff --git a/pinax/stripe/tests/test_actions.py b/pinax/stripe/tests/test_actions.py index c5109cfd6..4d12f2ae0 100644 --- a/pinax/stripe/tests/test_actions.py +++ b/pinax/stripe/tests/test_actions.py @@ -193,6 +193,31 @@ def test_customer_create_user_with_plan(self, CreateMock, SyncMock, CreateAndPay self.assertTrue(SyncMock.called) self.assertTrue(CreateAndPayMock.called) + @patch("pinax.stripe.actions.invoices.create_and_pay") + @patch("pinax.stripe.actions.customers.sync_customer") + @patch("stripe.Customer.create") + def test_customer_create_user_with_plan_and_quantity(self, CreateMock, SyncMock, CreateAndPayMock): + Plan.objects.create( + stripe_id="pro-monthly", + name="Pro ($19.99/month each)", + amount=19.99, + interval="monthly", + interval_count=1, + currency="usd" + ) + CreateMock.return_value = dict(id="cus_YYYYYYYYYYYYY") + customer = customers.create(self.user, card="token232323", plan=self.plan, quantity=42) + self.assertEqual(customer.user, self.user) + self.assertEqual(customer.stripe_id, "cus_YYYYYYYYYYYYY") + _, kwargs = CreateMock.call_args + self.assertEqual(kwargs["email"], self.user.email) + self.assertEqual(kwargs["source"], "token232323") + self.assertEqual(kwargs["plan"], self.plan) + self.assertEqual(kwargs["quantity"], 42) + self.assertIsNotNone(kwargs["trial_end"]) + self.assertTrue(SyncMock.called) + self.assertTrue(CreateAndPayMock.called) + @patch("stripe.Customer.retrieve") def test_purge(self, RetrieveMock): customer = Customer.objects.create(