From 07575ad9419e00ddd354e0ab404c88adc5358176 Mon Sep 17 00:00:00 2001 From: Christopher Vollick <0@psycoti.ca> Date: Wed, 14 Dec 2022 18:21:51 -0500 Subject: [PATCH] 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. --- forms/lnp_canada.rb | 12 ++++++++++++ lib/port_in_order.rb | 44 +++++++++++++++++++++++++++++++++++++++++++- sgx_jmp.rb | 22 +++++++++------------- 3 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 forms/lnp_canada.rb diff --git a/forms/lnp_canada.rb b/forms/lnp_canada.rb new file mode 100644 index 0000000000000000000000000000000000000000..76d061156939ef800dd8d0bb4fb667fb25827b64 --- /dev/null +++ b/forms/lnp_canada.rb @@ -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" +) diff --git a/lib/port_in_order.rb b/lib/port_in_order.rb index bbbe31fbfb678010796b13e56ecbdd52781d0077..5030fc0e621c7223dab086e1d2c699288ba9a63c 100644 --- a/lib/port_in_order.rb +++ b/lib/port_in_order.rb @@ -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 diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 9bcfebbf260d1b664a6d99096a7b29bf9f7b70bf..7b6a6db32a35fae716013fc6422f5bd5228f1d3b 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -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"