~singpolyma/sgx-jmp

fa0e681aceda27d87f51b3ece750c1f17adf69e4 — Stephen Paul Weber 9 months ago a688701 + bb33b0c
Merge branch 'bill-with-note'

* bill-with-note:
  Add a note when billing account
4 files changed, 10 insertions(+), 9 deletions(-)

M lib/bill_plan_command.rb
M lib/customer_plan.rb
M lib/registration.rb
M test/test_registration.rb
M lib/bill_plan_command.rb => lib/bill_plan_command.rb +1 -1
@@ 16,7 16,7 @@ class BillPlanCommand
	end

	def call
		@customer.bill_plan
		@customer.bill_plan(note: "Renew account plan")
		Command.reply do |reply|
			reply.note_type = :info
			reply.note_text = "Customer billed"

M lib/customer_plan.rb => lib/customer_plan.rb +7 -6
@@ 59,10 59,10 @@ class CustomerPlan
		SQL
	end

	def bill_plan
	def bill_plan(note: nil)
		EM.promise_fiber do
			DB.transaction do
				charge_for_plan
				charge_for_plan(note)
				add_one_month_to_current_plan unless activate_plan_starting_now
			end
		end


@@ 96,16 96,17 @@ class CustomerPlan

protected

	def charge_for_plan
	def charge_for_plan(note)
		params = [
			@customer_id,
			"#{@customer_id}-bill-#{plan_name}-at-#{Time.now.to_i}",
			-@plan.monthly_price
			-@plan.monthly_price,
			note
		]
		DB.exec(<<~SQL, params)
			INSERT INTO transactions
				(customer_id, transaction_id, created_at, amount)
			VALUES ($1, $2, LOCALTIMESTAMP, $3)
				(customer_id, transaction_id, created_at, amount, note)
			VALUES ($1, $2, LOCALTIMESTAMP, $3, $4)
		SQL
	end


M lib/registration.rb => lib/registration.rb +1 -1
@@ 415,7 415,7 @@ class Registration
		end

		def write
			@customer.bill_plan.then do
			@customer.bill_plan(note: "Bill for first month").then do
				@finish.new(@customer, @tel).write
			end
		end

M test/test_registration.rb => test/test_registration.rb +1 -1
@@ 431,7 431,7 @@ class RegistrationTest < Minitest::Test
					assert_equal CONFIG[:activation_amount], amount
					assert_equal :test_default_method, payment_method
				end
				customer.expect(:bill_plan, nil)
				customer.expect(:bill_plan, nil, [{ note: "Bill for first month" }])
				Registration::Payment::CreditCard::Activate::Finish.expect(
					:new,
					OpenStruct.new(write: nil),