Skip to content

Commit 8d1139a

Browse files
authored
Add test with idempotency key (#1555)
1 parent 85b0e59 commit 8d1139a

File tree

1 file changed

+76
-28
lines changed

1 file changed

+76
-28
lines changed

src/test/java/com/adyen/CheckoutTest.java

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.adyen.constants.ApiConstants;
2828
import com.adyen.enums.Environment;
29+
import com.adyen.model.RequestOptions;
2930
import com.adyen.model.checkout.*;
3031
import com.adyen.service.checkout.*;
3132
import com.fasterxml.jackson.databind.JsonNode;
@@ -39,7 +40,7 @@ public class CheckoutTest extends BaseTest {
3940

4041
/** Should make a payment */
4142
@Test
42-
public void TestPaymentSuccess() throws Exception {
43+
public void testPaymentSuccess() throws Exception {
4344
Client client = createMockClientFromFile("mocks/checkout/paymentResponse.json");
4445
CardDetails cardDetails =
4546
new CardDetails()
@@ -75,7 +76,7 @@ public void TestPaymentSuccess() throws Exception {
7576
* serialization and deserialization)
7677
*/
7778
@Test
78-
public void TestDeserializePaymentRequestIdeal() throws Exception {
79+
public void testDeserializePaymentRequestIdeal() throws Exception {
7980
String paymentRequestJson = getFileContents("mocks/checkout/paymentRequestIdeal.json");
8081

8182
PaymentRequest parsedCheckoutPaymentRequest = PaymentRequest.fromJson(paymentRequestJson);
@@ -97,7 +98,7 @@ public void TestDeserializePaymentRequestIdeal() throws Exception {
9798

9899
/** Deserialise CardDetails (scheme) */
99100
@Test
100-
public void TestDeserializePaymentRequestScheme() throws Exception {
101+
public void testDeserializePaymentRequestScheme() throws Exception {
101102
String paymentRequestJson = getFileContents("mocks/checkout/paymentRequestScheme.json");
102103

103104
PaymentRequest parsedCheckoutPaymentRequest = PaymentRequest.fromJson(paymentRequestJson);
@@ -125,7 +126,7 @@ public void TestDeserializePaymentRequestScheme() throws Exception {
125126

126127
/** Should make paymentMethods call */
127128
@Test
128-
public void TestPaymentMethodsSuccess() throws Exception {
129+
public void testPaymentMethodsSuccess() throws Exception {
129130
Client client = createMockClientFromFile("mocks/checkout/paymentMethodsResponse.json");
130131
PaymentMethodsRequest paymentMethodsRequest = new PaymentMethodsRequest()
131132
.merchantAccount("myMerchantAccount");
@@ -138,7 +139,7 @@ public void TestPaymentMethodsSuccess() throws Exception {
138139

139140
/** Should make paymentLink call */
140141
@Test
141-
public void TestPaymentLinkSuccess() throws Exception {
142+
public void testPaymentLinkSuccess() throws Exception {
142143
Client client = createMockClientFromFile("mocks/checkout/paymentLinkResponse.json");
143144
PaymentLinkRequest createPaymentLinkRequest = new PaymentLinkRequest()
144145
.amount(new Amount().currency("EUR").value(500L))
@@ -156,7 +157,7 @@ public void TestPaymentLinkSuccess() throws Exception {
156157

157158
/** Should make paymentLink get call */
158159
@Test
159-
public void TestGetPaymentLinkSuccess() throws Exception {
160+
public void testGetPaymentLinkSuccess() throws Exception {
160161
Client client = createMockClientFromFile("mocks/checkout/getPaymentLinkResponse.json");
161162

162163
PaymentLinksApi checkout = new PaymentLinksApi(client);
@@ -181,7 +182,7 @@ public void TestPatchPaymentLinkSuccess() throws Exception {
181182

182183
/** Should make payments/details call */
183184
@Test
184-
public void TestPaymentDetailsSuccess() throws Exception {
185+
public void testPaymentDetailsSuccess() throws Exception {
185186
Client client = createMockClientFromFile("mocks/checkout/paymentDetailsResponse.json");
186187
PaymentDetailsRequest detailsRequest = new PaymentDetailsRequest()
187188
.paymentData("STATE_DATA");
@@ -193,7 +194,7 @@ public void TestPaymentDetailsSuccess() throws Exception {
193194
}
194195

195196
@Test
196-
public void TestPaymentDetailsWithThreeDSRequestorChallengeInd() throws Exception {
197+
public void testPaymentDetailsWithThreeDSRequestorChallengeInd() throws Exception {
197198
Client client =
198199
createMockClientFromFile(
199200
"mocks/checkout/paymentDetailsResponseThreeDSRequestorChallengeInd.json");
@@ -211,7 +212,7 @@ public void TestPaymentDetailsWithThreeDSRequestorChallengeInd() throws Exceptio
211212
}
212213

213214
@Test
214-
public void TestPaymentDetailsWithThreeDS2Action() throws Exception {
215+
public void testPaymentDetailsWithThreeDS2Action() throws Exception {
215216
Client client =
216217
createMockClientFromFile("mocks/checkout/paymentDetailsResponseThreeDS2Action.json");
217218
PaymentDetailsRequest detailsRequest = new PaymentDetailsRequest()
@@ -232,7 +233,7 @@ public void TestPaymentDetailsWithThreeDS2Action() throws Exception {
232233

233234
/** Should make sessions call */
234235
@Test
235-
public void TestCreateSessionsSuccessCall() throws Exception {
236+
public void testCreateSessionsSuccessCall() throws Exception {
236237
Client client = createMockClientFromFile("mocks/checkout/createSessionsResponse.json");
237238
CreateCheckoutSessionRequest sessionRequest = new CreateCheckoutSessionRequest()
238239
.merchantAccount("YOUR_MERCHANT_ACCOUNT")
@@ -256,7 +257,7 @@ public void TestCreateSessionsSuccessCall() throws Exception {
256257

257258
/** Should make orders call */
258259
@Test
259-
public void TestCreateOrderSuccessCall() throws Exception {
260+
public void testCreateOrderSuccessCall() throws Exception {
260261
Client client = createMockClientFromFile("mocks/checkout/createOrderResponse.json");
261262
CreateOrderRequest checkoutCreateOrderRequest = new CreateOrderRequest()
262263
.amount(new Amount().currency("EUR").value(1000L))
@@ -270,7 +271,7 @@ public void TestCreateOrderSuccessCall() throws Exception {
270271
}
271272

272273
@Test
273-
public void TestCancelOrderSuccessCall() throws Exception {
274+
public void testCancelOrderSuccessCall() throws Exception {
274275
Client client = createMockClientFromFile("mocks/checkout/cancelOrderResponse.json");
275276
CancelOrderRequest checkoutCancelOrderRequest = new CancelOrderRequest()
276277
.merchantAccount("YOUR_MERCHANT_ACCOUNT")
@@ -288,7 +289,7 @@ public void TestCancelOrderSuccessCall() throws Exception {
288289

289290
/** Should make applePaySessions call */
290291
@Test
291-
public void TestApplePaySessionsSuccessCall() throws Exception {
292+
public void testApplePaySessionsSuccessCall() throws Exception {
292293
Client client = createMockClientFromFile("mocks/checkout/applePaySessionsResponse.json");
293294
ApplePaySessionRequest createApplePaySessionRequest = new ApplePaySessionRequest()
294295
.displayName("YOUR_MERCHANT_NAME")
@@ -303,7 +304,7 @@ public void TestApplePaySessionsSuccessCall() throws Exception {
303304

304305
/** Should make donations call */
305306
@Test
306-
public void TestDonationsSuccessCall() throws Exception {
307+
public void testDonationsSuccessCall() throws Exception {
307308
Client client = createMockClientFromFile("mocks/checkout/donationResponse.json");
308309
DonationPaymentRequest paymentDonationRequest = new DonationPaymentRequest()
309310
.donationAccount("YOUR_DONATION_ACCOUNT")
@@ -325,7 +326,7 @@ public void TestDonationsSuccessCall() throws Exception {
325326

326327
/** Should make paymentUpdateAmount call */
327328
@Test
328-
public void TestPaymenUpdateAmountSuccessCall() throws Exception {
329+
public void testPaymenUpdateAmountSuccessCall() throws Exception {
329330
Client client = createMockClientFromFile("mocks/checkout/paymentUpdateAmountResponse.json");
330331
ModificationsApi checkout = new ModificationsApi(client);
331332
PaymentAmountUpdateRequest createPaymentAmountUpdateRequest = new PaymentAmountUpdateRequest();
@@ -343,7 +344,7 @@ public void TestPaymenUpdateAmountSuccessCall() throws Exception {
343344

344345
/** Should make cardDetails call */
345346
@Test
346-
public void TestCardDetailsRequestSuccess() throws Exception {
347+
public void testCardDetailsRequestSuccess() throws Exception {
347348
Client client = createMockClientFromFile("mocks/checkout/cardDetailsResponse.json");
348349
CardDetailsRequest cardDetailsRequest = new CardDetailsRequest();
349350
cardDetailsRequest.setCardNumber("123412341234");
@@ -357,7 +358,7 @@ public void TestCardDetailsRequestSuccess() throws Exception {
357358

358359
/** Should properly (de)serialize Dates */
359360
@Test
360-
public void TestDateSerialization() throws Exception {
361+
public void testDateSerialization() throws Exception {
361362
BalanceCheckRequest checkoutBalanceCheckRequest = new BalanceCheckRequest();
362363
OffsetDateTime date =
363364
OffsetDateTime.parse(
@@ -378,7 +379,7 @@ public void TestDateSerialization() throws Exception {
378379

379380
/** Should get StoredPaymentMethods */
380381
@Test
381-
public void TestGetStoredPaymentMethods() throws Exception {
382+
public void testGetStoredPaymentMethods() throws Exception {
382383
Client client = createMockClientFromFile("mocks/checkout/getStoredPaymentMethodResponse.json");
383384
RecurringApi checkout = new RecurringApi(client);
384385
ListStoredPaymentMethodsResponse response =
@@ -389,7 +390,7 @@ public void TestGetStoredPaymentMethods() throws Exception {
389390

390391
/** Should delete StoredPaymentMethods */
391392
@Test
392-
public void TestDeleteStoredPaymentMethods() throws Exception {
393+
public void testDeleteStoredPaymentMethods() throws Exception {
393394
Client client =
394395
createMockClientFromFile("mocks/checkout/deleteStoredPaymentMethodResponse.json");
395396
RecurringApi checkout = new RecurringApi(client);
@@ -398,7 +399,7 @@ public void TestDeleteStoredPaymentMethods() throws Exception {
398399

399400
/** Should delete StoredPaymentMethods */
400401
@Test
401-
public void TestLiveURLCheckout() throws Exception {
402+
public void testLiveURLCheckout() throws Exception {
402403
Config config = new Config();
403404
config.setLiveEndpointUrlPrefix("prefix");
404405
config.setEnvironment(Environment.LIVE);
@@ -423,7 +424,7 @@ public void TestLiveURLCheckout() throws Exception {
423424
}
424425

425426
@Test
426-
public void TestLiveURLCheckoutWithSetEnviroment() throws Exception {
427+
public void testLiveURLCheckoutWithSetEnviroment() throws Exception {
427428
Client client =
428429
createMockClientFromFile("mocks/checkout/deleteStoredPaymentMethodResponse.json");
429430
client.setEnvironment(Environment.LIVE, "prefix");
@@ -445,7 +446,7 @@ public void TestLiveURLCheckoutWithSetEnviroment() throws Exception {
445446
}
446447

447448
@Test
448-
public void TestCheckoutPaymentMethodSerialisation() throws Exception {
449+
public void testCheckoutPaymentMethodSerialisation() throws Exception {
449450
// Checks that unknown parameters (in this case googlePayCardNetwork) in oneOf classes are not
450451
// strict and will
451452
// not throw an error.
@@ -484,7 +485,7 @@ public void TestCheckoutPaymentMethodSerialisation() throws Exception {
484485
}
485486

486487
@Test
487-
public void TestPaymentWithRatepay() throws Exception {
488+
public void testPaymentWithRatepay() throws Exception {
488489
Client client = createMockClientFromFile("mocks/checkout/paymentResponseRatepay.json");
489490

490491
RatepayDetails ratepayDetails =
@@ -548,7 +549,7 @@ public void TestPaymentWithRatepay() throws Exception {
548549
}
549550

550551
@Test
551-
public void TestPaymentWithRiverty() throws Exception {
552+
public void testPaymentWithRiverty() throws Exception {
552553
Client client = createMockClientFromFile("mocks/checkout/paymentResponseRiverty.json");
553554

554555
RivertyDetails rivertyDetails =
@@ -621,7 +622,7 @@ public void TestPaymentWithRiverty() throws Exception {
621622
}
622623

623624
@Test
624-
public void TestPaymentMethodsNullLists() throws Exception {
625+
public void testPaymentMethodsNullLists() throws Exception {
625626
Client client = createMockClientFromFile("mocks/checkout/paymentMethodsResponse.json");
626627
PaymentMethodsRequest paymentMethodsRequest = new PaymentMethodsRequest();
627628
paymentMethodsRequest.setMerchantAccount("myMerchantAccount");
@@ -634,7 +635,7 @@ public void TestPaymentMethodsNullLists() throws Exception {
634635
}
635636

636637
@Test
637-
public void TestSessionsCheckDefaultValues() throws Exception {
638+
public void testSessionsCheckDefaultValues() throws Exception {
638639
Client client = createMockClientFromFile("mocks/checkout/createSessionsResponse.json");
639640
CreateCheckoutSessionRequest sessionRequest = new CreateCheckoutSessionRequest();
640641
sessionRequest.setReturnUrl("https://your-company.com/checkout?shopperOrder=12xy..");
@@ -674,7 +675,7 @@ public void TestSessionsCheckDefaultValues() throws Exception {
674675
}
675676

676677
@Test
677-
public void TestBccm() throws Exception {
678+
public void testBccm() throws Exception {
678679
Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmc.json");
679680
PaymentRequest paymentRequest = new PaymentRequest();
680681
paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
@@ -697,7 +698,7 @@ public void TestBccm() throws Exception {
697698
}
698699

699700
@Test
700-
public void TestBccmMobile() throws Exception {
701+
public void testBccmMobile() throws Exception {
701702
Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmcMobile.json");
702703
PaymentRequest paymentRequest = new PaymentRequest();
703704
paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
@@ -738,4 +739,51 @@ public void testPixActionQrCode() throws Exception {
738739
assertEquals("pix", qrCodeAction.getPaymentMethodType());
739740
assertEquals("DMhpN90TFR2e7TzwHYRFkhw4brxm2wHBg", qrCodeAction.getQrCodeData());
740741
}
742+
743+
@Test
744+
public void testPaymentWithIdempotencyKey() throws Exception {
745+
Client client = createMockClientFromFile("mocks/checkout/paymentResultsResponse.json");
746+
CardDetails cardDetails =
747+
new CardDetails()
748+
.type(CardDetails.TypeEnum.SCHEME)
749+
.encryptedCardNumber("5136333333333335")
750+
.holderName("John Doe")
751+
.cvc("737")
752+
.encryptedExpiryMonth("08")
753+
.encryptedExpiryYear("2018");
754+
PaymentRequest paymentRequest =
755+
new PaymentRequest()
756+
.merchantAccount("YOUR_MERCHANT_ACCOUNT")
757+
.reference("YOUR_REFERENCE")
758+
.amount(new Amount()
759+
.currency("EUR")
760+
.value(1000L))
761+
.returnUrl("https://your-company.example.org/checkout?shopperOrder=12xy..")
762+
.paymentMethod(new CheckoutPaymentMethod(cardDetails));
763+
764+
PaymentsApi checkout = new PaymentsApi(client);
765+
766+
// set Idempotency Key
767+
RequestOptions requestOptions = new RequestOptions()
768+
.idempotencyKey("99361789-5204-4576-b123-4f9a1b2c3d45");
769+
PaymentResponse paymentResponse = checkout.payments(paymentRequest, requestOptions);
770+
771+
assertEquals("V4HZ4RBFJGXXGN82", paymentResponse.getPspReference());
772+
assertEquals(PaymentResponse.ResultCodeEnum.AUTHORISED, paymentResponse.getResultCode());
773+
774+
ArgumentCaptor<RequestOptions> optionsCaptor = ArgumentCaptor.forClass(RequestOptions.class);
775+
verify(client.getHttpClient())
776+
.request(
777+
eq("https://checkout-test.adyen.com/v71/payments"),
778+
isNotNull(),
779+
eq(client.getConfig()),
780+
eq(false),
781+
optionsCaptor.capture(),
782+
eq(ApiConstants.HttpMethod.POST),
783+
isNull()
784+
);
785+
assertEquals("99361789-5204-4576-b123-4f9a1b2c3d45", optionsCaptor.getValue().getIdempotencyKey());
786+
787+
}
788+
741789
}

0 commit comments

Comments
 (0)