Merge branch '3ds-tx'

Stephen Paul Weber created

* 3ds-tx:
  Privacy.com doesn't even like us anymore
  3DS first transaction

Change summary

lib/registration.rb       | 28 +++++++++++++-------
test/test_helper.rb       |  2 
test/test_registration.rb | 55 +++++++++++++++++++++++++++++-----------
3 files changed, 58 insertions(+), 27 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -229,16 +229,27 @@ class Registration
 		class CreditCard
 			Payment.kinds[:credit_card] = ->(*args, **kw) { self.for(*args, **kw) }
 
-			def self.for(customer, tel, finish: Finish, **)
-				customer.payment_methods.then do |payment_methods|
+			def self.for(in_customer, tel, finish: Finish, **)
+				reload_customer(in_customer).then do |(customer, payment_methods)|
+					if customer.balance >= CONFIG[:activation_amount_accept]
+						next BillPlan.new(customer, tel, finish: finish)
+					end
+
 					if (method = payment_methods.default_payment_method)
-						Activate.new(customer, method, tel, finish: finish)
-					else
-						new(customer, tel, finish: finish)
+						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
+				])
+			end
+
 			def initialize(customer, tel, finish: Finish)
 				@customer = customer
 				@tel = tel
@@ -250,7 +261,7 @@ class Registration
 				oob.url = CONFIG[:credit_card_url].call(
 					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
 			end
@@ -299,9 +310,6 @@ class Registration
 					"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" \
-					"If you were trying a prepaid card, you may wish to use "\
-					"Privacy.com instead, as they do support international " \
-					"transactions.\n\n " \
 					"You may add another card"
 
 				def decline_oob(reply)
@@ -309,7 +317,7 @@ class Registration
 					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

test/test_helper.rb 🔗

@@ -97,7 +97,7 @@ CONFIG = {
 		realm: "sip.example.com",
 		app: "sipappid"
 	},
-	credit_card_url: ->(*) { "http://creditcard.example.com" },
+	credit_card_url: ->(*) { "http://creditcard.example.com?" },
 	electrum_notify_url: ->(*) { "http://notify.example.com" },
 	keep_area_codes: ["556"],
 	keep_area_codes_in: {

test/test_registration.rb 🔗

@@ -285,11 +285,14 @@ class RegistrationTest < Minitest::Test
 				{ var: "activation_method", value: "credit_card" },
 				{ var: "plan_name", value: "test_usd" }
 			]
-			result = Registration::Payment.for(
-				iq,
-				cust,
-				"+15555550000"
-			).sync
+			result = execute_command do
+				Command.execution.customer_repo.expect(:find, cust, ["test"])
+				Registration::Payment.for(
+					iq,
+					cust,
+					""
+				).sync
+			end
 			assert_kind_of Registration::Payment::CreditCard, result
 			assert_mock cust
 		end
@@ -377,21 +380,41 @@ class RegistrationTest < Minitest::Test
 			end
 
 			def test_for
-				customer = Minitest::Mock.new(customer)
-				customer.expect(
+				cust = Minitest::Mock.new(customer)
+				cust.expect(
 					:payment_methods,
 					EMPromise.resolve(OpenStruct.new(default_payment_method: :test))
 				)
-				assert_kind_of(
-					Registration::Payment::CreditCard::Activate,
-					Registration::Payment::CreditCard.for(
-						customer,
-						"+15555550000"
-					).sync
-				)
+				execute_command do
+					Command.execution.customer_repo.expect(:find, cust, ["test"])
+					assert_kind_of(
+						Registration::Payment::CreditCard::Activate,
+						Registration::Payment::CreditCard.for(
+							cust,
+							"+15555550000"
+						).sync
+					)
+				end
 			end
 			em :test_for
 
+			def test_for_has_balance
+				cust = Minitest::Mock.new(customer)
+				cust.expect(:balance, 100)
+				cust.expect(:payment_methods, EMPromise.resolve(nil))
+				execute_command do
+					Command.execution.customer_repo.expect(:find, cust, ["test"])
+					assert_kind_of(
+						Registration::BillPlan,
+						Registration::Payment::CreditCard.for(
+							cust,
+							"+15555550000"
+						).sync
+					)
+				end
+			end
+			em :test_for_has_balance
+
 			def test_write
 				result = execute_command do
 					Command::COMMAND_MANAGER.expect(
@@ -401,7 +424,7 @@ class RegistrationTest < Minitest::Test
 							assert_equal [:execute, :next, :prev], reply.allowed_actions
 							assert_equal(
 								"Add credit card, save, then next here to continue: " \
-								"http://creditcard.example.com",
+								"http://creditcard.example.com?&amount=1",
 								reply.note.content
 							)
 						end]
@@ -505,7 +528,7 @@ class RegistrationTest < Minitest::Test
 					[Matching.new do |reply|
 						assert_equal :error, reply.note_type
 						assert_equal(
-							"#{msg}: http://creditcard.example.com",
+							"#{msg}: http://creditcard.example.com?&amount=1",
 							reply.note.content
 						)
 					end]