diff --git a/lib/pay_zen/service.rb b/lib/pay_zen/service.rb index 7e3938060..4f2dfbac6 100644 --- a/lib/pay_zen/service.rb +++ b/lib/pay_zen/service.rb @@ -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 diff --git a/test/lib/pay_zen/service_test.rb b/test/lib/pay_zen/service_test.rb index 52ce46349..94decb0cd 100644 --- a/test/lib/pay_zen/service_test.rb +++ b/test/lib/pay_zen/service_test.rb @@ -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 \ No newline at end of file