Skip to content

Commit 79b2609

Browse files
committed
Update Checkout models and tests
1 parent 42d6359 commit 79b2609

247 files changed

Lines changed: 9879 additions & 12002 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Adyen.IntegrationTest/Checkout/PaymentsServiceIntegrationTest.cs

Lines changed: 102 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,23 @@ public PaymentsServiceIntegrationTest()
6464
public async Task Given_Payments_When_CardDetails_Provided_Returns_OK()
6565
{
6666
// Arrange
67-
var request = new PaymentRequest(
68-
amount: new Amount("EUR", 1999),
69-
merchantAccount: _merchantAccount,
70-
reference: "reference",
71-
returnUrl: "https://adyen.com/",
72-
paymentMethod: new CheckoutPaymentMethod(
73-
new CardDetails(
74-
type: CardDetails.TypeEnum.Scheme,
75-
encryptedCardNumber: "test_4111111111111111",
76-
encryptedExpiryMonth: "test_03",
77-
encryptedExpiryYear: "test_2030",
78-
encryptedSecurityCode: "test_737",
79-
holderName: "John Smith"
80-
)
81-
)
82-
);
67+
var request = new PaymentRequest
68+
{
69+
Amount = new Amount { Currency = "EUR", Value = 1999 },
70+
MerchantAccount = _merchantAccount,
71+
Reference = "reference",
72+
ReturnUrl = "https://adyen.com/",
73+
PaymentMethod = new CheckoutPaymentMethod(
74+
new CardDetails
75+
{
76+
Type = CardDetails.TypeEnum.Scheme,
77+
EncryptedCardNumber = "test_4111111111111111",
78+
EncryptedExpiryMonth = "test_03",
79+
EncryptedExpiryYear = "test_2030",
80+
EncryptedSecurityCode = "test_737",
81+
HolderName = "John Smith"
82+
})
83+
};
8384
IPaymentsApiResponse response = await _paymentsApiService.PaymentsAsync(request);
8485

8586
response.TryDeserializeOkResponse(out var result);
@@ -90,22 +91,23 @@ public async Task Given_Payments_When_CardDetails_Provided_Returns_OK()
9091
public async Task xGiven_Payments_When_CardDetails_With_Empty_RequestOptions_Succeeds()
9192
{
9293
// Test when no idempotency key is provided
93-
var request = new PaymentRequest(
94-
amount: new Amount("EUR", 1999),
95-
merchantAccount: _merchantAccount,
96-
reference: "ref1-original-request-1",
97-
returnUrl: "https://adyen.com/",
98-
paymentMethod: new CheckoutPaymentMethod(
99-
new CardDetails(
100-
type: CardDetails.TypeEnum.Scheme,
101-
encryptedCardNumber: "test_4111111111111111",
102-
encryptedExpiryMonth: "test_03",
103-
encryptedExpiryYear: "test_2030",
104-
encryptedSecurityCode: "test_737",
105-
holderName: "John Smith"
106-
)
107-
)
108-
);
94+
var request = new PaymentRequest
95+
{
96+
Amount = new Amount { Currency = "EUR", Value = 1999 },
97+
MerchantAccount = _merchantAccount,
98+
Reference = "ref1-original-request-1",
99+
ReturnUrl = "https://adyen.com/",
100+
PaymentMethod = new CheckoutPaymentMethod(
101+
new CardDetails
102+
{
103+
Type = CardDetails.TypeEnum.Scheme,
104+
EncryptedCardNumber = "test_4111111111111111",
105+
EncryptedExpiryMonth = "test_03",
106+
EncryptedExpiryYear = "test_2030",
107+
EncryptedSecurityCode = "test_737",
108+
HolderName = "John Smith"
109+
})
110+
};
109111
IPaymentsApiResponse response = await _paymentsApiService.PaymentsAsync(request, new RequestOptions());
110112

111113
response.TryDeserializeOkResponse(out PaymentResponse result);
@@ -117,67 +119,70 @@ public async Task xGiven_Payments_When_CardDetails_With_Empty_RequestOptions_Suc
117119
public async Task Given_Payments_When_CardDetails_Without_Idempotency_Key_Provided_Returns_DifferentRefs()
118120
{
119121
// Test when no idempotency key is provided
120-
var request = new PaymentRequest(
121-
amount: new Amount("EUR", 1999),
122-
merchantAccount: _merchantAccount,
123-
reference: "ref1-original-request-1",
124-
returnUrl: "https://adyen.com/",
125-
paymentMethod: new CheckoutPaymentMethod(
126-
new CardDetails(
127-
type: CardDetails.TypeEnum.Scheme,
128-
encryptedCardNumber: "test_4111111111111111",
129-
encryptedExpiryMonth: "test_03",
130-
encryptedExpiryYear: "test_2030",
131-
encryptedSecurityCode: "test_737",
132-
holderName: "John Smith"
133-
)
134-
)
135-
);
122+
var request = new PaymentRequest
123+
{
124+
Amount = new Amount { Currency = "EUR", Value = 1999 },
125+
MerchantAccount = _merchantAccount,
126+
Reference = "ref1-original-request-1",
127+
ReturnUrl = "https://adyen.com/",
128+
PaymentMethod = new CheckoutPaymentMethod(
129+
new CardDetails
130+
{
131+
Type = CardDetails.TypeEnum.Scheme,
132+
EncryptedCardNumber = "test_4111111111111111",
133+
EncryptedExpiryMonth = "test_03",
134+
EncryptedExpiryYear = "test_2030",
135+
EncryptedSecurityCode = "test_737",
136+
HolderName = "John Smith"
137+
})
138+
};
136139
IPaymentsApiResponse response = await _paymentsApiService.PaymentsAsync(paymentRequest: request);
137140

138141
response.TryDeserializeOkResponse(out PaymentResponse result);
139142
Assert.AreEqual(result?.MerchantReference, "ref1-original-request-1");
140143

141144

142145
// Test when no idempotency key is provided
143-
var request2 = new PaymentRequest(
144-
amount: new Amount("EUR", 1999),
145-
merchantAccount: _merchantAccount,
146-
reference: "ref2-should-be-different",
147-
returnUrl: "https://adyen.com/",
148-
paymentMethod: new CheckoutPaymentMethod(
149-
new CardDetails(
150-
type: CardDetails.TypeEnum.Scheme,
151-
encryptedCardNumber: "test_4111111111111111",
152-
encryptedExpiryMonth: "test_03",
153-
encryptedExpiryYear: "test_2030",
154-
encryptedSecurityCode: "test_737",
155-
holderName: "John Smith"
156-
)
157-
)
158-
);
146+
var request2 = new PaymentRequest
147+
{
148+
Amount = new Amount { Currency = "EUR", Value = 1999 },
149+
MerchantAccount = _merchantAccount,
150+
Reference = "ref2-should-be-different",
151+
ReturnUrl = "https://adyen.com/",
152+
PaymentMethod = new CheckoutPaymentMethod(
153+
new CardDetails
154+
{
155+
Type = CardDetails.TypeEnum.Scheme,
156+
EncryptedCardNumber = "test_4111111111111111",
157+
EncryptedExpiryMonth = "test_03",
158+
EncryptedExpiryYear = "test_2030",
159+
EncryptedSecurityCode = "test_737",
160+
HolderName = "John Smith"
161+
})
162+
};
159163
IPaymentsApiResponse response2 = await _paymentsApiService.PaymentsAsync(paymentRequest: request2);
160164

161165
response2.TryDeserializeOkResponse(out PaymentResponse result2);
162166
Assert.AreEqual(result2?.MerchantReference, "ref2-should-be-different");
163167

164168
// Test when null is explicitly provided.
165-
var request3 = new PaymentRequest(
166-
amount: new Amount("EUR", 1999),
167-
merchantAccount: _merchantAccount,
168-
reference: "ref3-should-be-very-different",
169-
returnUrl: "https://adyen.com/",
170-
paymentMethod: new CheckoutPaymentMethod(
171-
new CardDetails(
172-
type: CardDetails.TypeEnum.Scheme,
173-
encryptedCardNumber: "test_4111111111111111",
174-
encryptedExpiryMonth: "test_03",
175-
encryptedExpiryYear: "test_2030",
176-
encryptedSecurityCode: "test_737",
177-
holderName: "John Smith"
178-
)
179-
)
180-
);
169+
var request3 = new PaymentRequest
170+
{
171+
Amount = new Amount { Currency = "EUR", Value = 1999 },
172+
MerchantAccount = _merchantAccount,
173+
Reference = "ref3-should-be-very-different",
174+
ReturnUrl = "https://adyen.com/",
175+
PaymentMethod = new CheckoutPaymentMethod(
176+
new CardDetails
177+
{
178+
Type = CardDetails.TypeEnum.Scheme,
179+
EncryptedCardNumber = "test_4111111111111111",
180+
EncryptedExpiryMonth = "test_03",
181+
EncryptedExpiryYear = "test_2030",
182+
EncryptedSecurityCode = "test_737",
183+
HolderName = "John Smith"
184+
})
185+
};
181186
IPaymentsApiResponse response3 = await _paymentsApiService.PaymentsAsync(request3);
182187
response3.TryDeserializeOkResponse(out PaymentResponse result3);
183188
Assert.AreEqual(result3?.MerchantReference, "ref3-should-be-very-different");
@@ -232,22 +237,23 @@ public async Task PaymentsServiceEvents_Override_Delegates_Example()
232237
{
233238
// Arrange
234239

235-
var request = new PaymentRequest(
236-
amount: new Amount("EUR", 1999),
237-
merchantAccount: _merchantAccount,
238-
reference: "reference",
239-
returnUrl: "https://adyen.com/",
240-
paymentMethod: new CheckoutPaymentMethod(
241-
new CardDetails(
242-
type: CardDetails.TypeEnum.Scheme,
243-
encryptedCardNumber: "test_4111111111111111",
244-
encryptedExpiryMonth: "test_03",
245-
encryptedExpiryYear: "test_2030",
246-
encryptedSecurityCode: "test_737",
247-
holderName: "John Smith"
248-
)
249-
)
250-
);
240+
var request = new PaymentRequest
241+
{
242+
Amount = new Amount { Currency = "EUR", Value = 1999 },
243+
MerchantAccount = _merchantAccount,
244+
Reference = "reference",
245+
ReturnUrl = "https://adyen.com/",
246+
PaymentMethod = new CheckoutPaymentMethod(
247+
new CardDetails
248+
{
249+
Type = CardDetails.TypeEnum.Scheme,
250+
EncryptedCardNumber = "test_4111111111111111",
251+
EncryptedExpiryMonth = "test_03",
252+
EncryptedExpiryYear = "test_2030",
253+
EncryptedSecurityCode = "test_737",
254+
HolderName = "John Smith"
255+
})
256+
};
251257

252258

253259
PaymentsServiceEvents paymentsServiceEvents = _host.Services.GetRequiredService<PaymentsServiceEvents>();

Adyen.Test/Checkout/CheckoutTest.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,15 @@ public void Given_Deserialize_When_PaymentResponse_3DS2_IdentifyShopper_Result_I
554554
public void Given_Serialize_When_CheckoutSessionRequest_Result_Contains_DateOnly_And_DateTimeOffset()
555555
{
556556
// Arrange
557-
CreateCheckoutSessionRequest checkoutSessionRequest = new CreateCheckoutSessionRequest(
558-
merchantAccount: "TestMerchant",
559-
reference: "TestReference",
560-
returnUrl: "http://test-url.com",
561-
amount: new Amount("EUR", 10000L),
562-
dateOfBirth: new DateOnly(1998, 1, 1),
563-
expiresAt: new DateTimeOffset(2023, 4, 1, 1, 1, 1, TimeSpan.Zero)
564-
);
557+
CreateCheckoutSessionRequest checkoutSessionRequest = new CreateCheckoutSessionRequest
558+
{
559+
MerchantAccount = "TestMerchant",
560+
Reference = "TestReference",
561+
ReturnUrl = "http://test-url.com",
562+
Amount = new Amount { Currency = "EUR", Value = 10000L },
563+
DateOfBirth = new DateOnly(1998, 1, 1),
564+
ExpiresAt = new DateTimeOffset(2023, 4, 1, 1, 1, 1, TimeSpan.Zero),
565+
};
565566

566567
// Act
567568
string target = JsonSerializer.Serialize(checkoutSessionRequest, _jsonSerializerOptionsProvider.Options);
@@ -585,14 +586,15 @@ public void Given_Serialize_When_CheckoutSessionRequest_Result_Contains_DateOnly
585586
public void Given_Serialize_When_CheckoutSessionRequest_Is_Filled_Result_Returns_No_Null_Values()
586587
{
587588
// Arrange
588-
CreateCheckoutSessionRequest checkoutSessionRequest = new CreateCheckoutSessionRequest(
589-
merchantAccount: "TestMerchant",
590-
reference: "TestReference",
591-
returnUrl: "http://test-url.com",
592-
amount: new Amount("EUR", 10000L),
593-
dateOfBirth: new DateOnly(1998, 1, 1),
594-
expiresAt: new DateTimeOffset(2023, 4, 1, 1, 1, 1, TimeSpan.Zero)
595-
);
589+
CreateCheckoutSessionRequest checkoutSessionRequest = new CreateCheckoutSessionRequest
590+
{
591+
MerchantAccount = "TestMerchant",
592+
Reference = "TestReference",
593+
ReturnUrl = "http://test-url.com",
594+
Amount = new Amount { Currency = "EUR", Value = 10000L },
595+
DateOfBirth = new DateOnly(1998, 1, 1),
596+
ExpiresAt = new DateTimeOffset(2023, 4, 1, 1, 1, 1, TimeSpan.Zero),
597+
};
596598

597599
// Act
598600
string target = JsonSerializer.Serialize(checkoutSessionRequest, _jsonSerializerOptionsProvider.Options);

Adyen.Test/Checkout/ModificationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void Given_Serialize_When_PaymentRefundRequest_Result_MerchantRefundReaso
119119
// Arrange
120120
PaymentRefundRequest paymentRefundRequest = new PaymentRefundRequest
121121
{
122-
Amount = new Amount("USD", 10000),
122+
Amount = new Amount { Currency = "USD", Value = 10000 },
123123
MerchantAccount = "TestMerchant",
124124
MerchantRefundReason = PaymentRefundRequest.MerchantRefundReasonEnum.FRAUD
125125
};
@@ -144,7 +144,7 @@ public void Given_Serialize_When_PaymentRefundRequest_Without_MerchantRefundReas
144144
// Arrange
145145
PaymentRefundRequest paymentRefundRequest = new PaymentRefundRequest
146146
{
147-
Amount = new Amount("USD", 10000),
147+
Amount = new Amount { Currency = "USD", Value = 10000 },
148148
MerchantAccount = "TestMerchant"
149149
};
150150

@@ -167,7 +167,7 @@ public void Given_Serialize_When_PaymentRefundRequest_With_MerchantRefundReason_
167167
// Arrange
168168
PaymentRefundRequest paymentRefundRequest = new PaymentRefundRequest
169169
{
170-
Amount = new Amount("USD", 10000),
170+
Amount = new Amount { Currency = "USD", Value = 10000 },
171171
MerchantAccount = "TestMerchant",
172172
MerchantRefundReason = null
173173
};

0 commit comments

Comments
 (0)