~singpolyma/sgx-jmp

b1c4110caf56116e790a6a93a45ccf9c2ba4ac9e — Stephen Paul Weber 1 year, 11 months ago 982324b
Block voice calls when account is expired

Allow for "transitional" (no plan) users for now, because we still have a bunch
of those.
3 files changed, 38 insertions(+), 0 deletions(-)

M lib/call_attempt.rb
A views/inbound/expired.slim
A views/outbound/expired.slim
M lib/call_attempt.rb => lib/call_attempt.rb +32 -0
@@ 66,6 66,38 @@ class CallAttempt
		as_json.to_json(*args)
	end

	class Expired
		CallAttempt.register do |customer:, direction:, **|
			new(direction: direction) if customer.plan_name && !customer.active?
		end

		value_semantics do
			direction Either(:inbound, :outbound)
		end

		def view
			"#{direction}/expired"
		end

		def tts
			TTSTemplate.new(view).tts(self)
		end

		def to_render
			[view]
		end

		def create_call(*); end

		def as_json(*)
			{ tts: tts }
		end

		def to_json(*args)
			as_json.to_json(*args)
		end
	end

	class Unsupported
		CallAttempt.register do |supported:, direction:, **|
			new(direction: direction) unless supported

A views/inbound/expired.slim => views/inbound/expired.slim +3 -0
@@ 0,0 1,3 @@
doctype xml
Response
	Hangup /

A views/outbound/expired.slim => views/outbound/expired.slim +3 -0
@@ 0,0 1,3 @@
doctype xml
Response
	SpeakSentence Your account is expired, please top up soon to keep your number.