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