@@ -396,24 +396,19 @@ class Registration
Payment.kinds[:credit_card] = ->(*args, **kw) { self.for(*args, **kw) }
def self.for(in_customer, tel, finish: Finish, **)
- reload_customer(in_customer).then do |(customer, payment_methods)|
+ reload_customer(in_customer).then do |customer|
if customer.balance >= CONFIG[:activation_amount_accept]
next BillPlan.new(customer, tel, finish: finish)
end
- if (method = payment_methods.default_payment_method)
- next Activate.new(customer, method, tel, finish: finish)
- end
-
new(customer, tel, finish: finish)
end
end
def self.reload_customer(customer)
- EMPromise.all([
- Command.execution.customer_repo.find(customer.customer_id),
- customer.payment_methods
- ])
+ EMPromise.resolve(nil).then do
+ Command.execution.customer_repo.find(customer.customer_id)
+ end
end
def initialize(customer, tel, finish: Finish)
@@ -428,7 +423,7 @@ class Registration
reply.to.stripped.to_s.gsub("\\", "%5C"),
@customer.customer_id
) + "&amount=#{CONFIG[:activation_amount]}"
- oob.desc = "Add credit card, save, then next here to continue"
+ oob.desc = "Pay by credit card, save, then next here to continue"
oob
end
@@ -444,61 +439,6 @@ class Registration
CreditCard.for(@customer, @tel, finish: @finish).then(&:write)
end
end
-
- class Activate
- def initialize(customer, payment_method, tel, finish: Finish)
- @customer = customer
- @payment_method = payment_method
- @tel = tel
- @finish = finish
- end
-
- def write
- CreditCardSale.create(
- @customer,
- amount: CONFIG[:activation_amount],
- payment_method: @payment_method
- ).then(
- ->(_) { sold },
- ->(_) { declined }
- )
- end
-
- protected
-
- def sold
- BillPlan.new(@customer, @tel, finish: @finish).write
- end
-
- DECLINE_MESSAGE =
- "Your bank declined the transaction. " \
- "Often this happens when a person's credit card " \
- "is a US card that does not support international " \
- "transactions, as JMP is not based in the USA, though " \
- "we do support transactions in USD.\n\n" \
- "You may add another card"
-
- def decline_oob(reply)
- oob = OOB.find_or_create(reply.command)
- oob.url = CONFIG[:credit_card_url].call(
- reply.to.stripped.to_s.gsub("\\", "%5C"),
- @customer.customer_id
- ) + "&amount=#{CONFIG[:activation_amount]}"
- oob.desc = DECLINE_MESSAGE
- oob
- end
-
- def declined
- Command.reply { |reply|
- reply_oob = decline_oob(reply)
- reply.allowed_actions = [:next]
- reply.note_type = :error
- reply.note_text = "#{reply_oob.desc}: #{reply_oob.url}"
- }.then do
- CreditCard.for(@customer, @tel, finish: @finish).then(&:write)
- end
- end
- end
end
class InviteCode
@@ -616,17 +616,6 @@ class RegistrationTest < Minitest::Test
end
def test_for_credit_card
- braintree_customer = Minitest::Mock.new
- CustomerFinancials::BRAINTREE.expect(
- :customer,
- braintree_customer
- )
- CustomerFinancials::REDIS.expect(:smembers, [], ["block_credit_cards"])
- braintree_customer.expect(
- :find,
- EMPromise.resolve(OpenStruct.new(payment_methods: [])),
- ["test"]
- )
iq = Blather::Stanza::Iq::Command.new
iq.from = "test@example.com"
iq.form.fields = [
@@ -780,7 +769,7 @@ class RegistrationTest < Minitest::Test
execute_command do
Command.execution.customer_repo.expect(:find, cust, ["test"])
assert_kind_of(
- Registration::Payment::CreditCard::Activate,
+ Registration::Payment::CreditCard,
Registration::Payment::CreditCard.for(
cust,
"+15555550000"
@@ -815,7 +804,7 @@ class RegistrationTest < Minitest::Test
[Matching.new do |reply|
assert_equal [:execute, :next, :prev], reply.allowed_actions
assert_equal(
- "Add credit card, save, then next here to continue: " \
+ "Pay by credit card, save, then next here to continue: " \
"http://creditcard.example.com?&amount=1",
reply.note.content
)
@@ -865,88 +854,6 @@ class RegistrationTest < Minitest::Test
em :test_write
end
- class ActivateTest < Minitest::Test
- Registration::Payment::CreditCard::Activate::Finish =
- Minitest::Mock.new
- Registration::Payment::CreditCard::Activate::CreditCardSale =
- Minitest::Mock.new
- Command::COMMAND_MANAGER = Minitest::Mock.new
-
- def test_write
- customer = Minitest::Mock.new(
- customer(plan_name: "test_usd")
- )
- Registration::Payment::CreditCard::Activate::CreditCardSale.expect(
- :create,
- EMPromise.resolve(nil)
- ) do |acustomer, amount:, payment_method:|
- assert_operator customer, :===, acustomer
- assert_equal CONFIG[:activation_amount], amount
- assert_equal :test_default_method, payment_method
- end
- customer.expect(
- :bill_plan,
- nil,
- note: "Bill +15555550000 for first month"
- )
- Registration::Payment::CreditCard::Activate::Finish.expect(
- :new,
- OpenStruct.new(write: nil),
- [customer, "+15555550000"]
- )
- execute_command do
- Registration::Payment::CreditCard::Activate.new(
- customer,
- :test_default_method,
- "+15555550000"
- ).write
- end
- Registration::Payment::CreditCard::Activate::CreditCardSale.verify
- customer.verify
- Registration::Payment::CreditCard::Activate::Finish.verify
- end
- em :test_write
-
- def test_write_declines
- customer = Minitest::Mock.new(
- customer(plan_name: "test_usd")
- )
- iq = Blather::Stanza::Iq::Command.new
- iq.from = "test@example.com"
- msg = Registration::Payment::CreditCard::Activate::DECLINE_MESSAGE
- Command::COMMAND_MANAGER.expect(
- :write,
- EMPromise.reject(:test_result),
- [Matching.new do |reply|
- assert_equal :error, reply.note_type
- assert_equal(
- "#{msg}: http://creditcard.example.com?&amount=1",
- reply.note.content
- )
- end]
- )
- result = execute_command do
- Registration::Payment::CreditCard::Activate::CreditCardSale.expect(
- :create,
- EMPromise.reject("declined")
- ) do |acustomer, amount:, payment_method:|
- assert_operator customer, :===, acustomer
- assert_equal CONFIG[:activation_amount], amount
- assert_equal :test_default_method, payment_method
- end
-
- Registration::Payment::CreditCard::Activate.new(
- customer,
- :test_default_method,
- "+15555550000"
- ).write.catch { |e| e }
- end
- assert_equal :test_result, result
- Registration::Payment::CreditCard::Activate::CreditCardSale.verify
- end
- em :test_write_declines
- end
-
class InviteCodeTest < Minitest::Test
Registration::Payment::InviteCode::DB =
Minitest::Mock.new