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

Fix payment intent methods to take extra parameters #678

Merged
merged 1 commit into from
Aug 28, 2018
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
19 changes: 9 additions & 10 deletions lib/stripe/payment_intent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
module Stripe
class PaymentIntent < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "payment_intent".freeze

def cancel
resp, api_key = request(:post, resource_url + "/cancel")
initialize_from(resp.data, api_key)
def cancel(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/cancel", params, opts)
initialize_from(resp.data, opts)
end

def capture
resp, api_key = request(:post, resource_url + "/capture")
initialize_from(resp.data, api_key)
def capture(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/capture", params, opts)
initialize_from(resp.data, opts)
end

def confirm
resp, api_key = request(:post, resource_url + "/confirm")
initialize_from(resp.data, api_key)
def confirm(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/confirm", params, opts)
initialize_from(resp.data, opts)
end
end
end
8 changes: 6 additions & 2 deletions test/stripe/payment_intent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class PaymentIntentTest < Test::Unit::TestCase
context "#capture" do
should "capture a payment_intent" do
payment_intent = Stripe::PaymentIntent.construct_from(id: "pi_123", object: "payment_intent")
payment_intent = payment_intent.capture
payment_intent = payment_intent.capture(
amount_to_capture: 1234
)

assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_123/capture"
assert payment_intent.is_a?(Stripe::PaymentIntent)
Expand All @@ -66,7 +68,9 @@ class PaymentIntentTest < Test::Unit::TestCase
context "#confirm" do
should "confirm a payment_intent" do
payment_intent = Stripe::PaymentIntent.construct_from(id: "pi_123", object: "payment_intent")
payment_intent = payment_intent.confirm
payment_intent = payment_intent.confirm(
source: "src_123"
)

assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_123/confirm"
assert payment_intent.is_a?(Stripe::PaymentIntent)
Expand Down