From bb33b0c2259432328905781f64825ad5dc6a2a3d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Apr 2022 13:30:46 -0500 Subject: [PATCH] Add a note when billing account --- 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(-) diff --git a/lib/bill_plan_command.rb b/lib/bill_plan_command.rb index 81ede5f..79a72af 100644 --- a/lib/bill_plan_command.rb +++ b/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" diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index 2dbaf0c..f9f45b0 100644 --- a/lib/customer_plan.rb +++ b/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 diff --git a/lib/registration.rb b/lib/registration.rb index ca21c80..816e99c 100644 --- a/lib/registration.rb +++ b/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 diff --git a/test/test_registration.rb b/test/test_registration.rb index a6b8cc6..190daeb 100644 --- a/test/test_registration.rb +++ b/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), -- 2.45.2