@@ -214,10 +214,11 @@ def create_customer
214
214
begin
215
215
payment_intent = Stripe ::PaymentIntent . create (
216
216
:amount => amount ,
217
- :currency => 'usd' ,
217
+ :currency => currency_for_country ( payload [ :country ] ) ,
218
218
:customer => payload [ :customer_id ] || @customer . id ,
219
219
:description => "Example PaymentIntent" ,
220
220
:capture_method => ENV [ 'CAPTURE_METHOD' ] == "manual" ? "manual" : "automatic" ,
221
+ payment_method_types : payment_methods_for_country ( payload [ :country ] ) ,
221
222
:metadata => {
222
223
:order_id => '5278735C-1F40-407D-933A-286E463E72D8' ,
223
224
} . merge ( payload [ :metadata ] || { } ) ,
@@ -262,7 +263,7 @@ def create_customer
262
263
# Create and confirm the PaymentIntent
263
264
payment_intent = Stripe ::PaymentIntent . create (
264
265
:amount => amount ,
265
- :currency => 'usd' ,
266
+ :currency => currency_for_country ( payload [ :country ] ) ,
266
267
:customer => payload [ :customer_id ] || @customer . id ,
267
268
:source => payload [ :source ] ,
268
269
:payment_method => payload [ :payment_method_id ] ,
@@ -358,3 +359,28 @@ def calculate_price(products, shipping)
358
359
359
360
return amount
360
361
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