~singpolyma/sgx-jmp

07575ad9419e00ddd354e0ab404c88adc5358176 — Christopher Vollick 1 year, 6 months ago 94298f5
Take in Carrier if Port is Canadian

Canadian ports need this extra info to port them in. Up until now I've
been messaging people manually to ask for it, but that adds a delay to
the porting process since I can't move forwards until they've told me,
and it may be hours between when they fill out the form and when I'm
processing it.

So this will just ask for all the data upfront, meaning I can fully
process them right away.
3 files changed, 64 insertions(+), 14 deletions(-)

A forms/lnp_canada.rb
M lib/port_in_order.rb
M sgx_jmp.rb
A forms/lnp_canada.rb => forms/lnp_canada.rb +12 -0
@@ 0,0 1,12 @@
form!
title "Bring your own number to JMP"
instructions <<~I
	To port this number, we must know the name of the carrier you're porting away from.
I

field(
	var: "LosingCarrier",
	required: true,
	type: "text-single",
	label: "Name of losing carrier"
)

M lib/port_in_order.rb => lib/port_in_order.rb +43 -1
@@ 1,14 1,33 @@
# frozen_string_literal: true

class PortInOrder
	def initialize(params)
	using FormToH

	def self.parse(customer, form)
		params = form.to_h.slice(
			"BillingTelephoneNumber", "Subscriber", "WirelessInfo"
		)
		# If the zip has anything that's not a digit, assume Canada
		if params.dig("Subscriber", "ServiceAddress", "Zip") =~ /[^\d\s]/
			Canada.new(customer, params)
		else
			new(customer, params)
		end
	end

	def initialize(customer, params)
		@params = params
		@params["CustomerOrderId"] = customer.customer_id
		@params["SiteId"] = CONFIG[:bandwidth_site]
		@params["PeerId"] = CONFIG[:bandwidth_peer]
		@params["ProcessingStatus"] = "DRAFT"
		@params["Subscriber"]["SubscriberType"] ||= "RESIDENTIAL"
	end

	def customer_id
		@params["CustomerOrderId"]
	end

	def loa_authorizing_person
		"%s %s" % [
			@params.dig("Subscriber", "FirstName"),


@@ 26,4 45,27 @@ class PortInOrder
			}
		end
	end

	def message(order_id)
		url = "https://dashboard.bandwidth.com/portal/r/a/" \
		      "#{CONFIG[:creds][:account]}/orders/portIn/#{order_id}"
		"New port-in request for #{customer_id}: #{url}"
	end

	def complete_with
		EMPromise.resolve(self)
	end

	class Canada < PortInOrder
		def message(order_id)
			"#{super} (canadian port from #{@losing_carrier})"
		end

		def complete_with
			yield(FormTemplate.render("lnp_canada")).then { |form|
				@losing_carrier = form.field("LosingCarrier").value
				self
			}
		end
	end
end

M sgx_jmp.rb => sgx_jmp.rb +9 -13
@@ 728,27 728,23 @@ Command.new(
	"Port in your number from another carrier",
	list_for: ->(**) { true }
) {
	using FormToH

	EMPromise.all([
		Command.customer,
		Command.reply do |reply|
			reply.allowed_actions = [:next]
			reply.command << FormTemplate.render("lnp")
		end
	]).then do |(customer, iq)|
		order = PortInOrder.new(iq.form.to_h.slice(
			"BillingTelephoneNumber", "Subscriber", "WirelessInfo"
		).merge("CustomerOrderId" => customer.customer_id))
	]).then { |(customer, iq)|
		PortInOrder.parse(customer, iq.form).complete_with do |form|
			Command.reply { |reply|
				reply.allowed_actions = [:next]
				reply.command << form
			}.then(&:form)
		end
	}.then do |order|
		order_id = BandwidthIris::PortIn.create(order.to_h)[:order_id]
		url = "https://dashboard.bandwidth.com/portal/r/a/" \
		      "#{CONFIG[:creds][:account]}/orders/portIn/#{order_id}"
		BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
		BLATHER.say(
			CONFIG[:notify_admin],
			"New port-in request for #{customer.customer_id}: #{url}",
			:groupchat
		)
		BLATHER.say(CONFIG[:notify_admin], order.message(order_id), :groupchat)
		Command.finish(
			"Your port-in request has been accepted, " \
			"support will contact you with next steps"