Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ CHANGELOG
------------------

* Added `securepay` to the payment processor validation.
* Added `credit_application` and `fund_transfer` to event type validation.
* Added the input `/event/party`. This is the party submitting the
transaction.
* Added the input `/payment/method`. This is the payment method associated
with the transaction.

3.3.0 (2025-05-23)
------------------
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ $request = $mf->withDevice(
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
acceptLanguage: 'en-US,en;q=0.8'
)->withEvent(
party: 'customer',
transactionId: 'txn3134133',
shopId: 's2123',
time: '2012-04-12T23:20:50+00:00',
Expand Down Expand Up @@ -190,6 +191,7 @@ $request = $mf->withDevice(
phoneCountryCode: '1',
deliverySpeed: 'same_day'
)->withPayment(
method: 'card',
processor: 'stripe',
wasAuthorized: false,
declineCode: 'invalid number'
Expand Down
49 changes: 49 additions & 0 deletions src/MinFraud.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,19 @@ public function withDevice(
* are:
* - `account_creation`
* - `account_login`
* - `credit_application`
* - `email_change`
* - `fund_transfer`
* - `password_reset`
* - `payout_change`
* - `purchase`
* - `recurring_purchase`
* - `referral`
* - `survey`
* @param string|null $party The party submitting the transaction. The valid values
* are:
* - `agent`
* - `customer`
*
* @return MinFraud A new immutable MinFraud object. This object is a clone of
* the original with additional data.
Expand All @@ -317,13 +323,15 @@ public function withEvent(
?string $time = null,
?string $transactionId = null,
?string $type = null,
?string $party = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$party = $this->remove($values, 'party');
$shopId = $this->remove($values, 'shop_id');
$time = $this->remove($values, 'time');
$transactionId = $this->remove($values, 'transaction_id');
Expand All @@ -332,6 +340,13 @@ public function withEvent(
$this->verifyEmpty($values);
}

if ($party !== null) {
if (!\in_array($party, ['agent', 'customer'], true)) {
$this->maybeThrowInvalidInputException("$party is not a valid party");
}
$values['party'] = $party;
}

if ($shopId !== null) {
$values['shop_id'] = $shopId;
}
Expand All @@ -354,7 +369,9 @@ public function withEvent(
if (!\in_array($type, [
'account_creation',
'account_login',
'credit_application',
'email_change',
'fund_transfer',
'password_reset',
'payout_change',
'purchase',
Expand Down Expand Up @@ -753,6 +770,18 @@ public function withShipping(
* @param bool|null $wasAuthorized The authorization outcome from the payment
* processor. If the transaction has not yet been
* approved or denied, do not include this field.
* @param string|null $method The payment method associated with the transaction.
* The valid values are:
* - `bank_debit`
* - `bank_redirect`
* - `bank_transfer`
* - `buy_now_pay_later`
* - `card`
* - `crypto`
* - `digital_wallet`
* - `gift_card`
* - `real_time_payment`
* - `rewards`
*
* @return MinFraud A new immutable MinFraud object. This object is
* a clone of the original with additional data.
Expand All @@ -762,6 +791,7 @@ public function withPayment(
?string $declineCode = null,
?string $processor = null,
?bool $wasAuthorized = null,
?string $method = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
Expand All @@ -771,6 +801,7 @@ public function withPayment(
}

$declineCode = $this->remove($values, 'decline_code');
$method = $this->remove($values, 'method');
$processor = $this->remove($values, 'processor');
$wasAuthorized = $this->remove($values, 'was_authorized', ['boolean']);

Expand All @@ -781,6 +812,24 @@ public function withPayment(
$values['decline_code'] = $declineCode;
}

if ($method !== null) {
if (!\in_array($method, [
'bank_debit',
'bank_redirect',
'bank_transfer',
'buy_now_pay_later',
'card',
'crypto',
'digital_wallet',
'gift_card',
'real_time_payment',
'rewards',
], true)) {
$this->maybeThrowInvalidInputException("$method is not a valid payment method");
}
$values['method'] = $method;
}

if ($processor !== null) {
if (!\in_array($processor, [
'adyen',
Expand Down
78 changes: 78 additions & 0 deletions tests/MaxMind/Test/MinFraudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function testFullInsightsRequestUsingNamedArgs(string $class, string $ser
domain: 'maxmind.com'
)
->withEvent(
party: 'customer',
transactionId: 'txn3134133',
shopId: 's2123',
time: '2014-04-12T23:20:50+00:00',
Expand All @@ -152,6 +153,7 @@ public function testFullInsightsRequestUsingNamedArgs(string $class, string $ser
referrerUri: 'http://www.amazon.com/'
)
->withPayment(
method: 'card',
processor: 'stripe',
wasAuthorized: false,
declineCode: 'invalid number'
Expand Down Expand Up @@ -1102,7 +1104,9 @@ public static function goodEventTypes(): array
return [
['account_creation'],
['account_login'],
['credit_application'],
['email_change'],
['fund_transfer'],
['password_reset'],
['payout_change'],
['purchase'],
Expand All @@ -1123,6 +1127,39 @@ public function testBadEventType(): void
)->withEvent(['type' => 'unknown']);
}

/**
* @dataProvider goodEventParties
*/
public function testGoodEventParty(string $good): void
{
$this->createMinFraudRequestWithFullResponse(
'insights',
0
)->withEvent(['party' => $good]);
}

/**
* @return array<list<string>>
*/
public static function goodEventParties(): array
{
return [
['agent'],
['customer'],
];
}

public function testBadEventParty(): void
{
$this->expectException(InvalidInputException::class);
$this->expectExceptionMessage('valid party');

$this->createMinFraudRequestWithFullResponse(
'insights',
0
)->withEvent(['party' => 'unknown']);
}

/**
* @dataProvider badCurrency
*/
Expand Down Expand Up @@ -1186,6 +1223,47 @@ public function testBadPaymentProcessor(): void
)->withPayment(['processor' => 'unknown']);
}

/**
* @dataProvider goodPaymentMethods
*/
public function testGoodPaymentMethod(string $good): void
{
$this->createMinFraudRequestWithFullResponse(
'insights',
0
)->withPayment(['method' => $good]);
}

/**
* @return array<list<string>>
*/
public static function goodPaymentMethods(): array
{
return [
['bank_debit'],
['bank_redirect'],
['bank_transfer'],
['buy_now_pay_later'],
['card'],
['crypto'],
['digital_wallet'],
['gift_card'],
['real_time_payment'],
['rewards'],
];
}

public function testBadPaymentMethod(): void
{
$this->expectException(InvalidInputException::class);
$this->expectExceptionMessage('valid payment method');

$this->createMinFraudRequestWithFullResponse(
'insights',
0
)->withPayment(['method' => 'unknown']);
}

/**
* @dataProvider validAmounts
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/data/minfraud/full-request.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"event": {
"party": "customer",
"transaction_id": "txn3134133",
"shop_id": "s2123",
"time": "2014-04-12T23:20:50+00:00",
Expand Down Expand Up @@ -41,6 +42,7 @@
"delivery_speed": "same_day"
},
"payment": {
"method": "card",
"processor": "stripe",
"was_authorized": false,
"decline_code": "invalid number"
Expand Down
Loading