Skip to content

Commit df26ea7

Browse files
authored
Merge pull request #1326 from maxmind/nlogan/report-no-ip
Make IP address optional when reporting transactions
2 parents daceba0 + 3032091 commit df26ea7

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
7.0.0
5+
------------------
6+
7+
* **Breaking** Updated `TransactionReport` to make the `ipAddress` parameter
8+
optional. Now the `tag` and at least one of the following paramters must be
9+
supplied: `ipAddress`, `maxmindId`, `minfraudId`, `transactionId`.
10+
411
6.1.0 (2024-04-16)
512
------------------
613

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ of:
9090
MaxMind encourages the use of this API, as data received through this channel
9191
is continually used to improve the accuracy of our fraud detection algorithms.
9292

93-
To use the Report Transactions API, create a new `TransactionReport` object. An
94-
IP address and a valid tag are required key values. Additional key values may
95-
also be set, as documented below.
93+
To use the Report Transactions API, create a new `TransactionReport` object. A
94+
valid tag and at least one of the following are required parameters:
95+
IP address, maxmind ID, minfraud ID, or transaction ID. Additional key values
96+
may also be set, as documented below.
9697

9798
See the API documentation for more details.
9899

src/request/transaction-report.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,39 @@ describe('Device()', () => {
2525
expect(report).toThrowError('transactionReport.tag');
2626
});
2727

28-
it('constructs', () => {
28+
it('constructs with ipAddress', () => {
2929
expect(() => {
3030
new TransactionReport({
3131
ipAddress: '1.1.1.1',
3232
tag: Tag.CHARGEBACK,
3333
});
3434
}).not.toThrow();
3535
});
36+
37+
it('constructs with maxmindId', () => {
38+
expect(() => {
39+
new TransactionReport({
40+
maxmindId: '12345678',
41+
tag: Tag.CHARGEBACK,
42+
});
43+
}).not.toThrow();
44+
});
45+
46+
it('constructs with minfraudId', () => {
47+
expect(() => {
48+
new TransactionReport({
49+
minfraudId: '58fa38d8-4b87-458b-a22b-f00eda1aa20',
50+
tag: Tag.CHARGEBACK,
51+
});
52+
}).not.toThrow();
53+
});
54+
55+
it('constructs with transactionId', () => {
56+
expect(() => {
57+
new TransactionReport({
58+
minfraudId: 'abc123',
59+
tag: Tag.CHARGEBACK,
60+
});
61+
}).not.toThrow();
62+
});
3663
});

src/request/transaction-report.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ interface TransactionReportProps {
1010
*/
1111
chargebackCode?: string;
1212
/**
13-
* The IP address of the customer placing the order.
13+
* The IP address of the customer placing the order. This field is not
14+
* required if you provide at least one of the transaction's minfraudId,
15+
* maxmindId, or transactionId. You are encouraged to provide it, if
16+
* possible.
1417
*/
15-
ipAddress: string;
18+
ipAddress?: string;
1619
/**
1720
* A unique eight character string identifying a minFraud Standard or
1821
* Premium request. These IDs are returned in the maxmindID field of a
@@ -23,8 +26,9 @@ interface TransactionReportProps {
2326
/**
2427
* A UUID that identifies a minFraud Score, minFraud Insights, or minFraud
2528
* Factors request. This ID is returned at /id in the response. This field
26-
* is not required, but you are encouraged to provide it if the request was
27-
* made to one of these services.
29+
* is not required if you provide at least one of the transaction's ipAddress,
30+
* minfraudId, or transactionId. You are encouraged to provide
31+
* it, if possible.
2832
*/
2933
minfraudId?: string;
3034
/**
@@ -40,8 +44,8 @@ interface TransactionReportProps {
4044
tag: Tag;
4145
/**
4246
* The transaction ID you originally passed to minFraud. This field is not
43-
* required, but you are encouraged to provide it or the transaction’s
44-
* maxmindId or minfraudId.
47+
* required if you provide at least one of the transaction's ipAddress,
48+
* minfraudId, or maxmindId. You are encouraged to provide it, if possible.
4549
*/
4650
transactionId?: string;
4751
}
@@ -50,7 +54,7 @@ export default class TransactionReport {
5054
/** @inheritDoc TransactionReportProps.chargebackCode */
5155
public chargebackCode?: string;
5256
/** @inheritDoc TransactionReportProps.ipAddress */
53-
public ipAddress: string;
57+
public ipAddress?: string;
5458
/** @inheritDoc TransactionReportProps.maxmindId */
5559
public maxmindId?: string;
5660
/** @inheritDoc TransactionReportProps.minfraudId */
@@ -63,12 +67,26 @@ export default class TransactionReport {
6367
public transactionId?: string;
6468

6569
public constructor(transactionReport: TransactionReportProps) {
66-
if (isIP(transactionReport.ipAddress) === 0) {
70+
// Check if at least one identifier field is set
71+
if (
72+
!transactionReport.ipAddress &&
73+
!transactionReport.maxmindId &&
74+
!transactionReport.minfraudId &&
75+
!transactionReport.transactionId
76+
) {
6777
throw new ArgumentError(
68-
'`transactionReport.ipAddress` is an invalid IP address'
78+
'The report must contain at least one of the following fields: `ipAddress`, `maxmindId`, `minfraudId`, `transactionId`.'
6979
);
7080
}
7181

82+
if (transactionReport.ipAddress) {
83+
if (isIP(transactionReport.ipAddress) === 0) {
84+
throw new ArgumentError(
85+
'`transactionReport.ipAddress` is an invalid IP address'
86+
);
87+
}
88+
}
89+
7290
if (
7391
!transactionReport.tag ||
7492
!Object.values(Tag).includes(transactionReport.tag)

0 commit comments

Comments
 (0)