Skip to content

Commit a0c9919

Browse files
oschwaldclaude
andcommitted
Update C# examples to use object initializer syntax
Change minFraud C# code samples to use object initializer syntax (e.g., `new Transaction { Device = ... }`) instead of constructor syntax with named parameters. This matches the style used in the official minfraud-api-dotnet README and is more idiomatic modern C#. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent d2dad83 commit a0c9919

File tree

2 files changed

+153
-143
lines changed

2 files changed

+153
-143
lines changed

content/minfraud/evaluate-a-transaction.md

Lines changed: 143 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -161,46 +161,50 @@ submit:
161161
{{< codeset >}}
162162

163163
```csharp
164-
var transaction = new Transaction(
165-
device: new Device(System.Net.IPAddress.Parse("1.1.1.1")),
166-
email:
167-
new Email(
168-
address: "[email protected]",
169-
domain: "maxmind.com"
170-
),
171-
billing:
172-
new Billing(
173-
address: "1 Billing Address St.",
174-
firstName: "First",
175-
lastName: "Last",
176-
company: "Company, Inc.",
177-
address2: "Unit 1",
178-
city: "Waltham",
179-
region: "MA",
180-
country: "US",
181-
postal: "02451",
182-
phoneNumber: "555-555-5555",
183-
phoneCountryCode: "1"
184-
),
185-
creditCard:
186-
new CreditCard(
187-
issuerIdNumber: "411111",
188-
),
189-
shipping:
190-
new Shipping(
191-
firstName: "First",
192-
lastName: "Last",
193-
company: "Company Inc.",
194-
address: "1 Shipping Address St.",
195-
address2: "Unit 1",
196-
city: "Waltham",
197-
region: "MA",
198-
country: "US",
199-
postal: "02451",
200-
phoneNumber: "555-555-5555",
201-
phoneCountryCode: "1",
202-
)
203-
);
164+
var transaction = new Transaction
165+
{
166+
Device = new Device
167+
{
168+
IPAddress = System.Net.IPAddress.Parse("1.1.1.1")
169+
},
170+
Email = new Email
171+
{
172+
Address = "[email protected]",
173+
Domain = "maxmind.com"
174+
},
175+
Billing = new Billing
176+
{
177+
FirstName = "First",
178+
LastName = "Last",
179+
Company = "Company, Inc.",
180+
Address = "1 Billing Address St.",
181+
Address2 = "Unit 1",
182+
City = "Waltham",
183+
Region = "MA",
184+
Country = "US",
185+
Postal = "02451",
186+
PhoneNumber = "555-555-5555",
187+
PhoneCountryCode = "1"
188+
},
189+
CreditCard = new CreditCard
190+
{
191+
IssuerIdNumber = "411111"
192+
},
193+
Shipping = new Shipping
194+
{
195+
FirstName = "First",
196+
LastName = "Last",
197+
Company = "Company Inc.",
198+
Address = "1 Shipping Address St.",
199+
Address2 = "Unit 1",
200+
City = "Waltham",
201+
Region = "MA",
202+
Country = "US",
203+
Postal = "02451",
204+
PhoneNumber = "555-555-5555",
205+
PhoneCountryCode = "1"
206+
}
207+
};
204208
```
205209

