Skip to content

Commit

Permalink
Add support for the Issuing Dispute Submit API (#944)
Browse files Browse the repository at this point in the history
* Codegen for openapi 474461f

* Add and fix tests for the latest stripe-mock

Some of the tests had to be changed/mocked because stripe-mock has a bug
where the includable sub-lists it returns have the wrong url set.
Because of this, when you call create/list/etc. on one of those sub-lists
the calls fails due to that URL being incorrect.
Moved one test to use charge+refund (auto-expanded) and another used a
mock to have the right URL returned.
  • Loading branch information
remi-stripe committed Sep 2, 2020
1 parent e1ae307 commit 683b101
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -17,7 +17,7 @@ sudo: false
env:
global:
# If changing this number, please also change it in `test/test_helper.rb`.
- STRIPE_MOCK_VERSION=0.95.0
- STRIPE_MOCK_VERSION=0.98.0

cache:
directories:
Expand Down
11 changes: 11 additions & 0 deletions lib/stripe/resources/issuing/dispute.rb
Expand Up @@ -9,6 +9,17 @@ class Dispute < APIResource
include Stripe::APIOperations::Save

OBJECT_NAME = "issuing.dispute"

custom_method :submit, http_verb: :post

def submit(params = {}, opts = {})
request_stripe_object(
method: :post,
path: resource_url + "/submit",
params: params,
opts: opts
)
end
end
end
end
14 changes: 7 additions & 7 deletions test/stripe/api_resource_test.rb
Expand Up @@ -111,15 +111,15 @@ class NestedTestAPIResource < APIResource
end

should "send expand when fetching through ListObject" do
stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123")
.to_return(body: JSON.generate(customer_fixture))
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123")
.to_return(body: JSON.generate(charge_fixture))

stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123/sources/cc_test_card")
.with(query: { "expand" => ["customer"] })
.to_return(body: JSON.generate(customer_fixture))
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123/refunds/re_123")
.with(query: { "expand" => ["balance_transaction"] })
.to_return(body: JSON.generate(charge_fixture))

customer = Stripe::Customer.retrieve("cus_123")
customer.sources.retrieve(id: "cc_test_card", expand: [:customer])
charge = Stripe::Charge.retrieve("ch_123")
charge.refunds.retrieve(id: "re_123", expand: [:balance_transaction])
end

context "when specifying per-object credentials" do
Expand Down
6 changes: 6 additions & 0 deletions test/stripe/customer_card_test.rb
Expand Up @@ -5,6 +5,12 @@
module Stripe
class CustomerCardTest < Test::Unit::TestCase
setup do
# Unfortunately, the OpenAPI spec has an issue where the sources list has the wrong
# url so we need to mock this call instead.
customer_json = { id: "cus_123", object: "customer", sources: { object: "list", data: [], has_more: true, url: "/v1/customers/cus_123/sources" } }
stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123")
.to_return(body: JSON.generate(customer_json))

@customer = Stripe::Customer.retrieve("cus_123")
end

Expand Down
21 changes: 20 additions & 1 deletion test/stripe/issuing/dispute_test.rb
Expand Up @@ -6,7 +6,7 @@ module Stripe
module Issuing
class DisputeTest < Test::Unit::TestCase
should "be creatable" do
dispute = Stripe::Issuing::Dispute.create
dispute = Stripe::Issuing::Dispute.create(transaction: "ipi_123")

assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes"
assert dispute.is_a?(Stripe::Issuing::Dispute)
Expand All @@ -30,6 +30,25 @@ class DisputeTest < Test::Unit::TestCase
assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes/ich_123"
assert dispute.is_a?(Stripe::Issuing::Dispute)
end

context "#submit" do
should "submit the dispute" do
dispute = Stripe::Issuing::Dispute.retrieve("idp_123")
dispute = dispute.submit
assert_requested :post,
"#{Stripe.api_base}/v1/issuing/disputes/idp_123/submit"
assert dispute.is_a?(Stripe::Issuing::Dispute)
end
end

context ".submit" do
should "submit the dispute" do
dispute = Stripe::Issuing::Dispute.submit("idp_123")
assert_requested :post,
"#{Stripe.api_base}/v1/issuing/disputes/idp_123/submit"
assert dispute.is_a?(Stripe::Issuing::Dispute)
end
end
end
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -16,7 +16,7 @@
require ::File.expand_path("stripe_mock", __dir__)

# If changing this number, please also change it in `.travis.yml`.
MOCK_MINIMUM_VERSION = "0.95.0"
MOCK_MINIMUM_VERSION = "0.98.0"
MOCK_PORT = Stripe::StripeMock.start

# Disable all real network connections except those that are outgoing to
Expand Down

0 comments on commit 683b101

Please sign in to comment.