Allow custom settled after time for tx

Stephen Paul Weber created

Change summary

lib/transaction.rb | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

Detailed changes

lib/transaction.rb 🔗

@@ -1,11 +1,12 @@
 # frozen_string_literal: true
 
 class Transaction
-	def initialize(customer_id, id, amount, note)
+	def initialize(customer_id, id, amount, note, settled_after: Time.now)
 		@customer_id = customer_id
 		@id = id
 		@amount = amount
 		@note = note
+		@after = settled_after
 	end
 
 	def bonus
@@ -33,12 +34,12 @@ class Transaction
 	end
 
 	def save
-		args = [@customer_id, @id, @amount, @note]
+		args = [@customer_id, @id, @amount, @note, @after]
 		DB.exec_params(<<-SQL, args).cmd_tuples.positive?
 			INSERT INTO transactions
 				(customer_id, transaction_id, settled_after, amount, note)
 			VALUES
-				($1, $2, LOCALTIMESTAMP, $3, $4)
+				($1, $2, $5, $3, $4)
 			ON CONFLICT (transaction_id) DO NOTHING
 		SQL
 	end