~singpolyma/sgx-jmp

42add6df0501466a6aebab88d03af2d91d680dd1 — Stephen Paul Weber 9 months ago a688701
Credit card transactions settle after 90 days, bills instantly
3 files changed, 20 insertions(+), 11 deletions(-)

M lib/customer_plan.rb
M lib/transaction.rb
M test/test_transaction.rb
M lib/customer_plan.rb => lib/customer_plan.rb +2 -2
@@ 104,8 104,8 @@ protected
		]
		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, settled_after, amount)
			VALUES ($1, $2, LOCALTIMESTAMP, LOCALTIMESTAMP, $3)
		SQL
	end


M lib/transaction.rb => lib/transaction.rb +15 -6
@@ 78,27 78,36 @@ class Transaction
		"$#{'%.2f' % amount}#{plus if bonus.positive?}"
	end

	def settled_after
		@created_at + (90 * 24 * 60 * 60)
	end

protected

	def insert_tx
		params = [@customer_id, @transaction_id, @created_at, @amount]
		params = [
			@customer_id, @transaction_id, @created_at, settled_after, @amount
		]
		DB.exec(<<~SQL, params)
			INSERT INTO transactions
				(customer_id, transaction_id, created_at, amount, note)
				(customer_id, transaction_id, created_at, settled_after, amount, note)
			VALUES
				($1, $2, $3, $4, 'Credit card payment')
				($1, $2, $3, $4, $5, 'Credit card payment')
		SQL
	end

	def insert_bonus
		return if bonus <= 0

		params = [@customer_id, "bonus_for_#{@transaction_id}", @created_at, bonus]
		params = [
			@customer_id, "bonus_for_#{@transaction_id}", @created_at,
			settled_after, bonus
		]
		DB.exec(<<~SQL, params)
			INSERT INTO transactions
				(customer_id, transaction_id, created_at, amount, note)
				(customer_id, transaction_id, created_at, settled_after, amount, note)
			VALUES
				($1, $2, $3, $4, 'Credit card payment bonus')
				($1, $2, $3, $4, $5, 'Credit card payment bonus')
		SQL
	end
end

M test/test_transaction.rb => test/test_transaction.rb +3 -3
@@ 96,7 96,7 @@ class TransactionTest < Minitest::Test
			EMPromise.resolve(nil),
			[
				String,
				["customer", "transaction", Time.at(0), 12]
				["customer", "transaction", Time.at(0), Time.at(7776000), 12]
			]
		)
		Transaction.new(FAKE_BRAINTREE_TRANSACTION).insert.sync


@@ 114,7 114,7 @@ class TransactionTest < Minitest::Test
			EMPromise.resolve(nil),
			[
				String,
				["customer", "transaction", Time.at(0), 100]
				["customer", "transaction", Time.at(0), Time.at(7776000), 100]
			]
		)
		Transaction::DB.expect(


@@ 122,7 122,7 @@ class TransactionTest < Minitest::Test
			EMPromise.resolve(nil),
			[
				String,
				["customer", "bonus_for_transaction", Time.at(0), 3]
				["customer", "bonus_for_transaction", Time.at(0), Time.at(7776000), 3]
			]
		)
		tx = FAKE_BRAINTREE_TRANSACTION.dup