Skip to content

Commit ad09be4

Browse files
[COREP-5017] add new methods to Merchant API createCheckoutSession and updateCheckoutSession
* [COREP-5017] add new methods to Merchant API `createCheckoutSession` and `updateCheckoutSession` * [COREP-4962] fix wallet session data in model * [COREP-5017] separate requests for create and update of checkoutSession * [COREP-5017] removed redundant parameter --------- Co-authored-by: Kamil Binkowski <kamilb@altapay.com>
1 parent 36ce7c5 commit ad09be4

9 files changed

Lines changed: 161 additions & 60 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [3.1.0]
5-
6-
- Enhanced interface of the endpoint cardWallet/session to pass create payment request params
4+
## [3.1.2]
5+
- Added new methods to Merchant API `createCheckoutSession` and `updateCheckoutSession`
6+
- Enhanced interface of the endpoint cardWallet/session to pass create payment request params
77

88
## [3.0.3]
99

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = 'com.altapay'
11-
version = '3.1.0'
11+
version = '3.1.2'
1212

1313
repositories {
1414
mavenCentral()

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ For integrating Java projects with the AltaPay gateway.
4949
<dependency>
5050
<groupId>com.altapay</groupId>
5151
<artifactId>sdk-java</artifactId>
52-
<version>3.1.0</version>
52+
<version>3.1.2</version>
5353
</dependency>
5454
5555
### Gradle
5656
57-
implementation 'com.altapay:sdk-java:3.1.0'
57+
implementation 'com.altapay:sdk-java:3.1.2'
5858
5959
## Changelog
6060

src/main/java/com/pensio/api/PensioMerchantAPI.java

Lines changed: 92 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import com.pensio.Amount;
55
import com.pensio.TaxType;
66
import com.pensio.api.generated.APIResponse;
7+
import com.pensio.api.generated.Session;
78
import com.pensio.api.request.*;
89

10+
import com.pensio.response.CheckoutSessionResponse;
911
import jakarta.xml.bind.JAXBElement;
1012
import jakarta.xml.bind.JAXBException;
1113

@@ -29,21 +31,20 @@ public PensioMerchantAPI(String baseURL, String username, String password)
2931
public boolean login() throws PensioAPIException
3032
{
3133
APIResponse response = getAPIResponse("login",
32-
HttpMethod.POST,
33-
new HashMap<String, String>());
34+
HttpMethod.POST,
35+
new HashMap<>());
3436
return "OK".equals(response.getBody().getResult());
3537
}
3638

