Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pw 5482/update checkout api v68 #625

Merged
merged 7 commits into from
Oct 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is the officially supported Java library for using Adyen's APIs.

The library supports all APIs under the following services:

* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v67/overview): Our latest integration for accepting online payments. Current supported version: **v67**
* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v68/overview): Our latest integration for accepting online payments. Current supported version: **v68**
* [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v52/overview): Our classic integration for online payments. Current supported version: **v52**
* [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v49/overview): Endpoints for managing saved payment details. Current supported version: **v49**
* [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v51/overview): Endpoints for sending funds to your customers. Current supported version: **v51**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/adyen/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Client {
public static final String CHECKOUT_ENDPOINT_TEST = "https://checkout-test.adyen.com/checkout";
public static final String CHECKOUT_ENDPOINT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout";
public static final String CHECKOUT_ENDPOINT_CERT_LIVE = "https://checkoutcert-live-%s.adyen.com/checkout";
public static final String CHECKOUT_API_VERSION = "v67";
public static final String CHECKOUT_API_VERSION = "v68";
public static final String CHECKOUT_STORED_PAYMENT_METHODS_VERSION = "v65";
public static final String BIN_LOOKUP_PAL_SUFFIX = "/pal/servlet/BinLookup/";
public static final String BIN_LOOKUP_API_VERSION = "v50";
Expand Down
1,541 changes: 1,541 additions & 0 deletions src/main/java/com/adyen/model/checkout/CreateCheckoutSessionRequest.java

Large diffs are not rendered by default.

1,583 changes: 1,583 additions & 0 deletions src/main/java/com/adyen/model/checkout/CreateCheckoutSessionResponse.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ public String toString() {
}




}


Expand Down
22 changes: 21 additions & 1 deletion src/main/java/com/adyen/service/Checkout.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* Adyen Java API Library
*
* Copyright (c) 2020 Adyen B.V.
* Copyright (c) 2021 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
Expand All @@ -29,6 +29,8 @@
import com.adyen.model.checkout.CheckoutCreateOrderRequest;
import com.adyen.model.checkout.CheckoutCreateOrderResponse;
import com.adyen.model.checkout.CreateStoredPaymentMethodRequest;
import com.adyen.model.checkout.CreateCheckoutSessionRequest;
import com.adyen.model.checkout.CreateCheckoutSessionResponse;
import com.adyen.model.checkout.PaymentMethodsRequest;
import com.adyen.model.checkout.PaymentMethodsResponse;
import com.adyen.model.checkout.PaymentResultRequest;
Expand All @@ -48,6 +50,7 @@
import com.adyen.service.resource.checkout.Payments;
import com.adyen.service.resource.checkout.PaymentsDetails;
import com.adyen.service.resource.checkout.PaymentsResult;
import com.adyen.service.resource.checkout.Sessions;
import com.adyen.service.resource.checkout.StoredPaymentsMethods;
import com.google.gson.reflect.TypeToken;

