Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list_usage_record_summaries and list_source_transactions #882

Merged
merged 2 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/stripe/resources/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ module Stripe
class Source < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource

OBJECT_NAME = "source"

custom_method :verify, http_verb: :post

nested_resource_class_methods :source_transaction, operations: %i[list]

def verify(params = {}, opts = {})
request_stripe_object(
method: :post,
Expand Down Expand Up @@ -36,5 +39,7 @@ def source_transactions(params = {}, opts = {})
opts)
Util.convert_to_stripe_object(resp.data, opts)
end
extend Gem::Deprecate
deprecate :source_transactions, :"Source.list_source_transactions", 2020, 1
end
end
5 changes: 5 additions & 0 deletions lib/stripe/resources/subscription_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ class SubscriptionItem < APIResource
OBJECT_NAME = "subscription_item"

nested_resource_class_methods :usage_record, operations: %i[create]
nested_resource_class_methods :usage_record_summary,
operations: %i[list],
resource_plural: "usage_record_summaries"

def usage_record_summaries(params = {}, opts = {})
resp, opts = request(:get, resource_url + "/usage_record_summaries", params, opts)
Util.convert_to_stripe_object(resp.data, opts)
end
extend Gem::Deprecate
deprecate :usage_record_summaries, :"SubscriptionItem.list_usage_record_summaries", 2020, 1
end
end
10 changes: 9 additions & 1 deletion test/stripe/source_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ class SourceTransactionTest < Test::Unit::TestCase
@source = Stripe::Source.retrieve("src_123")
end

should "be listable" do
should "be listable (DEPRECATED)" do
transactions = @source.source_transactions

assert_requested :get, "#{Stripe.api_base}/v1/sources/#{@source.id}/source_transactions"
assert transactions.data.is_a?(Array)
assert transactions.first.is_a?(Stripe::SourceTransaction)
end

should "be listable" do
transactions = Stripe::Source.list_source_transactions(@source.id)

assert_requested :get, "#{Stripe.api_base}/v1/sources/#{@source.id}/source_transactions"
assert transactions.data.is_a?(Array)
assert transactions.first.is_a?(Stripe::SourceTransaction)
end
end
end
9 changes: 9 additions & 0 deletions test/stripe/subscription_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,14 @@ class SubscriptionItemTest < Test::Unit::TestCase
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/si_123/usage_records"
end
end

context "#list_usage_record_summaries" do
should "list usage record summaries" do
Stripe::SubscriptionItem.list_usage_record_summaries(
"si_123",
)
assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/si_123/usage_record_summaries"
end
end
end
end