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
71 changes: 71 additions & 0 deletions src/test/java/com/adyen/CheckoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,77 @@ public void testCreateSessionsSuccessCall() throws Exception {
createCheckoutSessionResponse.getStorePaymentMethodMode());
}

@Test
public void testUpdateSessionSuccessCall() throws Exception {
Client client = createMockClientFromResponse("{\"sessionData\":\"updated-session-data\"}");
CheckoutSessionPatchSessionRequest sessionRequest =
new CheckoutSessionPatchSessionRequest()
.amount(new SessionAmountUpdate().currency("EUR").value(750L))
.payable(true)
.sessionData("original-session-data");

PaymentsApi checkout = new PaymentsApi(client);
CheckoutSessionPatchSessionResponse response =
checkout.updateSession("CS1453E3730C313478", sessionRequest);

assertEquals("updated-session-data", response.getSessionData());
verify(client.getHttpClient())
.request(
String.format(
"https://checkout-test.adyen.com/v%s/sessions/CS1453E3730C313478",
PaymentsApi.API_VERSION),
sessionRequest.toJson(),
client.getConfig(),
false,
null,
ApiConstants.HttpMethod.PATCH,
null);
}

@Test
public void testNewCheckoutModelFieldsSerialization() throws Exception {
AffirmDetails affirmDetails =
new AffirmDetails().type(AffirmDetails.TypeEnum.AFFIRM).financingProgram("PAY_IN_4");
DonationCampaignsRequest donationCampaignsRequest =
new DonationCampaignsRequest().currency("EUR").label("Round up for charity");

assertEquals("PAY_IN_4", AffirmDetails.fromJson(affirmDetails.toJson()).getFinancingProgram());
assertEquals(
"Round up for charity",
DonationCampaignsRequest.fromJson(donationCampaignsRequest.toJson()).getLabel());
}

@Test
public void testDonationPaymentMethodWithSepaDirectDebit() throws Exception {
DonationPaymentMethod paymentMethod =
new DonationPaymentMethod(
new SepaDirectDebitDonations()
.type(SepaDirectDebitDonations.TypeEnum.SEPADIRECTDEBIT)
.storedPaymentMethodId("M5N7TQ4TG5PFWR50"));

DonationPaymentMethod parsed = DonationPaymentMethod.fromJson(paymentMethod.toJson());

assertEquals(
SepaDirectDebitDonations.TypeEnum.SEPADIRECTDEBIT,
parsed.getSepaDirectDebitDonations().getType());
assertEquals(
"M5N7TQ4TG5PFWR50", parsed.getSepaDirectDebitDonations().getStoredPaymentMethodId());
}

@Test
public void testGopayWalletUsesStoredPaymentMethodDetails() throws Exception {
CheckoutPaymentMethod paymentMethod =
new CheckoutPaymentMethod(
new StoredPaymentMethodDetails()
.type(StoredPaymentMethodDetails.TypeEnum.GOPAY_WALLET));

CheckoutPaymentMethod parsed = CheckoutPaymentMethod.fromJson(paymentMethod.toJson());

assertEquals(
StoredPaymentMethodDetails.TypeEnum.GOPAY_WALLET,
parsed.getStoredPaymentMethodDetails().getType());
}

/** Should make orders call */
@Test
public void testCreateOrderSuccessCall() throws Exception {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/adyen/PaymentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,21 @@ public void TestByteArrayDeserialization() throws Exception {
assertEquals(expectedBytesAsString, new String(Base64.decodeBase64(actualDeserializedBytes)));
}

@Test
public void TestTransactionLinkId() throws Exception {
String transactionLinkId = "MC-TLID-123456789";
AdditionalDataCommon requestAdditionalData =
new AdditionalDataCommon().transactionLinkId(transactionLinkId);

assertEquals("{\"transactionLinkId\":\"MC-TLID-123456789\"}", requestAdditionalData.toJson());

ResponseAdditionalDataCommon responseAdditionalData =
ResponseAdditionalDataCommon.fromJson(
"{\"transactionLinkId\":\"" + transactionLinkId + "\"}");

assertEquals(transactionLinkId, responseAdditionalData.getTransactionLinkId());
}

@Test
public void TestByteArrayToJSONString() throws Exception {
Client client = createMockClientFromFile("mocks/authorise-success.json");
Expand Down