No more legacy session for BTC

Stephen Paul Weber created

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.

Change summary

lib/registration.rb       | 20 ++++++++------------
test/test_registration.rb |  5 +++++
2 files changed, 13 insertions(+), 12 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -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
 				])

test/test_registration.rb 🔗

@@ -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,