1# frozen_string_literal: true
2
3require_relative "./paypal_done"
4
5class MigrateBilling
6 def initialize(customer, finish: PaypalDone)
7 @customer = customer
8 @finish = finish
9 end
10
11 def parse(iq)
12 plan_name = iq.form.field("plan_name").value.to_s
13 (@customer = @customer.with_plan(plan_name)).save_plan!.then {
14 Registration::Payment.for(
15 iq, @customer,
16 OpenStruct.new(price: 0, to_s: @customer.registered?.phone),
17 finish: @finish
18 )
19 }.then(&:write)
20 end
21
22 def msg
23 "#{@customer.customer_id} migrated to #{@customer.currency}"
24 end
25
26 def write
27 Command.reply(&method(:form)).then(&method(:parse)).catch_only(
28 Command::Execution::FinalStanza
29 ) do |s|
30 BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
31 BLATHER.say(CONFIG[:notify_admin], msg, :groupchat)
32 EMPromise.reject(s)
33 end
34 end
35
36protected
37
38 def form(stanza)
39 stanza.allowed_actions = [:next]
40 stanza.command << FormTemplate.render("migrate_billing")
41 end
42end