~singpolyma/sgx-jmp

c92ea39bfda931534e014039d3afd4af56a59499 — Stephen Paul Weber 9 months ago 74b3ab7
Say what customer was affected
1 files changed, 9 insertions(+), 5 deletions(-)

M lib/bill_plan_command.rb
M lib/bill_plan_command.rb => lib/bill_plan_command.rb +9 -5
@@ 2,7 2,7 @@

class BillPlanCommand
	def self.for(customer)
		return ForUnregistered.new unless customer.registered?
		return ForUnregistered.new(customer) unless customer.registered?

		unless customer.balance > customer.monthly_price
			return ForLowBalance.new(customer)


@@ 19,7 19,7 @@ class BillPlanCommand
		@customer.bill_plan(note: "Renew account plan")
		Command.reply do |reply|
			reply.note_type = :info
			reply.note_text = "Customer billed"
			reply.note_text = "#{@customer.customer_id} billed"
		end
	end



@@ 30,12 30,12 @@ class BillPlanCommand

		def call
			LowBalance.for(@customer).then(&:notify!).then do |amount|
				return command_for(amount).call if amount&.positive?
				next command_for(amount).call if amount&.positive?

				notify_failure
				Command.reply do |reply|
					reply.note_type = :error
					reply.note_text = "Customer balance is too low"
					reply.note_text = "#{@customer.customer_id} balance is too low"
				end
			end
		end


@@ 59,10 59,14 @@ class BillPlanCommand
	end

	class ForUnregistered
		def initialize(customer)
			@customer = customer
		end

		def call
			Command.reply do |reply|
				reply.note_type = :error
				reply.note_text = "Customer is not registered"
				reply.note_text = "#{@customer.customer_id} is not registered"
			end
		end
	end