3739
public PaymentRequestResponse createPaymentRequest(PaymentRequest paymentRequest) throws PensioAPIException
3840
{
3941
try
4042
{
41-
HashMap<String, String> params = new HashMap<String, String>();
43+
HashMap<String, String> params = new HashMap<>();
4244
setPaymentRequestParameters(paymentRequest, params);
4345

4446
APIResponse response = getAPIResponse("createPaymentRequest", HttpMethod.POST, params);
4547

46-
4748
PaymentRequestResponseImpl paymentRequestResponseImpl = new PaymentRequestResponseImpl()
4849
.setUrl(new URL(response.getBody().getUrl()))
4950
.setPaymentRequestId(response.getBody().getPaymentRequestId());
@@ -58,12 +59,11 @@ public PaymentRequestResponse createPaymentRequest(PaymentRequest paymentRequest
5859
{
5960
throw new PensioAPIException(e);
6061
}
61-
6262
}
6363

6464
public APIResponse createInvoiceReservation(CreateInvoiceReservationRequest request) throws PensioAPIException
6565
{
66-
HashMap<String, String> params = new HashMap<String, String>();
66+
HashMap<String, String> params = new HashMap<>();
6767

6868
setInvoiceReservationRequestParameters(request, params);
6969

@@ -72,7 +72,7 @@ public APIResponse createInvoiceReservation(CreateInvoiceReservationRequest requ
7272

7373
public APIResponse updateOrder(UpdateOrderRequest request) throws PensioAPIException
7474
{
75-
HashMap<String, String> params = new HashMap<String, String>();
75+
HashMap<String, String> params = new HashMap<>();
7676

7777
setUpdateOrderRequestParameters (request, params);
7878

@@ -81,7 +81,7 @@ public APIResponse updateOrder(UpdateOrderRequest request) throws PensioAPIExcep
8181

8282
public APIResponse reservation(PaymentReservationRequest request) throws PensioAPIException
8383
{
84-
HashMap<String, String> params = new HashMap<String, String>();
84+
HashMap<String, String> params = new HashMap<>();
8585
setPaymentRequestParameters(request, params);
8686
setCreditCardRequestParameters(request, params);
8787
setPaymentSource(request, params);
@@ -98,33 +98,33 @@ private void setPaymentSource(PaymentReservationRequest request,
9898
}
9999
}
100100

101-
public APIResponse capture(CaptureReservationRequest request) throws PensioAPIException
101+
public APIResponse capture(CaptureReservationRequest request) throws PensioAPIException
102102
{
103-
HashMap<String, String> params = new HashMap<String, String>();
103+
HashMap<String, String> params = new HashMap<>();
104104
addParam(params, "transaction_id", request.getTransactionId());
105105
addParam(params, "amount", request.getAmountString());
106106
addParam(params, "reconciliation_identifier", request.getReconciliationIdentifier());
107107
addParam(params, "invoice_number", request.getInvoiceNumber());
108108
addParam(params, "sales_tax", request.getSalesTax());
109109
OrderLine[] orderLines = request.getOrderLines();
110-
addOrderLines("orderLines", params, Arrays.asList(orderLines));
110+
addOrderLines("orderLines", params, Arrays.asList(orderLines));
111111
return getAPIResponse("captureReservation", HttpMethod.POST, params);
112112
}
113113

114-
public APIResponse refund(RefundRequest request) throws PensioAPIException
114+
public APIResponse refund(RefundRequest request) throws PensioAPIException
115115
{
116-
HashMap<String, String> params = new HashMap<String, String>();
116+
HashMap<String, String> params = new HashMap<>();
117117
addParam(params, "transaction_id", request.getPaymentId());
118118
addParam(params, "amount", request.getAmountString());
119119
addParam(params, "reconciliation_identifier", request.getReconciliationIdentifier());
120120
OrderLine[] orderLines = request.getOrderLines();
121-
addOrderLines("orderLines", params, Arrays.asList(orderLines));
121+
addOrderLines("orderLines", params, Arrays.asList(orderLines));
122122
return getAPIResponse("refundCapturedReservation", HttpMethod.POST, params);
123123
}
124-
125-
public APIResponse chargeSubscription(ChargeSubscriptionRequest request) throws PensioAPIException
124+
125+
public APIResponse chargeSubscription(ChargeSubscriptionRequest request) throws PensioAPIException
126126
{
127-
HashMap<String, String> params = new HashMap<String, String>();
127+
HashMap<String, String> params = new HashMap<>();
128128
addParam(params, "agreement[id]", request.getAgreementId());
129129
addParam(params, "amount", request.getAmountString());
130130
addParam(params, "reconciliation_identifier", request.getReconciliationIdentifier());
@@ -153,10 +153,10 @@ public APIResponse chargeSubscription(ChargeSubscriptionRequest request) throws
153153

154154
return getAPIResponse("chargeSubscription", HttpMethod.POST, params);
155155
}
156-
157-
public APIResponse reserveSubscriptionCharge(ReserveSubscriptionChargeRequest request) throws PensioAPIException
156+
157+
public APIResponse reserveSubscriptionCharge(ReserveSubscriptionChargeRequest request) throws PensioAPIException
158158
{
159-
HashMap<String, String> params = new HashMap<String, String>();
159+
HashMap<String, String> params = new HashMap<>();
160160
addParam(params, "agreement[id]", request.getAgreementId());
161161
addParam(params, "amount", request.getAmountString());
162162

@@ -184,36 +184,36 @@ public APIResponse reserveSubscriptionCharge(ReserveSubscriptionChargeRequest re
184184

185185
return getAPIResponse("reserveSubscriptionCharge", HttpMethod.POST, params);
186186
}
187-
188-
public APIResponse fundingList(FundingListRequest request) throws PensioAPIException
187+
188+
public APIResponse fundingList(FundingListRequest request) throws PensioAPIException
189189
{
190-
HashMap<String, String> params = new HashMap<String, String>();
190+
HashMap<String, String> params = new HashMap<>();
191191
addParam(params, "page", String.valueOf(request.getPage()));
192-
192+
193193
return getAPIResponse("fundingList", HttpMethod.GET, params);
194194
}
195195

196196
public APIResponse getTerminals() throws PensioAPIException {
197-
return getAPIResponse("getTerminals", HttpMethod.GET, new HashMap<String, String>());
197+
return getAPIResponse("getTerminals", HttpMethod.GET, new HashMap<>());
198198
}
199-
199+
200200
public List<FundingRecord> downloadFunding(String downloadLink) throws PensioAPIException
201201
{
202202
try
203203
{
204-
InputStream inStream = this.httpHelper.doPost(downloadLink, new HashMap<String, String>(), username, password, getSdkVersion());
204+
InputStream inStream = this.httpHelper.doPost(downloadLink, new HashMap<>(), username, password, getSdkVersion());
205205

206206
CsvReader reader = new CsvReader(inStream,';', Charset.forName("UTF-8"));
207-
ArrayList<FundingRecord> result = new ArrayList<FundingRecord>();
208-
207+
ArrayList<FundingRecord> result = new ArrayList<>();
208+
209209
if(reader.readHeaders())
210210
{
211211
while(reader.readRecord())
212212
{
213213
FundingRecord record = new FundingRecord();
214214
String date = reader.get("Date");
215215
System.out.println("Date: "+date);
216-
216+
217217
if (date.matches("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
218218
{
219219
record.setFundingDate(DateHelper.parseDate("yyyy-MM-dd hh:mm:ss", date));
@@ -222,7 +222,7 @@ public List<FundingRecord> downloadFunding(String downloadLink) throws PensioAPI
222222
{
223223
record.setFundingDate(DateHelper.parseDate("yyyy-MM-dd", date));
224224
}
225-
225+
226226
record.setRecordType(reader.get("Type"));
227227
record.setId(reader.get("ID"));
228228
record.setReconciliationIdentifier(reader.get("Reconciliation Identifier"));
@@ -232,7 +232,7 @@ public List<FundingRecord> downloadFunding(String downloadLink) throws PensioAPI
232232
record.setShop(reader.get("Shop"));
233233
record.setPaymentAmount(Amount.get(reader.get("Transaction Amount"), reader.get("Transaction Currency")));
234234
record.setFundingAmount(Amount.get(reader.get("Settlement Amount"), reader.get("Settlement Currency")));
235-
235+
236236
String exRate = reader.get("Exchange Rate");
237237
if (exRate == null || exRate.length() == 0)
238238
{
@@ -242,38 +242,37 @@ public List<FundingRecord> downloadFunding(String downloadLink) throws PensioAPI
242242
{
243243
record.setExchangeRate(Double.parseDouble(exRate));
244244
}
245-
245+
246246
record.setFixedFeeAmount(Amount.get(reader.get("Fixed Fee"), reader.get("Settlement Currency")));
247247
record.setFixedFeeVatAmount(Amount.get(reader.get("Fixed Fee VAT"), reader.get("Settlement Currency")));
248248
record.setRateBasedFeeAmount(Amount.get(reader.get("Rate Based Fee"), reader.get("Settlement Currency")));
249249
record.setRateBasedFeeVatAmount(Amount.get(reader.get("Rate Based Fee VAT"), reader.get("Settlement Currency")));
250-
250+
251251
result.add(record);
252-
252+
253253
}
254254
}
255255
reader.close();
256-
257-
256+
258257
return result;
259258
}
260259
catch (Exception e)
261260
{
262261
throw new PensioAPIException(e);
263262
}
264263
}
265-
266-
public APIResponse release(ReleaseReservationRequest request) throws PensioAPIException
264+
265+
public APIResponse release(ReleaseReservationRequest request) throws PensioAPIException
267266
{
268-
HashMap<String, String> params = new HashMap<String, String>();
267+
HashMap<String, String> params = new HashMap<>();
269268
addParam(params, "transaction_id", request.getPaymentId());
270-
269+
271270
return getAPIResponse("releaseReservation", HttpMethod.POST, params);
272271
}
273-
274-
public APIResponse queryGiftCard(PaymentReservationRequest request) throws PensioAPIException
272+
273+
public APIResponse queryGiftCard(PaymentReservationRequest request) throws PensioAPIException
275274
{
276-
HashMap<String, String> params = new HashMap<String, String>();
275+
HashMap<String, String> params = new HashMap<>();
277276
if (request.getGiftCard() == null){
278277
addParam(params, "terminal", request.getTerminal());
279278
addParam(params, "giftcard[token]", request.getGiftCardToken());
@@ -285,22 +284,22 @@ public APIResponse queryGiftCard(PaymentReservationRequest request) throws Pensi
285284

286285
return getAPIResponse("queryGiftCard", HttpMethod.POST, params);
287286
}
288-
287+
289288
private void setCreditCardRequestParameters(
290289
PaymentReservationRequest request, HashMap<String, String> params)
291290
{
292291
if(request.getCreditCard() == null)
293292
{
294293
return;
295294
}
296-
295+
297296
addParam(params, "credit_card_token", request.getCreditCard().getToken());
298297
addParam(params, "cardnum", request.getCreditCard().getCardNumber());
299298
addParam(params, "emonth", request.getCreditCard().getExpiryMonth());
300299
addParam(params, "eyear", request.getCreditCard().getExpiryYear());
301-
300+
302301
addParam(params, "cvc", request.getCreditCard().getCvc());
303-
302+
304303
}
305304

306305
protected void setPaymentRequestParameters(
@@ -434,8 +433,7 @@ protected APIResponse getAPIResponse(String method,
434433
{
435434
throw new PensioAPIException(response.getHeader());
436435
}
437-
438-
436+
439437
return response;
440438
}
441439
catch (Exception e)
@@ -448,7 +446,7 @@ public PaymentRequestResponse createMultiPaymentRequest(MultiPaymentRequestParen
448446
{
449447
try
450448
{
451-
HashMap<String, String> params = new HashMap<String, String>();
449+
HashMap<String, String> params = new HashMap<>();
452450
setMultiPaymentRequestParameters(multiPaymentRequest, params);
453451

454452
APIResponse response = getAPIResponse("createMultiPaymentRequest", HttpMethod.POST, params);
@@ -485,7 +483,7 @@ public APIResponse parsePostBackXMLParameter(String xmlParameter) throws PensioA
485483

486484
public APIResponse transactions(TransactionsRequest request) throws PensioAPIException
487485
{
488-
HashMap<String, String> params = new HashMap<String, String>();
486+
HashMap<String, String> params = new HashMap<>();
489487
addParam(params, "transaction_id", request.getPaymentId());
490488

491489
return getAPIResponse("payments", HttpMethod.GET, params);
@@ -672,7 +670,7 @@ public APIResponse cardWalletSession(CardWalletSessionRequest request) throws Pe
672670

673671
public APIResponse cardWalletAuthorize(CardWalletAuthorizeRequest request) throws PensioAPIException
674672
{
675-
HashMap<String, String> params = new HashMap<String, String>();
673+
HashMap<String, String> params = new HashMap<>();
676674
addParam(params, "provider_data", request.getProviderData());
677675
addParam(params, "sale_reconciliation_identifier", request.getSaleReconciliationIdentifier());
678676
addParam(params, "sale_invoice_number", request.getSaleInvoiceNumber());
@@ -683,6 +681,47 @@ public APIResponse cardWalletAuthorize(CardWalletAuthorizeRequest request) throw
683681
return getAPIResponse("cardWallet/authorize", HttpMethod.POST, params);
684682
}
685683

684+
public CheckoutSessionResponse createCheckoutSession(CreateCheckoutSessionRequest createCheckoutSessionRequest) throws PensioAPIException
685+
{
686+
String apiUrl = "checkoutSession";
687+
688+
HashMap<String, String> params = new HashMap<>();
689+
if (createCheckoutSessionRequest != null && createCheckoutSessionRequest.getSessionId() != null) {
690+
addParam(params, "session_id", createCheckoutSessionRequest.getSessionId());
691+
}
692+
693+
return checkoutSession(apiUrl, params);
694+
}
695+
696+
public CheckoutSessionResponse updateCheckoutSession(UpdateCheckoutSessionRequest updateCheckoutSessionRequest) throws PensioAPIException
697+
{
698+
if (updateCheckoutSessionRequest == null || updateCheckoutSessionRequest.sessionId() == null) {
699+
throw new PensioAPIException("updateCheckoutSessionRequest.sessionId cannot be null for updateCheckoutSession");
700+
}
701+
if (updateCheckoutSessionRequest.status() == null) {
702+
throw new PensioAPIException("updateCheckoutSessionRequest.sessionStatus cannot be null for updateCheckoutSession");
703+
}
704+
705+
String apiUrl = "checkoutSession/" + updateCheckoutSessionRequest.sessionId();
706+
707+
HashMap<String, String> params = new HashMap<>();
708+
addParam(params, "session_status", updateCheckoutSessionRequest.status().name());
709+
710+
return checkoutSession(apiUrl, params);
711+
}
712+
713+
private CheckoutSessionResponse checkoutSession(String apiUrl, HashMap<String, String> params) throws PensioAPIException {
714+
APIResponse response = getAPIResponse(apiUrl, HttpMethod.POST, params);
715+
716+
CheckoutSessionResponse checkoutSessionResponse = new CheckoutSessionResponse();
717+
if (response.getBody().getSession() != null) {
718+
Session session = response.getBody().getSession();
719+
checkoutSessionResponse.setSessionId(session.getId());
720+
checkoutSessionResponse.setSessionStatus(SessionStatus.valueOf(session.getStatus()));
721+
}
722+
return checkoutSessionResponse;
723+
}
724+
686725
protected String getAppAPIPath()
687726
{
688727
return "merchant/API/";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.pensio.api;
2+
3+
public enum SessionStatus {
4+
Created,
5+
Completed,
6+
Expired
7+
}

0 commit comments

Comments
 (0)