Skip to content

Commit c4001b2

Browse files
author
esinev
committed
Added terminalId to all requests
1 parent 326dd79 commit c4001b2

9 files changed

Lines changed: 131 additions & 6 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.payneteasy.pos.proxy.impl;
2+
3+
import com.payneteasy.android.sdk.logger.ILogger;
4+
import com.payneteasy.android.sdk.reader.inpas.config.InpasTerminalConfiguration;
5+
import com.payneteasy.android.sdk.util.LoggerUtil;
6+
import com.payneteasy.inpas.sa.client.SmartAgentClient;
7+
import com.payneteasy.inpas.sa.messages.sale.*;
8+
9+
import java.io.IOException;
10+
import java.math.BigDecimal;
11+
12+
public class InpasNetworkClientExtended {
13+
14+
private static final ILogger LOG = LoggerUtil.create(InpasNetworkClientExtended.class);
15+
16+
private final SmartAgentClient delegate;
17+
private final String address;
18+
private final InpasTerminalConfiguration configuration;
19+
20+
public InpasNetworkClientExtended(String aAddress, InpasTerminalConfiguration aConfiguration) {
21+
delegate = new SmartAgentClient(aConfiguration.createNetworkClientOptions(aAddress));
22+
address = aAddress;
23+
configuration = aConfiguration;
24+
}
25+
26+
public void connect() throws InterruptedException {
27+
while (!Thread.currentThread().isInterrupted()) {
28+
try {
29+
delegate.openConnection();
30+
return;
31+
} catch (IOException e) {
32+
if(configuration.throwExceptionIfCannotConnect()) {
33+
throw new IllegalStateException("Cannot connect to " + address, e);
34+
} else {
35+
LOG.error("Cannot connect to {}. Sleeping 1 second ...", address, e);
36+
Thread.sleep(1_000);
37+
}
38+
}
39+
}
40+
41+
}
42+
43+
public Sa1PaymentResponse makeSale(String aCurrency, BigDecimal aAmount, String aTerminalId) throws IOException {
44+
Sa1PaymentResponse saleResponse = delegate.sale(new Sa1PaymentRequest.Builder()
45+
._04_currencyCode(643)
46+
._00_amount(aAmount)
47+
._26_stan(configuration.getInvoice())
48+
._27_terminalId(aTerminalId)
49+
.build());
50+
return saleResponse;
51+
}
52+
53+
public Sa29ReversalResponse makeReversal(String aCurrency, BigDecimal aAmount, String aRrn, String aTerminalId) throws IOException {
54+
55+
Sa29ReversalRequest request = new Sa29ReversalRequest.Builder()
56+
._00_amount(aAmount)
57+
._04_currencyCode(643)
58+
._26_stan(configuration.getInvoice())
59+
._14_rrn(aRrn)
60+
._27_terminalId(aTerminalId)
61+
.build();
62+
return delegate.reversal(request);
63+
}
64+
65+
public void makeReconciliation(String aTerminalId) {
66+
try {
67+
Sa59ReconciliationResponse reconciliation = delegate.reconciliation(new Sa59ReconciliationRequest.Builder()._27_terminalId(aTerminalId).build());
68+
} catch (IOException e) {
69+
LOG.error("Cannot make reconciliation", e);
70+
}
71+
}
72+
73+
public void closeConnection() {
74+
try {
75+
delegate.close();
76+
} catch (Exception e) {
77+
LOG.error("Error while closing connection", e);
78+
}
79+
}
80+
81+
public void sendEot() {
82+
try {
83+
delegate.sendEot();
84+
} catch (Exception e) {
85+
LOG.error("Cannot send EOT", e);
86+
}
87+
}
88+
89+
public Sa26TestConnectionResponse checkConnection(String aTerminalId ) {
90+
try {
91+
LOG.debug("InpasNetworkClient; checkConnection new branch");
92+
return delegate.testConnectionToHost(aTerminalId);
93+
} catch (IOException e) {
94+
LOG.error("Error while testConnectionLocal", e);
95+
}
96+
97+
return null;
98+
}
99+
}

server/src/main/java/com/payneteasy/pos/proxy/impl/InpasNetworkManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public InpasNetworkManager(String amount, String currency, String aPosAddress) {
2424
}
2525

2626
public interface IInpasOperationHandler {
27-
PaymentResponse invokeOperation(InpasNetworkClient aClient) throws IOException;
27+
PaymentResponse invokeOperation(InpasNetworkClientExtended aClient) throws IOException;
2828
}
2929

