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 support for listing source_transactions #603

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,32 +20,32 @@ 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

# 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

Expand Down
1 change: 1 addition & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions lib/stripe/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lib/stripe/source_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Stripe
class SourceTransaction < StripeObject
OBJECT_NAME = "source_transaction".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 @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions test/stripe/source_transaction_test.rb
Original file line number Diff line number Diff line change
@@ -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