From a5fbd9e843754876f224f566e5572d1c52edc776 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 13 Apr 2022 09:02:00 -0500 Subject: [PATCH] Use correct merchant account for card verification Based on plan currency --- config.ru | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/config.ru b/config.ru index b81a995..feba605 100644 --- a/config.ru +++ b/config.ru @@ -26,6 +26,7 @@ end use Sentry::Rack::CaptureExceptions REDIS = Redis.new +PLANS = Dhall.load("env:PLANS").sync BRAINTREE_CONFIG = Dhall.load("env:BRAINTREE_CONFIG").sync ELECTRUM = Electrum.new( **Dhall::Coder.load("env:ELECTRUM_CONFIG", transform_keys: :to_sym) @@ -90,8 +91,21 @@ class CreditCardGateway @customer_id end + def customer_plan + name = DB.exec_params(<<~SQL, [customer_id]).first&.[]("plan_name") + SELECT plan_name FROM customer_plans WHERE customer_id=$1 LIMIT 1 + SQL + PLANS.find { |plan| plan[:name].to_s == name } + end + + def merchant_account + BRAINTREE_CONFIG[:merchant_accounts][customer_plan[:currency]] + end + def client_token - @gateway.client_token.generate(customer_id: customer_id) + kwargs = {} + kwargs[:merchant_account_id] = merchant_account.to_s if merchant_account + @gateway.client_token.generate(customer_id: customer_id, **kwargs) end def payment_methods? -- 2.45.2