Skip to content
Browse files

Support deleting subscription discounts

  • Loading branch information...
1 parent 929c11b commit 755ca6fc52b841cb94c8d3df3db293be2b00ac9c @jimdanz jimdanz committed Jan 29, 2014
Showing with 28 additions and 0 deletions.
  1. +6 −0 stripe/resource.py
  2. +22 −0 stripe/test/test_integration.py
View
6 stripe/resource.py
@@ -457,6 +457,12 @@ def retrieve(cls, id, api_key=None, **params):
"Can't retrieve a subscription without a customer ID. "
"Use customer.subscriptions.retrieve('subscription_id') instead.")
+ def delete_discount(self, **params):
+ requestor = api_requestor.APIRequestor(self.api_key)
+ url = self.instance_url() + '/discount'
+ _, api_key = requestor.request('delete', url)
+ self.refresh_from({'discount': None}, api_key, True)
+
class Token(CreateableAPIResource):
pass
View
22 stripe/test/test_integration.py
@@ -460,6 +460,28 @@ def test_attach_coupon(self):
customer.delete_discount()
self.assertEqual(None, customer.discount)
+class SubscriptionCouponTest(StripeTestCase):
+
+ def setUp(self):
+ super(SubscriptionCouponTest, self).setUp()
+ self.plan_obj = stripe.Plan.create(**DUMMY_PLAN)
+ self.coupon_obj = stripe.Coupon.create(**DUMMY_COUPON)
+
+ def tearDown(self):
+ self.coupon_obj.delete()
+
+ def test_attach_coupon_to_subscription(self):
+ customer = stripe.Customer.create(card=DUMMY_CARD)
+
+ subscription = customer.subscriptions.create(
+ plan=DUMMY_PLAN['id'], coupon=self.coupon_obj.id)
+
+ self.assertTrue(hasattr(subscription, 'discount'))
+ self.assertNotEqual(None, subscription.discount)
+
+ subscription.delete_discount()
+ self.assertEqual(None, subscription.discount)
+
class InvalidRequestErrorTest(StripeTestCase):

0 comments on commit 755ca6f

Please sign in to comment.
Something went wrong with that request. Please try again.