diff --git a/lib/stripe/topup.rb b/lib/stripe/topup.rb index 21218e71a..c1906e9df 100644 --- a/lib/stripe/topup.rb +++ b/lib/stripe/topup.rb @@ -7,5 +7,10 @@ class Topup < APIResource include Stripe::APIOperations::Save OBJECT_NAME = "topup".freeze + + def cancel + resp, api_key = request(:post, resource_url + "/cancel") + initialize_from(resp.data, api_key) + end end end diff --git a/test/stripe/topup_test.rb b/test/stripe/topup_test.rb index cd23ba7a8..cecd2dbe0 100644 --- a/test/stripe/topup_test.rb +++ b/test/stripe/topup_test.rb @@ -41,5 +41,14 @@ class TopupTest < Test::Unit::TestCase assert_requested :post, "#{Stripe.api_base}/v1/topups/tu_123" assert topup.is_a?(Stripe::Topup) end + + context "#cancel" do + should "cancel the topup" do + topup = Stripe::Topup.retrieve("tu_123") + topup = topup.cancel + assert_requested :post, "#{Stripe.api_base}/v1/topups/#{topup.id}/cancel" + assert topup.is_a?(Stripe::Topup) + end + end end end