206210
```java
@@ -519,6 +523,7 @@ using MaxMind.MinFraud;
519523
using MaxMind.MinFraud.Request;
520524
using System;
521525
using System.Collections.Generic;
526+
using System.Net;
522527
using System.Threading.Tasks;
523528

524529
public class MinFraudExample
@@ -530,109 +535,112 @@ public class MinFraudExample
530535

531536
static public async Task MinFraudAsync()
532537
{
533-
var transaction = new Transaction(
534-
device: new Device(System.Net.IPAddress.Parse("1.1.1.1"),
535-
userAgent:
536-
"Mozilla/5.0 (X11; Linux x86_64)",
537-
acceptLanguage: "en-US,en;q=0.8",
538-
sessionAge: 3600,
539-
sessionId: "a333a4e127f880d8820e56a66f40717c"
540-
),
541-
userEvent:
542-
new Event
543-
(
544-
transactionId: "txn3134133",
545-
shopId: "s2123",
546-
time: new DateTimeOffset(2014, 4, 12, 23, 20, 50, 52, new TimeSpan(0)),
547-
type: EventType.Purchase
548-
),
549-
account:
550-
new Account(
551-
userId: "3132",
552-
username: "fred"
553-
),
554-
email:
555-
new Email(
556-
address: "[email protected]",
557-
domain: "maxmind.com"
558-
),
559-
billing:
560-
new Billing(
561-
address: "1 Billing Address St.",
562-
firstName: "First",
563-
lastName: "Last",
564-
company: "Company, Inc.",
565-
address2: "Unit 1",
566-
city: "Waltham",
567-
region: "MA",
568-
country: "US",
569-
postal: "02451",
570-
phoneNumber: "555-555-5555",
571-
phoneCountryCode: "1"
572-
),
573-
shipping:
574-
new Shipping(
575-
firstName: "First",
576-
lastName: "Last",
577-
company: "Company Inc.",
578-
address: "1 Shipping Address St.",
579-
address2: "Unit 1",
580-
city: "Waltham",
581-
region: "MA",
582-
country: "US",
583-
postal: "02451",
584-
phoneNumber: "555-555-5555",
585-
phoneCountryCode: "1",
586-
deliverySpeed: ShippingDeliverySpeed.SameDay
587-
),
588-
payment:
589-
new Payment(
590-
processor: PaymentProcessor.Stripe,
591-
wasAuthorized: false,
592-
declineCode: "invalid number"
593-
),
594-
creditCard:
595-
new CreditCard(
596-
issuerIdNumber: "411111",
597-
bankName: "Test Bank",
598-
bankPhoneCountryCode: "1",
599-
bankPhoneNumber: "555-555-5555",
600-
avsResult: 'Y',
601-
cvvResult: 'N',
602-
last4Digits: "1234"
603-
),
604-
order:
605-
new Order(
606-
amount: 323.21m,
607-
currency: "USD",
608-
discountCode: "FIRST",
609-
affiliateId: "af12",
610-
subaffiliateId: "saf42",
611-
referrerUri: new Uri("http://www.amazon.com/")
612-
),
613-
shoppingCart: new List<ShoppingCartItem>
538+
var transaction = new Transaction
539+
{
540+
Device = new Device
541+
{
542+
IPAddress = IPAddress.Parse("1.1.1.1"),
543+
UserAgent = "Mozilla/5.0 (X11; Linux x86_64)",
544+
AcceptLanguage = "en-US,en;q=0.8",
545+
SessionAge = 3600,
546+
SessionId = "a333a4e127f880d8820e56a66f40717c"
547+
},
548+
Event = new Event
549+
{
550+
TransactionId = "txn3134133",
551+
ShopId = "s2123",
552+
Time = new DateTimeOffset(2014, 4, 12, 23, 20, 50, 52, new TimeSpan(0)),
553+
Type = EventType.Purchase
554+
},
555+
Account = new Account
556+
{
557+
UserId = "3132",
558+
Username = "fred"
559+
},
560+
Email = new Email
561+
{
562+
Address = "[email protected]",
563+
Domain = "maxmind.com"
564+
},
565+
Billing = new Billing
566+
{
567+
FirstName = "First",
568+
LastName = "Last",
569+
Company = "Company, Inc.",
570+
Address = "1 Billing Address St.",
571+
Address2 = "Unit 1",
572+
City = "Waltham",
573+
Region = "MA",
574+
Country = "US",
575+
Postal = "02451",
576+
PhoneNumber = "555-555-5555",
577+
PhoneCountryCode = "1"
578+
},
579+
Shipping = new Shipping
580+
{
581+
FirstName = "First",
582+
LastName = "Last",
583+
Company = "Company Inc.",
584+
Address = "1 Shipping Address St.",
585+
Address2 = "Unit 1",
586+
City = "Waltham",
587+
Region = "MA",
588+
Country = "US",
589+
Postal = "02451",
590+
PhoneNumber = "555-555-5555",
591+
PhoneCountryCode = "1",
592+
DeliverySpeed = ShippingDeliverySpeed.SameDay
593+
},
594+
Payment = new Payment
595+
{
596+
Processor = PaymentProcessor.Stripe,
597+
WasAuthorized = false,
598+
DeclineCode = "invalid number"
599+
},
600+
CreditCard = new CreditCard
601+
{
602+
IssuerIdNumber = "411111",
603+
BankName = "Test Bank",
604+
BankPhoneCountryCode = "1",
605+
BankPhoneNumber = "555-555-5555",
606+
AvsResult = 'Y',
607+
CvvResult = 'N',
608+
Last4Digits = "1234"
609+
},
610+
Order = new Order
611+
{
612+
Amount = 323.21m,
613+
Currency = "USD",
614+
DiscountCode = "FIRST",
615+
AffiliateId = "af12",
616+
SubaffiliateId = "saf42",
617+
ReferrerUri = new Uri("http://www.amazon.com/")
618+
},
619+
ShoppingCart = new List<ShoppingCartItem>
614620
{
615-
new ShoppingCartItem(
616-
category: "pets",
617-
itemId: "ad23232",
618-
quantity: 2,
619-
price: 20.43m
620-
),
621-
new ShoppingCartItem(
622-
category: "beauty",
623-
itemId: "bst112",
624-
quantity: 1,
625-
price: 100.00m
626-
)
621+
new ShoppingCartItem
622+
{
623+
Category = "pets",
624+
ItemId = "ad23232",
625+
Quantity = 2,
626+
Price = 20.43m
627+
},
628+
new ShoppingCartItem
629+
{
630+
Category = "beauty",
631+
ItemId = "bst112",
632+
Quantity = 1,
633+
Price = 100.00m
634+
}
627635
},
628-
customInputs: new CustomInputs.Builder
636+
CustomInputs = new CustomInputs.Builder
629637
{
630638
{ "float_input", 12.1d},
631639
{ "integer_input", 3123},
632640
{ "string_input", "This is a string input."},
633641
{ "boolean_input", true},
634642
}.Build()
635-
);
643+
};
636644

637645
// If you are making multiple requests, a single WebServiceClient
638646
// should be shared across requests to allow connection reuse. The

content/minfraud/report-a-transaction.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,18 @@ help us understand context are extremely helpful.
108108
```csharp
109109
var client = new WebServiceClient(10, "LICENSEKEY");
110110

111-
var report = new TransactionReport(
112-
ipAddress: IPAddress.Parse("1.1.1.1"),
113-
tag: TransactionReportTag.Chargeback,
111+
var report = new TransactionReport
112+
{
113+
IPAddress = IPAddress.Parse("1.1.1.1"),
114+
Tag = TransactionReportTag.Chargeback,
114115

115116
// The following key/values are not mandatory but are encouraged
116-
maxmindId: "abcd1234",
117-
minfraudId: new Guid("01c25cb0-f067-4e02-8ed0-a094c580f5e4"),
118-
transactionId: "txn123",
119-
chargebackCode: "BL",
120-
notes: "Suspicious account behavior");
117+
MaxMindId = "abcd1234",
118+
MinFraudId = new Guid("01c25cb0-f067-4e02-8ed0-a094c580f5e4"),
119+
TransactionId = "txn123",
120+
ChargebackCode = "BL",
121+
Notes = "Suspicious account behavior"
122+
};
121123

122124
await client.ReportAsync(report);
123125
```

0 commit comments

Comments
 (0)