From d698bd6fc70323087ed93d769d624cb559f27393 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Fri, 3 Aug 2018 12:50:39 +0200 Subject: [PATCH] Add cancel support for topups --- lib/stripe/topup.rb | 5 +++++ test/stripe/topup_test.rb | 9 +++++++++ 2 files changed, 14 insertions(+) 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