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

Commit 9ac448f

Browse files
Re-add FPX support (#69)
1 parent 67cb89f commit 9ac448f

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

web.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ def create_customer
214214
begin
215215
payment_intent = Stripe::PaymentIntent.create(
216216
:amount => amount,
217-
:currency => 'usd',
217+
:currency => currency_for_country(payload[:country]),
218218
:customer => payload[:customer_id] || @customer.id,
219219
:description => "Example PaymentIntent",
220220
:capture_method => ENV['CAPTURE_METHOD'] == "manual" ? "manual" : "automatic",
221+
payment_method_types: payment_methods_for_country(payload[:country]),
221222
:metadata => {
222223
:order_id => '5278735C-1F40-407D-933A-286E463E72D8',
223224
}.merge(payload[:metadata] || {}),
@@ -262,7 +263,7 @@ def create_customer
262263
# Create and confirm the PaymentIntent
263264
payment_intent = Stripe::PaymentIntent.create(
264265
:amount => amount,
265-
:currency => 'usd',
266+
:currency => currency_for_country(payload[:country]),
266267
:customer => payload[:customer_id] || @customer.id,
267268
:source => payload[:source],
268269
:payment_method => payload[:payment_method_id],
@@ -358,3 +359,28 @@ def calculate_price(products, shipping)
358359

359360
return amount
360361
end
362+
363+
def currency_for_country(country)
364+
# Determine currency to use. Generally a store would charge different prices for
365+
# different countries, but for the sake of simplicity we'll charge X of the local currency.
366+
367+
case country
368+
when 'us'
369+
'usd'
370+
when 'my'
371+
'myr'
372+
else
373+
'usd'
374+
end
375+
end
376+
377+
def payment_methods_for_country(country)
378+
case country
379+
when 'us'
380+
['card']
381+
when 'my'
382+
['card', 'fpx']
383+
else
384+
['card']
385+
end
386+
end

0 commit comments

Comments
 (0)