Form to configure monthly overage limit

Stephen Paul Weber created

Change summary

forms/plan_settings.rb | 22 ++++++++++++++++++++++
sgx_jmp.rb             | 18 ++++++++++++++++++
2 files changed, 40 insertions(+)

Detailed changes

forms/plan_settings.rb 🔗

@@ -0,0 +1,22 @@
+form!
+
+title "Plan Settings"
+
+instructions(
+	"Your plan includes #{@customer.message_limit} and " \
+	"#{@customer.minute_limit}.  JMP will always prompt for your explicit " \
+	"consent before allowing any action which would incur more overage in a " \
+	"calendar month than your configured limit below.\n\n" \
+	"JMP is not yet billing for overages, but will be soon."
+)
+
+field(
+	var: "monthly_overage_limit",
+	type: "text-single",
+	datatype: "xs:integer",
+	label: "Dollars of overage to allow each month",
+	description:
+		"0 means you will never be automatically charged more " \
+		"than your monthly fee",
+	value: @customer.monthly_overage_limit.to_s
+)

sgx_jmp.rb 🔗

@@ -577,6 +577,24 @@ Command.new(
 	end
 }.register(self).then(&CommandList.method(:register))
 
+Command.new(
+	"plan settings",
+	"Manage your plan, including overage limits",
+	list_for: ->(customer:, **) { !!customer&.currency }
+) {
+	Command.customer.then do |customer|
+		Command.reply { |reply|
+			reply.allowed_actions = [:next]
+			reply.command << FormTemplate.render("plan_settings", customer: customer)
+		}.then { |iq|
+			Command.execution.customer_repo.put_monthly_overage_limit(
+				customer,
+				iq.form.field("monthly_overage_limit")&.value.to_i
+			)
+		}.then { Command.finish("Configuration saved!") }
+	end
+}.register(self).then(&CommandList.method(:register))
+
 Command.new(
 	"referral codes",
 	"Refer a friend for free credit"