Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Add support for passing payment_method_types param in payload (#65)
Browse files Browse the repository at this point in the history
This is necessary for supporting payment methods other than 'card'
  • Loading branch information
mshafrir-stripe authored Aug 21, 2019
1 parent b387631 commit 0f3c3de
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def log_info(message)
payload[:amount],
payload[:source],
payload[:payment_method],
payload[:payment_method_types] || ['card'],
payload[:customer_id] || @customer.id,
payload[:metadata],
'usd',
payload[:currency] || 'usd',
payload[:shipping],
payload[:return_url],
)
Expand Down Expand Up @@ -148,7 +149,7 @@ def create_customer
end
begin
setup_intent = Stripe::SetupIntent.create({
payment_method_types: ['card'],
payment_method_types: payload[:payment_method_types] || ['card'],
payment_method: payload[:payment_method],
return_url: payload[:return_url],
confirm: payload[:payment_method] != nil,
Expand Down Expand Up @@ -183,6 +184,7 @@ def create_customer
params[:amount],
nil,
nil,
params[:payment_method_types] || ['card'],
nil,
params[:metadata],
params[:currency],
Expand Down Expand Up @@ -226,6 +228,7 @@ def create_customer
source.amount,
source.id,
nil,
['card'],
source.metadata["customer"],
source.metadata,
source.currency,
Expand All @@ -244,15 +247,15 @@ def create_customer
status 200
end

def create_payment_intent(amount, source_id, payment_method_id, customer_id = nil,
def create_payment_intent(amount, source_id, payment_method_id, payment_method_types = ['card'], customer_id = nil,
metadata = {}, currency = 'usd', shipping = nil, return_url = nil, confirm = false)
return Stripe::PaymentIntent.create(
:amount => amount,
:currency => currency || 'usd',
:customer => customer_id,
:source => source_id,
:payment_method => payment_method_id,
:payment_method_types => ['card'],
:payment_method_types => payment_method_types,
:description => "Example PaymentIntent",
:shipping => shipping,
:return_url => return_url,
Expand All @@ -266,8 +269,9 @@ def create_payment_intent(amount, source_id, payment_method_id, customer_id = ni
)
end

def create_and_capture_payment_intent(amount, source_id, payment_method_id, customer_id = nil,
metadata = {}, currency = 'usd', shipping = nil, return_url = nil)
return create_payment_intent(amount, source_id, payment_method_id, customer_id,
metadata, currency, shipping, return_url, true)
def create_and_capture_payment_intent(amount, source_id, payment_method_id, payment_method_types = ['card'],
customer_id = nil, metadata = {}, currency = 'usd', shipping = nil,
return_url = nil)
return create_payment_intent(amount, source_id, payment_method_id, payment_method_types,
customer_id, metadata, currency, shipping, return_url, true)
end

0 comments on commit 0f3c3de

Please sign in to comment.