diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ceb15eb3d..1898286ca 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,16 +1,16 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-10-12 18:19:29 +0200 using RuboCop version 0.50.0. +# on 2017-10-26 15:43:11 +0200 using RuboCop version 0.50.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 18 +# Offense count: 19 Metrics/AbcSize: Max: 49 -# Offense count: 24 +# Offense count: 27 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 455 @@ -20,17 +20,17 @@ Metrics/BlockLength: Metrics/ClassLength: Max: 583 -# Offense count: 8 +# Offense count: 10 Metrics/CyclomaticComplexity: Max: 13 -# Offense count: 215 +# Offense count: 257 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 310 -# Offense count: 31 +# Offense count: 32 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 47 @@ -38,14 +38,14 @@ Metrics/MethodLength: # Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 302 + Max: 303 # Offense count: 5 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 7 -# Offense count: 4 +# Offense count: 5 Metrics/PerceivedComplexity: Max: 15 diff --git a/lib/stripe.rb b/lib/stripe.rb index 12effe1e5..a2468b37e 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -68,6 +68,7 @@ require "stripe/reversal" require "stripe/sku" require "stripe/source" +require "stripe/source_transaction" require "stripe/subscription" require "stripe/subscription_item" require "stripe/three_d_secure" diff --git a/lib/stripe/source.rb b/lib/stripe/source.rb index 1cce5540a..399eaba3b 100644 --- a/lib/stripe/source.rb +++ b/lib/stripe/source.rb @@ -23,6 +23,11 @@ def delete(params = {}, opts = {}) extend Gem::Deprecate deprecate :delete, "#detach", 2017, 10 + def source_transactions(params = {}, opts = {}) + resp, opts = request(:get, resource_url + "/source_transactions", params, Util.normalize_opts(opts)) + Util.convert_to_stripe_object(resp.data, opts) + end + def verify(params = {}, opts = {}) resp, opts = request(:post, resource_url + "/verify", params, Util.normalize_opts(opts)) initialize_from(resp.data, opts) diff --git a/lib/stripe/source_transaction.rb b/lib/stripe/source_transaction.rb new file mode 100644 index 000000000..a661a9a51 --- /dev/null +++ b/lib/stripe/source_transaction.rb @@ -0,0 +1,5 @@ +module Stripe + class SourceTransaction < StripeObject + OBJECT_NAME = "source_transaction".freeze + end +end diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index 3a6e20d6b..103fc8833 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -77,6 +77,7 @@ def self.object_classes Reversal::OBJECT_NAME => Reversal, SKU::OBJECT_NAME => SKU, Source::OBJECT_NAME => Source, + SourceTransaction::OBJECT_NAME => SourceTransaction, Subscription::OBJECT_NAME => Subscription, SubscriptionItem::OBJECT_NAME => SubscriptionItem, ThreeDSecure::OBJECT_NAME => ThreeDSecure, diff --git a/test/stripe/source_transaction_test.rb b/test/stripe/source_transaction_test.rb new file mode 100644 index 000000000..f5ce90c45 --- /dev/null +++ b/test/stripe/source_transaction_test.rb @@ -0,0 +1,28 @@ +require File.expand_path("../../test_helper", __FILE__) + +module Stripe + class SourceTransactionTest < Test::Unit::TestCase + setup do + @source = Stripe::Source.retrieve("src_123") + end + + should "be listable" do + # TODO: remove the stub once stripe-mock supports /v1/sources/src_.../source_transactions + stub_request(:get, "#{Stripe.api_base}/v1/sources/#{@source.id}/source_transactions") + .to_return(body: JSON.generate( + object: "list", + data: [ + { + object: "source_transaction", + }, + ] + )) + + 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 + end +end