M config.dhall.sample => config.dhall.sample +8 -4
@@ 8,11 8,12 @@
port = 5347
},
sgx = "component2.localhost",
- creds = toMap {
- nick = "userid",
- username = "token",
- password = "secret"
+ creds = {
+ account = "00000",
+ username = "dashboard user",
+ password = "dashboard password"
},
+ bandwidth_site = "",
braintree = {
environment = "sandbox",
merchant_id = "",
@@ 24,6 25,9 @@
}
},
plans = ./plans.dhall
+ electrum = ./electrum.dhall,
+ oxr_app_id = "",
+ activation_amount = 15,
credit_card_url = \(jid: Text) -> \(customer_id: Text) ->
"https://pay.jmp.chat/${jid}/credit_cards?customer_id=${customer_id}"
}
M lib/registration.rb => lib/registration.rb +18 -5
@@ 65,7 65,7 @@ class Registration
},
{
value: "credit_card",
- label: "Credit Card"
+ label: "Credit Card ($#{CONFIG[:activation_amount]})"
},
{
value: "code",
@@ 173,8 173,8 @@ class Registration
def self.for(iq, customer, tel)
customer.payment_methods.then do |payment_methods|
- if payment_methods.default_payment_method
- Activate.new(iq, customer, tel)
+ if (method = payment_methods.default_payment_method)
+ Activate.new(iq, customer, method, tel)
else
new(iq, customer, tel)
end
@@ 210,8 210,21 @@ class Registration
end
class Activate
- def initialize(_iq, _customer, _tel)
- raise "TODO"
+ def initialize(iq, customer, payment_method, tel)
+ @reply = iq.reply
+ @customer = customer
+ @payment_method = payment_method
+ @tel = tel
+ end
+
+ def write
+ Transaction.sale(
+ @customer.merchant_account,
+ @payment_method,
+ CONFIG[:activation_amount]
+ ).then(&:insert).then do
+ @customer.bill_plan
+ end
end
end
end
M sgx_jmp.rb => sgx_jmp.rb +15 -5
@@ 8,12 8,19 @@ require "braintree"
require "dhall"
require "em-hiredis"
require "em_promise"
+require "ruby-bandwidth-iris"
+
+CONFIG =
+ Dhall::Coder
+ .new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc])
+ .load(ARGV[0], transform_keys: ->(k) { k&.to_sym })
singleton_class.class_eval do
include Blather::DSL
Blather::DSL.append_features(self)
end
+require_relative "lib/bandwidth_tn_order"
require_relative "lib/btc_sell_prices"
require_relative "lib/buy_account_credit_form"
require_relative "lib/customer"
@@ 24,13 31,15 @@ require_relative "lib/registration"
require_relative "lib/transaction"
require_relative "lib/web_register_manager"
-CONFIG =
- Dhall::Coder
- .new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc])
- .load(ARGV[0], transform_keys: ->(k) { k&.to_sym })
-
ELECTRUM = Electrum.new(**CONFIG[:electrum])
+Faraday.default_adapter = :em_synchrony
+BandwidthIris::Client.global_options = {
+ account_id: CONFIG[:creds][:account],
+ username: CONFIG[:creds][:username],
+ password: CONFIG[:creds][:password]
+}
+
# Braintree is not async, so wrap in EM.defer for now
class AsyncBraintree
def initialize(environment:, merchant_id:, public_key:, private_key:, **)
@@ 161,6 170,7 @@ disco_items node: "http://jabber.org/protocol/commands" do |iq|
end
command :execute?, node: "jabber:iq:register", sessionid: nil do |iq|
+ web_register_manager["test@localhost"] = "+15555550000"
Customer.for_jid(iq.from.stripped).catch {
nil
}.then { |customer|
M test/test_helper.rb => test/test_helper.rb +2 -1
@@ 41,7 41,8 @@ CONFIG = {
plans: [
{
name: "test_usd",
- currency: :USD
+ currency: :USD,
+ monthly_price: 1000
},
{
name: "test_bad_currency",
M test/test_registration.rb => test/test_registration.rb +38 -4
@@ 128,12 128,9 @@ class RegistrationTest < Minitest::Test
EMPromise.resolve("testaddr")
)
iq = Blather::Stanza::Iq::Command.new
- iq.form.fields = [
- { var: "plan_name", value: "test_usd" }
- ]
@bitcoin = Registration::Payment::Bitcoin.new(
iq,
- Customer.new("test"),
+ Customer.new("test", plan_name: "test_usd"),
"+15555550000"
)
end
@@ 187,5 184,42 @@ class RegistrationTest < Minitest::Test
)
end
end
+
+ class ActivateTest < Minitest::Test
+ Registration::Payment::CreditCard::Activate::Transaction =
+ Minitest::Mock.new
+
+ def test_write
+ transaction = PromiseMock.new
+ transaction.expect(
+ :insert,
+ EMPromise.resolve(nil)
+ )
+ Registration::Payment::CreditCard::Activate::Transaction.expect(
+ :sale,
+ transaction,
+ [
+ "merchant_usd",
+ :test_default_method,
+ CONFIG[:activation_amount]
+ ]
+ )
+ iq = Blather::Stanza::Iq::Command.new
+ customer = Minitest::Mock.new(
+ Customer.new("test", plan_name: "test_usd")
+ )
+ customer.expect(:bill_plan, nil)
+ Registration::Payment::CreditCard::Activate.new(
+ iq,
+ customer,
+ :test_default_method,
+ "+15555550000"
+ ).write.sync
+ Registration::Payment::CreditCard::Activate::Transaction.verify
+ transaction.verify
+ customer.verify
+ end
+ em :test_write
+ end
end
end