Skip to content

Commit 620ce06

Browse files
authored
Merge pull request #156 from maxmind/wstorey/eng-2870-eventparty-and-paymentmethod-minfraud-inputs-are-supported
Add /event/party, /payment/method, and new /event/type values
2 parents c84b8bf + 121854a commit 620ce06

File tree

6 files changed

+140
-3
lines changed

6 files changed

+140
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
* Added the processor `:securepay` to `Minfraud::Components::Payment`.
66
* Ruby 3.2+ is now required. If you're using Ruby 3.0 or 3.1, please use
77
version 2.8.0 of this gem.
8+
* Added `/event/type` values `:credit_application` and `:fund_transfer` to
9+
`Minfraud::Components::Event`.
10+
* Added the input `/event/party`. This is the party submitting the
11+
transaction. You may provide this using the `party` attribute on
12+
`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`.
816

917
## v2.8.0 (2025-05-23)
1018

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ assessment = Minfraud::Assessments.new(
8686
user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
8787
},
8888
event: {
89+
party: :customer,
8990
transaction_id: 'txn3134133',
9091
shop_id: 's2123',
9192
time: '2012-04-12T23:20:50+00:00',
@@ -127,6 +128,7 @@ assessment = Minfraud::Assessments.new(
127128
delivery_speed: :same_day,
128129
},
129130
payment: {
131+
method: :card,
130132
processor: :stripe,
131133
was_authorized: false,
132134
decline_code: 'invalid number',

lib/minfraud/components/event.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ class Event < Base
99
include ::Minfraud::Enum
1010
include Minfraud::Validates
1111

12+
# The party submitting the transaction. This must be one of +:agent+ or
13+
# +:customer+.
14+
#
15+
# @!attribute party
16+
#
17+
# @return [Symbol, nil]
18+
enum_accessor :party,
19+
%i[
20+
agent
21+
customer
22+
]
23+
1224
# Your internal ID for the transaction. MaxMind can use this to locate a
1325
# specific transaction in logs, and it will also show up in email alerts
1426
# and notifications from MaxMind to you. No specific format is required.
@@ -35,9 +47,10 @@ class Event < Base
3547
attr_accessor :time
3648

3749
# The type of event being scored. This must be one of
38-
# +:account_creation+, +:account_login+, +:email_change+,
39-
# +:password_reset+, +:payout_change+, +:purchase+,
40-
# +:recurring_purchase+, +:referral+, or +:survey+.
50+
# +:account_creation+, +:account_login+, +:credit_application+,
51+
# +:email_change+, +:fund_transfer+, +:password_reset+,
52+
# +:payout_change+, +:purchase+, +:recurring_purchase+, +:referral+,
53+
# or +:survey+.
4154
#
4255
# @!attribute type
4356
#
@@ -46,7 +59,9 @@ class Event < Base
4659
%i[
4760
account_creation
4861
account_login
62+
credit_application
4963
email_change
64+
fund_transfer
5065
password_reset
5166
payout_change
5267
purchase
@@ -58,6 +73,7 @@ class Event < Base
5873
# @param params [Hash] Hash of parameters. Each key/value should
5974
# correspond to one of the available attributes.
6075
def initialize(params = {})
76+
self.party = params[:party]
6177
@transaction_id = params[:transaction_id]
6278
@shop_id = params[:shop_id]
6379
@time = params[:time]

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/event_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
end.to raise_exception(Minfraud::NotEnumValueError)
1212
end
1313
end
14+
15+
context 'with an invalid party' do
16+
it 'raises an exception' do
17+
expect do
18+
described_class.new({ party: :invalid })
19+
end.to raise_exception(Minfraud::NotEnumValueError)
20+
end
21+
end
1422
end
1523

1624
describe 'validation' do
@@ -31,5 +39,29 @@
3139
time: '2020-08-28T14:00:00Z',
3240
)
3341
end
42+
43+
it 'accepts credit_application as a valid type' do
44+
described_class.new(
45+
type: :credit_application,
46+
)
47+
end
48+
49+
it 'accepts fund_transfer as a valid type' do
50+
described_class.new(
51+
type: :fund_transfer,
52+
)
53+
end
54+
55+
it 'accepts agent as a valid party' do
56+
described_class.new(
57+
party: :agent,
58+
)
59+
end
60+
61+
it 'accepts customer as a valid party' do
62+
described_class.new(
63+
party: :customer,
64+
)
65+
end
3466
end
3567
end

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)