Detailed changes
@@ -43,6 +43,13 @@ SCHEMA = "{
name : Text,
allow_register: Bool,
subaccount_discount: Natural
+ },
+ braintree: {
+ environment : Text,
+ merchant_accounts : { CAD : Text, USD : Text },
+ merchant_id : Text,
+ private_key : Text,
+ public_key : Text
}
}"
@@ -55,6 +62,7 @@ CONFIG = Dhall::Coder
CONFIG[:keep_area_codes_in] = {}
CONFIG[:creds] = {}
+require_relative "../lib/async_braintree"
require_relative "../lib/blather_notify"
require_relative "../lib/customer_repo"
require_relative "../lib/low_balance"
@@ -62,6 +70,7 @@ require_relative "../lib/postgres"
require_relative "../lib/sim_repo"
require_relative "../lib/transaction"
+BRAINTREE = AsyncBraintree.new(**CONFIG[:braintree])
CUSTOMER_REPO = CustomerRepo.new
SIM_REPO = SIMRepo.new
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# Braintree is not async, so wrap in EM.defer for now
+class AsyncBraintree
+ def initialize(environment:, merchant_id:, public_key:, private_key:, **)
+ @gateway = Braintree::Gateway.new(
+ environment: environment,
+ merchant_id: merchant_id,
+ public_key: public_key,
+ private_key: private_key
+ )
+ @gateway.config.logger = LOG
+ end
+
+ def respond_to_missing?(m, *)
+ @gateway.respond_to?(m) || super
+ end
+
+ def method_missing(m, *args)
+ return super unless respond_to_missing?(m, *args)
+
+ EM.promise_defer(klass: PromiseChain) do
+ @gateway.public_send(m, *args)
+ end
+ end
+
+ class PromiseChain < EMPromise
+ def respond_to_missing?(*)
+ false && super # We don't actually know what we respond to...
+ end
+
+ def method_missing(m, *args)
+ return super if respond_to_missing?(m, *args)
+
+ self.then { |o| o.public_send(m, *args) }
+ end
+ end
+end
@@ -124,43 +124,7 @@ BANDWIDTH_VOICE = Bandwidth::Client.new(
class AuthError < StandardError; end
-# Braintree is not async, so wrap in EM.defer for now
-class AsyncBraintree
- def initialize(environment:, merchant_id:, public_key:, private_key:, **)
- @gateway = Braintree::Gateway.new(
- environment: environment,
- merchant_id: merchant_id,
- public_key: public_key,
- private_key: private_key
- )
- @gateway.config.logger = LOG
- end
-
- def respond_to_missing?(m, *)
- @gateway.respond_to?(m) || super
- end
-
- def method_missing(m, *args)
- return super unless respond_to_missing?(m, *args)
-
- EM.promise_defer(klass: PromiseChain) do
- @gateway.public_send(m, *args)
- end
- end
-
- class PromiseChain < EMPromise
- def respond_to_missing?(*)
- false && super # We don't actually know what we respond to...
- end
-
- def method_missing(m, *args)
- return super if respond_to_missing?(m, *args)
-
- self.then { |o| o.public_send(m, *args) }
- end
- end
-end
-
+require_relative "lib/async_braintree"
BRAINTREE = AsyncBraintree.new(**CONFIG[:braintree])
def panic(e, hub=nil)