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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<String> 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`

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = 'com.altapay'
version = '3.1.14'
version = '3.1.15'

repositories {
mavenCentral()
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/pensio/api/PensioMerchantAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,20 @@ private void addTerminals(HashMap<String, String> params, List<String> terminals

private CheckoutSessionResponse checkoutSession(String apiUrl, HashMap<String, String> 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()
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/pensio/response/CheckoutSessionResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.pensio.api.SessionStatus;

import java.util.List;

public class CheckoutSessionResponse {
private String sessionId;
private SessionStatus sessionStatus;
private List<String> supportedTerminals;

public String getSessionId() {
return sessionId;
Expand All @@ -21,4 +24,12 @@ public SessionStatus getSessionStatus() {
public void setSessionStatus(SessionStatus sessionStatus) {
this.sessionStatus = sessionStatus;
}

public List<String> getSupportedTerminals() {
return supportedTerminals;
}

public void setSupportedTerminals(List<String> supportedTerminals) {
this.supportedTerminals = supportedTerminals;
}
}
7 changes: 7 additions & 0 deletions src/main/resources/xsd/APIResponse.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@
<xs:all>
<xs:element name="Id" type="xs:string"/>
<xs:element name="Status" type="xs:string"/>
<xs:element name="SupportedTerminals" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Terminal" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>

Expand Down
90 changes: 90 additions & 0 deletions src/test/java/com/pensio/api/CheckoutSessionResponseParseTest.java
Original file line number Diff line number Diff line change
@@ -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 =
"<?xml version=\"1.0\"?>" +
"<APIResponse version=\"20260519\">" +
" <Header>" +
" <Date>2026-05-19T11:00:00+00:00</Date>" +
" <Path>API/createCheckoutSession</Path>" +
" <ErrorCode>0</ErrorCode>" +
" <ErrorMessage>Success</ErrorMessage>" +
" </Header>";

private final PensioMerchantAPI api = new PensioMerchantAPI("url", "u", "p");

@Test
void mapsSessionWithPopulatedSupportedTerminals() throws Exception {
String xml = XML_HEADER +
" <Body>" +
" <Session>" +
" <Id>sess-1</Id>" +
" <Status>CREATED</Status>" +
" <SupportedTerminals>" +
" <Terminal>terminal-a</Terminal>" +
" <Terminal>terminal-b</Terminal>" +
" </SupportedTerminals>" +
" </Session>" +
" </Body>" +
"</APIResponse>";

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 +
" <Body>" +
" <Session>" +
" <Id>sess-2</Id>" +
" <Status>CREATED</Status>" +
" <SupportedTerminals/>" +
" </Session>" +
" </Body>" +
"</APIResponse>";

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 +
" <Body>" +
" <Session>" +
" <Id>sess-3</Id>" +
" <Status>CREATED</Status>" +
" </Session>" +
" </Body>" +
"</APIResponse>";

APIResponse parsed = api.parsePostBackXMLParameter(xml);
Session session = parsed.getBody().getSession();
CheckoutSessionResponse mapped = PensioMerchantAPI.mapCheckoutSessionResponse(session);

assertNull(mapped.getSupportedTerminals());
}
}
Loading