Skip to content

Commit 89ef273

Browse files
horghclaude
andcommitted
Add method enum field to Payment component
Add new method field to Payment component with 10 payment method values (bank_debit, bank_redirect, bank_transfer, buy_now_pay_later, card, crypto, digital_wallet, gift_card, real_time_payment, rewards) to specify the payment method associated with the transaction. Includes comprehensive test coverage and documentation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 43bfc71 commit 89ef273

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Added the input `/event/party`. This is the party submitting the
1111
transaction. You may provide this using the `party` attribute on
1212
`Minfraud::Components::Event`.
13+
* Added the input `/payment/method`. This is the payment method associated
14+
with the transaction. You may provide this using the `method` attribute
15+
on `Minfraud::Components::Payment`.
1316

1417
## v2.8.0 (2025-05-23)
1518

lib/minfraud/components/payment.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ class Payment < Base
99
include ::Minfraud::Enum
1010
include Minfraud::Validates
1111

12+
# The payment method associated with the transaction. This must be one of
13+
# +:bank_debit+, +:bank_redirect+, +:bank_transfer+, +:buy_now_pay_later+,
14+
# +:card+, +:crypto+, +:digital_wallet+, +:gift_card+,
15+
# +:real_time_payment+, or +:rewards+.
16+
#
17+
# @!attribute method
18+
#
19+
# @return [Symbol, nil]
20+
enum_accessor :method,
21+
%i[
22+
bank_debit
23+
bank_redirect
24+
bank_transfer
25+
buy_now_pay_later
26+
card
27+
crypto
28+
digital_wallet
29+
gift_card
30+
real_time_payment
31+
rewards
32+
]
33+
1234
# The payment processor used for the transaction. The value is one
1335
# listed as a valid value, as a symbol.
1436
#
@@ -196,6 +218,7 @@ class Payment < Base
196218
def initialize(params = {})
197219
@was_authorized = params[:was_authorized]
198220
@decline_code = params[:decline_code]
221+
self.method = params[:method]
199222
self.processor = params[:processor]
200223

201224
validate

spec/components/payment_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe Minfraud::Components::Payment do
6+
describe '#initialize' do
7+
context 'with an invalid processor' do
8+
it 'raises an exception' do
9+
expect do
10+
described_class.new({ processor: :invalid_processor })
11+
end.to raise_exception(Minfraud::NotEnumValueError)
12+
end
13+
end
14+
15+
context 'with an invalid method' do
16+
it 'raises an exception' do
17+
expect do
18+
described_class.new({ method: :invalid_method })
19+
end.to raise_exception(Minfraud::NotEnumValueError)
20+
end
21+
end
22+
end
23+
24+
describe 'validation' do
25+
before do
26+
Minfraud.configure { |c| c.enable_validation = 1 }
27+
end
28+
29+
it 'does not raise an exception for valid values' do
30+
described_class.new(
31+
processor: :stripe,
32+
method: :card,
33+
was_authorized: true,
34+
decline_code: 'insufficient_funds',
35+
)
36+
end
37+
38+
it 'accepts bank_debit as a valid method' do
39+
described_class.new(
40+
method: :bank_debit,
41+
)
42+
end
43+
44+
it 'accepts digital_wallet as a valid method' do
45+
described_class.new(
46+
method: :digital_wallet,
47+
)
48+
end
49+
50+
it 'accepts buy_now_pay_later as a valid method' do
51+
described_class.new(
52+
method: :buy_now_pay_later,
53+
)
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)