From b1c4110caf56116e790a6a93a45ccf9c2ba4ac9e Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 26 Apr 2022 13:21:04 -0500 Subject: [PATCH] Block voice calls when account is expired Allow for "transitional" (no plan) users for now, because we still have a bunch of those. --- lib/call_attempt.rb | 32 ++++++++++++++++++++++++++++++++ views/inbound/expired.slim | 3 +++ views/outbound/expired.slim | 3 +++ 3 files changed, 38 insertions(+) create mode 100644 views/inbound/expired.slim create mode 100644 views/outbound/expired.slim diff --git a/lib/call_attempt.rb b/lib/call_attempt.rb index 782d4424b59ba6de72f9151f4273600bc7b6d91b..072a5c52eac84feaa15e6499d0b22ddab07ea32b 100644 --- a/lib/call_attempt.rb +++ b/lib/call_attempt.rb @@ -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 diff --git a/views/inbound/expired.slim b/views/inbound/expired.slim new file mode 100644 index 0000000000000000000000000000000000000000..68e146def972c111d1df3a816975dd7482678fb4 --- /dev/null +++ b/views/inbound/expired.slim @@ -0,0 +1,3 @@ +doctype xml +Response + Hangup / diff --git a/views/outbound/expired.slim b/views/outbound/expired.slim new file mode 100644 index 0000000000000000000000000000000000000000..000718004f42ea15dfd69e6e9a8db4faefa9abdb --- /dev/null +++ b/views/outbound/expired.slim @@ -0,0 +1,3 @@ +doctype xml +Response + SpeakSentence Your account is expired, please top up soon to keep your number.