-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the
SetupIntent
resource and APIs
- Loading branch information
1 parent
2cc7714
commit a993e89
Showing
8 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class SetupIntent < APIResource | ||
extend Stripe::APIOperations::Create | ||
extend Stripe::APIOperations::List | ||
include Stripe::APIOperations::Save | ||
|
||
OBJECT_NAME = "setup_intent".freeze | ||
|
||
custom_method :cancel, http_verb: :post | ||
custom_method :confirm, http_verb: :post | ||
|
||
def cancel(params = {}, opts = {}) | ||
resp, opts = request(:post, resource_url + "/cancel", params, opts) | ||
Util.convert_to_stripe_object(resp.data, opts) | ||
end | ||
|
||
def confirm(params = {}, opts = {}) | ||
resp, opts = request(:post, resource_url + "/confirm", params, opts) | ||
Util.convert_to_stripe_object(resp.data, opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../test_helper", __dir__) | ||
|
||
module Stripe | ||
class SetupIntentTest < Test::Unit::TestCase | ||
TEST_RESOURCE_ID = "seti_123".freeze | ||
|
||
should "be listable" do | ||
setup_intents = Stripe::SetupIntent.list | ||
assert_requested :get, "#{Stripe.api_base}/v1/setup_intents" | ||
assert setup_intents.data.is_a?(Array) | ||
assert setup_intents.data[0].is_a?(Stripe::SetupIntent) | ||
end | ||
|
||
should "be retrievable" do | ||
setup_intent = Stripe::SetupIntent.retrieve("seti_123") | ||
assert_requested :get, "#{Stripe.api_base}/v1/setup_intents/seti_123" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
|
||
should "be creatable" do | ||
setup_intent = Stripe::SetupIntent.create( | ||
payment_method_types: ["card"] | ||
) | ||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
|
||
should "be saveable" do | ||
setup_intent = Stripe::SetupIntent.construct_from(id: "seti_123", object: "setup_intent", metadata: {}) | ||
setup_intent.metadata["key"] = "value" | ||
setup_intent.save | ||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/#{setup_intent.id}" | ||
end | ||
|
||
should "be updateable" do | ||
setup_intent = Stripe::SetupIntent.update("seti_123", metadata: { foo: "bar" }) | ||
|
||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
|
||
context "#cancel" do | ||
should "cancel a setup_intent" do | ||
setup_intent = Stripe::SetupIntent.construct_from(id: "seti_123", object: "setup_intent") | ||
setup_intent = setup_intent.cancel | ||
|
||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/cancel" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
end | ||
|
||
context ".cancel" do | ||
should "cancel a setup_intent" do | ||
setup_intent = Stripe::SetupIntent.cancel("seti_123") | ||
|
||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/cancel" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
end | ||
|
||
context "#confirm" do | ||
should "confirm a setup_intent" do | ||
setup_intent = Stripe::SetupIntent.construct_from(id: "seti_123", object: "setup_intent") | ||
setup_intent = setup_intent.confirm( | ||
payment_method: "pm_123" | ||
) | ||
|
||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/confirm" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
end | ||
|
||
context ".confirm" do | ||
should "confirm a setup_intent" do | ||
setup_intent = Stripe::SetupIntent.confirm("seti_123", payment_method: "pm_123") | ||
|
||
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/confirm" | ||
assert setup_intent.is_a?(Stripe::SetupIntent) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters