diff --git a/lib/bill_plan_command.rb b/lib/bill_plan_command.rb index 81ede5fe905522f9dd2f714080d3275486e5d0d8..79a72afca098a6ee8f806e1444772522235b86fe 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 2dbaf0cbda3418e5286791c3addbd48d3cbf373e..f9f45b0b165a82ba44c3a7e7676254322a1eb56d 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 ca21c8062c0bab1f2deb97cc0470baf36e5cfd41..816e99cd1c472a5bba218ad687e9b6b479380d38 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 a6b8cc6572bc4c0fd98bd4f79c9b21140e2a2f25..190daebb6f0d74eb2069c53c35b5013da3b08ae3 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),