Support deleting subscription discounts

This commit is contained in:
Jim Danz 2014-01-29 14:54:31 -08:00
parent 06cfcc6131
commit c4d5774170
2 changed files with 25 additions and 0 deletions

View File

@ -10,5 +10,16 @@ module Stripe
def self.retrieve(id, api_key=nil)
raise NotImplementedError.new("Subscriptions cannot be retrieved without a customer ID. Retrieve a subscription using customer.subscriptions.retrieve('subscription_id')")
end
def delete_discount
Stripe.request(:delete, discount_url, @api_key)
refresh_from({ :discount => nil }, api_key, true)
end
private
def discount_url
url + '/discount'
end
end
end

View File

@ -54,5 +54,19 @@ module Stripe
subscription = customer.subscriptions.create(:plan => 'silver')
assert_equal subscription.id, 'test_new_subscription'
end
should "be able to delete a subscriptions's discount" do
@mock.expects(:get).once.returns(test_response(test_customer))
@mock.expects(:post).once.returns(test_response(test_subscription(:id => 'test_new_subscription')))
customer = Stripe::Customer.retrieve("test_customer")
subscription = customer.subscriptions.create(:plan => 'silver')
url = "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/test_new_subscription/discount"
@mock.expects(:delete).once.with(url, nil, nil).returns(test_response(test_delete_discount_response))
subscription.delete_discount
assert_equal nil, subscription.discount
end
end
end