~singpolyma/sgx-jmp

c49b2c6ed2fabce87d87ca0e03821fca12d27be8 — Stephen Paul Weber 8 months ago 64b88af
No more legacy session for BTC

Set the same key as web register manager, so that on next register jmp.chat the
tel we were using in this flow will be used.   Not needed if they came from web
register, but will still extend expiry in that case and no harm.

Clean up pending tel key on Finish.
2 files changed, 13 insertions(+), 12 deletions(-)

M lib/registration.rb
M test/test_registration.rb
M lib/registration.rb => lib/registration.rb +8 -12
@@ 157,6 157,8 @@ class Registration
		class Bitcoin
			Payment.kinds[:bitcoin] = method(:new)

			THIRTY_DAYS = 60 * 60 * 24 * 30

			def initialize(customer, tel)
				@customer = customer
				@customer_id = customer.customer_id


@@ 165,20 167,13 @@ class Registration

			attr_reader :customer_id, :tel

			def legacy_session_save
				sid = SecureRandom.hex
				REDIS.mset(
					"reg-sid_for-#{customer_id}", sid,
					"reg-session_tel-#{sid}", tel
				)
			end

			def save
				EMPromise.all([
					legacy_session_save,
					REDIS.mset(
						"pending_tel_for-#{customer_id}", tel,
						"pending_plan_for-#{customer_id}", @customer.plan_name
					REDIS.setex("pending_tel_for-#{@customer.jid}", tel, THIRTY_DAYS),
					REDIS.setex(
						"pending_plan_for-#{customer_id}",
						@customer.plan_name,
						THIRTY_DAYS
					)
				])
			end


@@ 458,6 453,7 @@ class Registration
		def customer_active_tel_purchased
			@customer.register!(@tel).catch(&method(:raise_setup_error)).then {
				EMPromise.all([
					REDIS.del("pending_tel_for-#{@customer.jid}"),
					REDIS.set("catapult_fwd-#{@tel}", cheogram_sip_addr),
					@customer.fwd_timeout = 25 # ~5 seconds / ring, 5 rings
				])

M test/test_registration.rb => test/test_registration.rb +5 -0
@@ 569,6 569,11 @@ class RegistrationTest < Minitest::Test
					"sip:test%40example.net@sip.cheogram.com"
				]
			)
			Registration::Finish::REDIS.expect(
				:del,
				nil,
				["pending_tel_for-test@example.net"]
			)
			BackendSgx::REDIS.expect(
				:set,
				nil,