Skip to content

Commit

Permalink
Add support for /v1/topups endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkakar-stripe committed Feb 16, 2018
1 parent 16704d9 commit 0be2268
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Metrics/MethodLength:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 304
Max: 305

# Offense count: 5
# Configuration parameters: CountKeywordArgs.
Expand Down
1 change: 1 addition & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
require "stripe/subscription_item"
require "stripe/three_d_secure"
require "stripe/token"
require "stripe/topup"
require "stripe/transfer"

# OAuth
Expand Down
9 changes: 9 additions & 0 deletions lib/stripe/topup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Stripe
class Topup < APIResource
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Save

OBJECT_NAME = "topup".freeze
end
end
1 change: 1 addition & 0 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def self.object_classes
SubscriptionItem::OBJECT_NAME => SubscriptionItem,
ThreeDSecure::OBJECT_NAME => ThreeDSecure,
Token::OBJECT_NAME => Token,
Topup::OBJECT_NAME => Topup,
Transfer::OBJECT_NAME => Transfer,
}
end
Expand Down
43 changes: 43 additions & 0 deletions test/stripe/topup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require File.expand_path("../../test_helper", __FILE__)

module Stripe
class TopupTest < Test::Unit::TestCase
should "be listable" do
topups = Stripe::Topup.list
assert_requested :get, "#{Stripe.api_base}/v1/topups"
assert topups.data.is_a?(Array)
assert topups.data[0].is_a?(Stripe::Topup)
end

should "be retrievable" do
topup = Stripe::Topup.retrieve("tu_123")
assert_requested :get, "#{Stripe.api_base}/v1/topups/tu_123"
assert topup.is_a?(Stripe::Topup)
end

should "be creatable" do
topup = Stripe::Topup.create(
amount: 100,
currency: "USD",
source: "src_123",
description: "description",
statement_descriptor: "statement descriptor"
)
assert_requested :post, "#{Stripe.api_base}/v1/topups"
assert topup.is_a?(Stripe::Topup)
end

should "be saveable" do
topup = Stripe::Topup.retrieve("tu_123")
topup.metadata["key"] = "value"
topup.save
assert_requested :post, "#{Stripe.api_base}/v1/topups/#{topup.id}"
end

should "be updateable" do
topup = Stripe::Topup.update("tu_123", metadata: { foo: "bar" })
assert_requested :post, "#{Stripe.api_base}/v1/topups/tu_123"
assert topup.is_a?(Stripe::Topup)
end
end
end

0 comments on commit 0be2268

Please sign in to comment.