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"