3030
public PaymentResponse makeOperation(IInpasOperationHandler aHandler) {
31-
InpasNetworkClient client = new InpasNetworkClient(posAddress, new InpasTerminalConfiguration.Builder()
31+
InpasNetworkClientExtended client = new InpasNetworkClientExtended(posAddress, new InpasTerminalConfiguration.Builder()
3232
.packetOptions(new DefaultClientPacketOptions())
3333
.throwExceptionIfCannotConnect(true)
3434
.build()

server/src/main/java/com/payneteasy/pos/proxy/impl/PaymentServiceImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public PaymentResponse pay(PaymentRequest aRequest) {
1818
InpasNetworkManager manager = new InpasNetworkManager(aRequest.getAmount(), aRequest.getCurrency(), aRequest.getPosAddress());
1919

2020
return manager.makeOperation(aClient -> {
21-
Sa1PaymentResponse saResponse = aClient.makeSale(aRequest.getCurrency(), new BigDecimal(aRequest.getAmount()));
21+
Sa1PaymentResponse saResponse = aClient.makeSale(
22+
aRequest.getCurrency()
23+
, new BigDecimal(aRequest.getAmount())
24+
, aRequest.getTerminalId()
25+
);
2226

2327
return PaymentResponse.builder()
2428
.amount ( saResponse.get_00_amount().toString() )
@@ -34,7 +38,12 @@ public PaymentResponse refund(RefundRequest aRequest) {
3438
InpasNetworkManager manager = new InpasNetworkManager(aRequest.getRefundAmount(), aRequest.getCurrency(), aRequest.getPosAddress());
3539

3640
return manager.makeOperation(aClient -> {
37-
Sa29ReversalResponse saResponse = aClient.makeReversal(aRequest.getCurrency(), new BigDecimal(aRequest.getRefundAmount()), toRrn(aRequest.getOrderId()));
41+
Sa29ReversalResponse saResponse = aClient.makeReversal(
42+
aRequest.getCurrency()
43+
, new BigDecimal(aRequest.getRefundAmount())
44+
, toRrn(aRequest.getOrderId())
45+
, aRequest.getTerminalId()
46+
);
3847

3948
return PaymentResponse.builder()
4049
.amount ( saResponse.get_00_amount().toString() )
@@ -50,7 +59,7 @@ public CloseDayResponse closeDay(CloseDayRequest aRequest) {
5059
InpasNetworkManager manager = new InpasNetworkManager("0", "RUB", aRequest.getPosAddress());
5160

5261
PaymentResponse response = manager.makeOperation(aClient -> {
53-
aClient.makeReconciliation();
62+
aClient.makeReconciliation(aRequest.getTerminalId());
5463
return PaymentResponse.builder()
5564
.responseCode("00")
5665
.currency("RUB")

server/src/main/java/com/payneteasy/pos/proxy/messages/CloseDayRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ public class CloseDayRequest {
1212
@NonNull
1313
private final String posType;
1414

15+
private final String terminalId;
16+
1517
}

server/src/main/java/com/payneteasy/pos/proxy/messages/PaymentRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public class PaymentRequest {
1818
@NonNull
1919
private final String posType;
2020

21+
private final String terminalId;
22+
2123
}

server/src/main/java/com/payneteasy/pos/proxy/messages/RefundRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ public class RefundRequest {
2323
@NonNull
2424
private final String posType;
2525

26+
private final String terminalId;
2627
}

swagger/messages/CloseDayRequest.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ properties:
99
description: "POS terminal type"
1010
example: "INPAS"
1111

12-
1312
posAddress:
1413
type: "string"
1514
description: "POS terminal address"
1615
example: "10.0.1.20:27015"
1716

17+
terminalId:
18+
type: "string"
19+
description: "Terminal ID"
20+
example: "3A123456"

swagger/messages/PaymentRequest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ properties:
2525
description: "POS terminal address"
2626
example: "10.0.1.20:27015"
2727

28+
terminalId:
29+
type: "string"
30+
description: "Terminal ID"
31+
example: "3A123456"
32+

swagger/messages/RefundRequest.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ properties:
2828
description: "POS terminal address"
2929
example: "10.0.1.20:27015"
3030

31+
terminalId:
32+
type: "string"
33+
description: "Terminal ID"
34+
example: "3A123456"

0 commit comments

Comments
 (0)