Skip to content

Commit

Permalink
Merge pull request #678 from stripe/remi-fix-payment-intent
Browse files Browse the repository at this point in the history
Fix payment intent methods to take extra parameters
  • Loading branch information
brandur-stripe authored Aug 28, 2018
2 parents 3a8f1d7 + 0632afb commit 29d9e0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
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

0 comments on commit 29d9e0d

Please sign in to comment.