Skip to content

Commit

Permalink
fix PayZen::Service#find_transaction_by_payment_schedule_item
Browse files Browse the repository at this point in the history
  • Loading branch information
nflorentin committed Dec 1, 2023
1 parent 038c7d8 commit 736e42f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pay_zen/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ def find_transaction_by_payment_schedule_item(transactions, payment_schedule_ite
due_date = payment_schedule_item.due_date.to_date

transactions.find do |tr|
expected_capture_date = Time.zone.parse(tr["transactionDetails"]["paymentMethodDetails"]["expectedCaptureDate"]).to_date
next unless tr["operationType"] == "DEBIT"

(tr["operationType"] == "DEBIT") && (expected_capture_date.between?(due_date - 1.day, due_date + 1.day))
expected_capture_date = Time.zone.parse(tr["transactionDetails"]["paymentMethodDetails"]["expectedCaptureDate"]).to_date
expected_capture_date.between?(due_date - 1.day, due_date + 1.day)
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/lib/pay_zen/service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@ def format_transaction(operation_type:, expected_capture_date:)
transactions = [format_transaction(operation_type: "CREDIT", expected_capture_date: expected_capture_date)]

assert_nil @service.find_transaction_by_payment_schedule_item(transactions, payment_schedule_item)

transactions = [format_transaction(operation_type: "VERIFICATION", expected_capture_date: nil)]

assert_nil @service.find_transaction_by_payment_schedule_item(transactions, payment_schedule_item)
end
end

0 comments on commit 736e42f

Please sign in to comment.