~singpolyma/sgx-jmp

75658ba14b40d551488dae800e9a7d2bfeb239a8 — Stephen Paul Weber a month ago 028e7a1
Use FormTemplate for activation form
M .rubocop.yml => .rubocop.yml +1 -1
@@ 122,7 122,7 @@ Style/FormatStringToken:

Style/FrozenStringLiteralComment:
  Exclude:
    - forms/*
    - forms/**/*.rb

Naming/AccessorMethodName:
  Enabled: false

A forms/registration/activate.rb => forms/registration/activate.rb +36 -0
@@ 0,0 1,36 @@
form!
title "Activate JMP"

center = " (#{@rate_center})" if @rate_center
instructions <<~I
	You've selected #{@tel}#{center} as your JMP number.
	To activate your account, you can either deposit $#{CONFIG[:activation_amount]} to your balance or enter your invite code if you have one.
	(If you'd like to pay in a cryptocurrency other than Bitcoin, currently we recommend using a service like simpleswap.io, morphtoken.com, changenow.io, or godex.io. Manual payment via Bitcoin Cash is also available if you contact support.)
I

field(
	var: "activation_method",
	type: "list-single",
	label: "Activate using",
	required: true,
	options: [
		{
			value: "credit_card",
			label: "Credit Card"
		},
		{
			value: "bitcoin",
			label: "Bitcoin"
		},
		{
			value: "code",
			label: "Invite Code"
		},
		{
			value: "mail",
			label: "Mail or eTransfer"
		}
	]
)

instance_eval File.read("#{__dir__}/plan_name.rb")

A forms/registration/plan_name.rb => forms/registration/plan_name.rb +16 -0
@@ 0,0 1,16 @@
field(
	var: "plan_name",
	type: "list-single",
	label: "What currency should your account balance be in?",
	required: true,
	options: [
		{
			value: "cad_beta_unlimited-v20210223",
			label: "Canadian Dollars"
		},
		{
			value: "usd_beta_unlimited-v20210223",
			label: "United States Dollars"
		}
	]
)

M lib/registration.rb => lib/registration.rb +14 -72
@@ 48,85 48,27 @@ class Registration

		attr_reader :customer, :tel

		FORM_FIELDS = [
			{
				var: "activation_method",
				type: "list-single",
				label: "Activate using",
				required: true,
				options: [
					{
						value: "credit_card",
						label: "Credit Card"
					},
					{
						value: "bitcoin",
						label: "Bitcoin"
					},
					{
						value: "code",
						label: "Invite Code"
					},
					{
						value: "mail",
						label: "Mail or eTransfer"
					}
				]
			},
			{
				var: "plan_name",
				type: "list-single",
				label: "What currency should your account balance be in?",
				required: true,
				options: [
					{
						value: "cad_beta_unlimited-v20210223",
						label: "Canadian Dollars"
					},
					{
						value: "usd_beta_unlimited-v20210223",
						label: "United States Dollars"
					}
				]
			}
		].freeze

		ACTIVATE_INSTRUCTION =
			"To activate your account, you can either deposit " \
			"$#{CONFIG[:activation_amount]} to your balance or enter " \
			"your invite code if you have one."

		CRYPTOCURRENCY_INSTRUCTION =
			"(If you'd like to pay in a cryptocurrency other than " \
			"Bitcoin, currently we recommend using a service like " \
			"simpleswap.io, morphtoken.com, changenow.io, or godex.io. " \
			"Manual payment via Bitcoin Cash is also available if you " \
			"contact support.)"

		def add_instructions(form, center)
			center = " (#{center})" if center
			[
				"You've selected #{tel}#{center} as your JMP number",
				ACTIVATE_INSTRUCTION,
				CRYPTOCURRENCY_INSTRUCTION
			].each do |txt|
				form << Blather::XMPPNode.new(:instructions, form.document).tap { |i|
					i << txt
				}
			end
		def form(center)
			FormTemplate.render(
				"registration/activate",
				tel: tel,
				rate_center: center
			)
		end

		def write
			rate_center.then { |center|
				Command.reply do |reply|
					reply.allowed_actions = [:next]
					form = reply.form
					form.type = :form
					form.title = "Activate JMP"
					add_instructions(form, center)
					form.fields = FORM_FIELDS
					reply.command << form(center)
				end
			}.then { |iq| Payment.for(iq, customer, tel) }.then(&:write)
			}.then(&method(:next_step))
		end

		def next_step(iq)
			EMPromise.resolve(nil).then {
				Payment.for(iq, customer, tel)
			}.then(&:write)
		end

	protected

M test/test_registration.rb => test/test_registration.rb +2 -2
@@ 100,8 100,8 @@ class RegistrationTest < Minitest::Test
				[Matching.new do |iq|
					assert_equal :form, iq.form.type
					assert_equal(
						"You've selected +15555550000 (FA, KE) as your JMP number",
						iq.form.instructions
						"You've selected +15555550000 (FA, KE) as your JMP number.",
						iq.form.instructions.lines.first.chomp
					)
				end]
			)