diff --git a/CHANGELOG.md b/CHANGELOG.md index c8dd9d4..e8be90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [3.1.15] +- Added `SupportedTerminals` (list of `Terminal` titles) to `Session` in `/createCheckoutSession` and `/updateCheckoutSession` API responses, and corresponding nullable `List supportedTerminals` field on `CheckoutSessionResponse`. Allows consumers to learn which terminals successfully initialised an external session (or didn't require one) in the checkout session, so that unsupported payment methods can be filtered out. Backward compatible: field is `null` when the gateway omits the element. + ## [3.1.14] - Added `AcquirerTransactionData` diff --git a/build.gradle b/build.gradle index 0790c35..d4dc002 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } group = 'com.altapay' -version = '3.1.14' +version = '3.1.15' repositories { mavenCentral() diff --git a/src/main/java/com/pensio/api/PensioMerchantAPI.java b/src/main/java/com/pensio/api/PensioMerchantAPI.java index db0e207..bea059f 100644 --- a/src/main/java/com/pensio/api/PensioMerchantAPI.java +++ b/src/main/java/com/pensio/api/PensioMerchantAPI.java @@ -766,14 +766,20 @@ private void addTerminals(HashMap params, List terminals private CheckoutSessionResponse checkoutSession(String apiUrl, HashMap params) throws PensioAPIException { APIResponse response = getAPIResponse(apiUrl, HttpMethod.POST, params); + return mapCheckoutSessionResponse(response.getBody().getSession()); + } - CheckoutSessionResponse checkoutSessionResponse = new CheckoutSessionResponse(); - if (response.getBody().getSession() != null) { - Session session = response.getBody().getSession(); - checkoutSessionResponse.setSessionId(session.getId()); - checkoutSessionResponse.setSessionStatus(SessionStatus.valueOf(session.getStatus())); + static CheckoutSessionResponse mapCheckoutSessionResponse(Session session) { + CheckoutSessionResponse out = new CheckoutSessionResponse(); + if (session == null) { + return out; + } + out.setSessionId(session.getId()); + out.setSessionStatus(SessionStatus.valueOf(session.getStatus())); + if (session.getSupportedTerminals() != null) { + out.setSupportedTerminals(new java.util.ArrayList<>(session.getSupportedTerminals().getTerminal())); } - return checkoutSessionResponse; + return out; } protected String getAppAPIPath() diff --git a/src/main/java/com/pensio/response/CheckoutSessionResponse.java b/src/main/java/com/pensio/response/CheckoutSessionResponse.java index b213066..ccb16c0 100644 --- a/src/main/java/com/pensio/response/CheckoutSessionResponse.java +++ b/src/main/java/com/pensio/response/CheckoutSessionResponse.java @@ -2,9 +2,12 @@ import com.pensio.api.SessionStatus; +import java.util.List; + public class CheckoutSessionResponse { private String sessionId; private SessionStatus sessionStatus; + private List supportedTerminals; public String getSessionId() { return sessionId; @@ -21,4 +24,12 @@ public SessionStatus getSessionStatus() { public void setSessionStatus(SessionStatus sessionStatus) { this.sessionStatus = sessionStatus; } + + public List getSupportedTerminals() { + return supportedTerminals; + } + + public void setSupportedTerminals(List supportedTerminals) { + this.supportedTerminals = supportedTerminals; + } } diff --git a/src/main/resources/xsd/APIResponse.xsd b/src/main/resources/xsd/APIResponse.xsd index c1d01c5..6e47d5b 100644 --- a/src/main/resources/xsd/APIResponse.xsd +++ b/src/main/resources/xsd/APIResponse.xsd @@ -338,6 +338,13 @@ + + + + + + + diff --git a/src/test/java/com/pensio/api/CheckoutSessionResponseParseTest.java b/src/test/java/com/pensio/api/CheckoutSessionResponseParseTest.java new file mode 100644 index 0000000..4287b7e --- /dev/null +++ b/src/test/java/com/pensio/api/CheckoutSessionResponseParseTest.java @@ -0,0 +1,90 @@ +package com.pensio.api; + +import com.pensio.api.generated.APIResponse; +import com.pensio.api.generated.Session; +import com.pensio.response.CheckoutSessionResponse; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class CheckoutSessionResponseParseTest { + + private static final String XML_HEADER = + "" + + "" + + "
" + + " 2026-05-19T11:00:00+00:00" + + " API/createCheckoutSession" + + " 0" + + " Success" + + "
"; + + private final PensioMerchantAPI api = new PensioMerchantAPI("url", "u", "p"); + + @Test + void mapsSessionWithPopulatedSupportedTerminals() throws Exception { + String xml = XML_HEADER + + " " + + " " + + " sess-1" + + " CREATED" + + " " + + " terminal-a" + + " terminal-b" + + " " + + " " + + " " + + "
"; + + APIResponse parsed = api.parsePostBackXMLParameter(xml); + Session session = parsed.getBody().getSession(); + CheckoutSessionResponse mapped = PensioMerchantAPI.mapCheckoutSessionResponse(session); + + assertEquals("sess-1", mapped.getSessionId()); + assertNotNull(mapped.getSupportedTerminals()); + assertEquals(List.of("terminal-a", "terminal-b"), mapped.getSupportedTerminals()); + } + + @Test + void mapsSessionWithEmptySupportedTerminalsElement() throws Exception { + String xml = XML_HEADER + + " " + + " " + + " sess-2" + + " CREATED" + + " " + + " " + + " " + + ""; + + APIResponse parsed = api.parsePostBackXMLParameter(xml); + Session session = parsed.getBody().getSession(); + CheckoutSessionResponse mapped = PensioMerchantAPI.mapCheckoutSessionResponse(session); + + assertNotNull(mapped.getSupportedTerminals()); + assertTrue(mapped.getSupportedTerminals().isEmpty()); + } + + @Test + void mapsSessionWithoutSupportedTerminalsElement() throws Exception { + String xml = XML_HEADER + + " " + + " " + + " sess-3" + + " CREATED" + + " " + + " " + + ""; + + APIResponse parsed = api.parsePostBackXMLParameter(xml); + Session session = parsed.getBody().getSession(); + CheckoutSessionResponse mapped = PensioMerchantAPI.mapCheckoutSessionResponse(session); + + assertNull(mapped.getSupportedTerminals()); + } +}