Skip to content

Commit 14ea30e

Browse files
horghclaude
andcommitted
Add party field to event with agent/customer values
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d0ae3cc commit 14ea30e

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ CHANGELOG
66

77
* Added `securepay` to the payment processor validation.
88
* Added `credit_application` and `fund_transfer` to event type validation.
9+
* Added the input `/event/party`. This is the party submitting the
10+
transaction.
911

1012
3.3.0 (2025-05-23)
1113
------------------

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ $request = $mf->withDevice(
154154
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
155155
acceptLanguage: 'en-US,en;q=0.8'
156156
)->withEvent(
157+
party: 'customer',
157158
transactionId: 'txn3134133',
158159
shopId: 's2123',
159160
time: '2012-04-12T23:20:50+00:00',

src/MinFraud.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ public function withDevice(
306306
* - `recurring_purchase`
307307
* - `referral`
308308
* - `survey`
309+
* @param string|null $party The party submitting the transaction. The valid values
310+
* are:
311+
* - `agent`
312+
* - `customer`
309313
*
310314
* @return MinFraud A new immutable MinFraud object. This object is a clone of
311315
* the original with additional data.
@@ -319,13 +323,15 @@ public function withEvent(
319323
?string $time = null,
320324
?string $transactionId = null,
321325
?string $type = null,
326+
?string $party = null,
322327
): self {
323328
if (\count($values) !== 0) {
324329
if (\func_num_args() !== 1) {
325330
throw new \InvalidArgumentException(
326331
'You may only provide the $values array or named arguments, not both.',
327332
);
328333
}
334+
$party = $this->remove($values, 'party');
329335
$shopId = $this->remove($values, 'shop_id');
330336
$time = $this->remove($values, 'time');
331337
$transactionId = $this->remove($values, 'transaction_id');
@@ -334,6 +340,13 @@ public function withEvent(
334340
$this->verifyEmpty($values);
335341
}
336342

343+
if ($party !== null) {
344+
if (!\in_array($party, ['agent', 'customer'], true)) {
345+
$this->maybeThrowInvalidInputException("$party is not a valid party");
346+
}
347+
$values['party'] = $party;
348+
}
349+
337350
if ($shopId !== null) {
338351
$values['shop_id'] = $shopId;
339352
}

tests/MaxMind/Test/MinFraudTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public function testFullInsightsRequestUsingNamedArgs(string $class, string $ser
136136
domain: 'maxmind.com'
137137
)
138138
->withEvent(
139+
party: 'customer',
139140
transactionId: 'txn3134133',
140141
shopId: 's2123',
141142
time: '2014-04-12T23:20:50+00:00',
@@ -1125,6 +1126,39 @@ public function testBadEventType(): void
11251126
)->withEvent(['type' => 'unknown']);
11261127
}
11271128

1129+
/**
1130+
* @dataProvider goodEventParties
1131+
*/
1132+
public function testGoodEventParty(string $good): void
1133+
{
1134+
$this->createMinFraudRequestWithFullResponse(
1135+
'insights',
1136+
0
1137+
)->withEvent(['party' => $good]);
1138+
}
1139+
1140+
/**
1141+
* @return array<list<string>>
1142+
*/
1143+
public static function goodEventParties(): array
1144+
{
1145+
return [
1146+
['agent'],
1147+
['customer'],
1148+
];
1149+
}
1150+
1151+
public function testBadEventParty(): void
1152+
{
1153+
$this->expectException(InvalidInputException::class);
1154+
$this->expectExceptionMessage('valid party');
1155+
1156+
$this->createMinFraudRequestWithFullResponse(
1157+
'insights',
1158+
0
1159+
)->withEvent(['party' => 'unknown']);
1160+
}
1161+
11281162
/**
11291163
* @dataProvider badCurrency
11301164
*/

tests/data/minfraud/full-request.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"event": {
3+
"party": "customer",
34
"transaction_id": "txn3134133",
45
"shop_id": "s2123",
56
"time": "2014-04-12T23:20:50+00:00",

0 commit comments

Comments
 (0)