Expand All @@ -62,6 +65,7 @@ public class Checkout extends ApiKeyAuthenticatedService {
private PaymentsResult paymentsResult;
private Orders orders;
private OrdersCancel ordersCancel;
private Sessions sessions;
private StoredPaymentsMethods storedPaymentsMethods;

public Checkout(Client client) {
Expand All @@ -74,6 +78,7 @@ public Checkout(Client client) {
paymentsResult = new PaymentsResult(this);
orders = new Orders(this);
ordersCancel = new OrdersCancel(this);
sessions = new Sessions(this);
storedPaymentsMethods = new StoredPaymentsMethods(this);

}
Expand Down Expand Up @@ -213,4 +218,19 @@ public CheckoutCancelOrderResponse ordersCancel(CheckoutCancelOrderRequest check
return GSON.fromJson(jsonResult, new TypeToken<CheckoutCancelOrderResponse>() {
}.getType());
}

/**
* POST /sessions API call
*
* @param createCheckoutSessionRequest CreateCheckoutSessionRequest
* @return
* @throws ApiException
* @throws IOException
*/
public CreateCheckoutSessionResponse sessions(CreateCheckoutSessionRequest createCheckoutSessionRequest) throws ApiException, IOException {
String jsonRequest = GSON.toJson(createCheckoutSessionRequest);
String jsonResult = sessions.request(jsonRequest);
return GSON.fromJson(jsonResult, new TypeToken<CreateCheckoutSessionResponse>() {
}.getType());
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/adyen/service/resource/checkout/Sessions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Java API Library
*
* Copyright (c) 2021 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/

package com.adyen.service.resource.checkout;

import com.adyen.Client;
import com.adyen.Service;
import com.adyen.service.Resource;

wboereboom marked this conversation as resolved.
Show resolved Hide resolved
import java.util.Arrays;

public class Sessions extends Resource {

public Sessions(Service service) {
super(service, service.getClient().getConfig().getCheckoutEndpoint() + "/" + Client.CHECKOUT_API_VERSION + "/sessions",
Arrays.asList("amount", "reference", "returnUrl", "merchantAccount"));
}
}
44 changes: 43 additions & 1 deletion src/test/java/com/adyen/CheckoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* Adyen Java API Library
*
* Copyright (c) 2020 Adyen B.V.
* Copyright (c) 2021 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
Expand Down Expand Up @@ -45,6 +45,8 @@
import com.adyen.model.checkout.PaymentsDetailsResponse;
import com.adyen.model.checkout.PaymentsRequest;
import com.adyen.model.checkout.PaymentsResponse;
import com.adyen.model.checkout.CreateCheckoutSessionRequest;
import com.adyen.model.checkout.CreateCheckoutSessionResponse;
import com.adyen.model.checkout.Redirect;
import com.adyen.model.checkout.RiskData;
import com.adyen.model.checkout.StoredPaymentMethodResource;
Expand Down Expand Up @@ -2165,6 +2167,46 @@ public void TestBankTransferPaymentsSuccess() throws IOException, ApiException {
assertEquals("851-6178-9473-6924A", paymentsResponse.getAction().getReference());
assertEquals("bankTransfer_IBAN", paymentsResponse.getAction().getPaymentMethodType());
}

/**
* Test Checkout Sessions
*/
protected CreateCheckoutSessionRequest createCreateCheckoutSessionRequest() {
CreateCheckoutSessionRequest createCheckoutSessionRequest = new CreateCheckoutSessionRequest();
createCheckoutSessionRequest.setMerchantAccount("TestMerchant");
createCheckoutSessionRequest.setReference("TestReference");
createCheckoutSessionRequest.setReturnUrl("http://test-url.com");

Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setValue(10000L);

createCheckoutSessionRequest.setAmount(amount);
return createCheckoutSessionRequest;
}

@Test
public void TestCheckoutSessionSuccess() throws IOException, ApiException {
Client client = createMockClientFromFile("mocks/checkout/sessions-success.json");
Checkout checkout = new Checkout(client);
CreateCheckoutSessionRequest sessionsRequest = createCreateCheckoutSessionRequest();
CreateCheckoutSessionResponse sessionsResponse = checkout.sessions(sessionsRequest);
assertEquals("TestMerchant", sessionsResponse.getMerchantAccount());
assertEquals("TestReference", sessionsResponse.getReference());
assertEquals("http://test-url.com", sessionsResponse.getReturnUrl());
assertEquals("2021-09-30T06:45:06Z", sessionsResponse.getExpiresAt());
assertEquals("EUR", sessionsResponse.getAmount().getCurrency());
assertEquals("1000", sessionsResponse.getAmount().getValue().toString());
}

@Test
public void TestCheckoutSessionErrorMocked() throws Exception {
Client client = createMockClientFromFile("mocks/checkout/sessions-error-invalid-data-422.json");
Checkout checkout = new Checkout(client);
CreateCheckoutSessionRequest sessionsRequest = createCreateCheckoutSessionRequest();
CreateCheckoutSessionResponse sessionsResponse = checkout.sessions(sessionsRequest);
assertNull(sessionsResponse.getSessionData());
}
}

class TestPaymentMethodDetails implements PaymentMethodDetails {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"status": 422,
"errorCode": "130",
"message": "Reference Missing",
"errorType": "validation"
}
11 changes: 11 additions & 0 deletions src/test/resources/mocks/checkout/sessions-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "session-test-id",
"amount": {
"currency": "EUR",
"value": 1000
},
"reference": "TestReference",
"returnUrl": "http://test-url.com",
"expiresAt": "2021-09-30T06:45:06Z",
"merchantAccount": "TestMerchant"
}