~singpolyma/jmp-pay

1b7a0cbe80e149d585e14dcdcd4ffd9fb38ef511 — Stephen Paul Weber 8 months ago cda6284
Allow custom settled after time for tx
1 files changed, 4 insertions(+), 3 deletions(-)

M lib/transaction.rb
M lib/transaction.rb => lib/transaction.rb +4 -3
@@ 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