@@ 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?