Add a note when billing account

Stephen Paul Weber created

Change summary

lib/bill_plan_command.rb  |  2 +-
lib/customer_plan.rb      | 13 +++++++------
lib/registration.rb       |  2 +-
test/test_registration.rb |  2 +-
4 files changed, 10 insertions(+), 9 deletions(-)

Detailed changes

lib/bill_plan_command.rb 🔗

@@ -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"

lib/customer_plan.rb 🔗

@@ -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
 

lib/registration.rb 🔗

@@ -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

test/test_registration.rb 🔗

@@ -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),