~singpolyma/jmp-pay

a5fbd9e843754876f224f566e5572d1c52edc776 — Stephen Paul Weber 1 year, 5 months ago a52b561
Use correct merchant account for card verification

Based on plan currency
1 files changed, 15 insertions(+), 1 deletions(-)

M config.ru
M config.ru => config.ru +15 -1
@@ 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?