Skip to content

Commit

Permalink
Added terminalId to all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
esinev committed Jul 4, 2023
1 parent 326dd79 commit c4001b2
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.payneteasy.pos.proxy.impl;

import com.payneteasy.android.sdk.logger.ILogger;
import com.payneteasy.android.sdk.reader.inpas.config.InpasTerminalConfiguration;
import com.payneteasy.android.sdk.util.LoggerUtil;
import com.payneteasy.inpas.sa.client.SmartAgentClient;
import com.payneteasy.inpas.sa.messages.sale.*;

import java.io.IOException;
import java.math.BigDecimal;

public class InpasNetworkClientExtended {

private static final ILogger LOG = LoggerUtil.create(InpasNetworkClientExtended.class);

private final SmartAgentClient delegate;
private final String address;
private final InpasTerminalConfiguration configuration;

public InpasNetworkClientExtended(String aAddress, InpasTerminalConfiguration aConfiguration) {
delegate = new SmartAgentClient(aConfiguration.createNetworkClientOptions(aAddress));
address = aAddress;
configuration = aConfiguration;
}

public void connect() throws InterruptedException {
while (!Thread.currentThread().isInterrupted()) {
try {
delegate.openConnection();
return;
} catch (IOException e) {
if(configuration.throwExceptionIfCannotConnect()) {
throw new IllegalStateException("Cannot connect to " + address, e);
} else {
LOG.error("Cannot connect to {}. Sleeping 1 second ...", address, e);
Thread.sleep(1_000);
}
}
}

}

public Sa1PaymentResponse makeSale(String aCurrency, BigDecimal aAmount, String aTerminalId) throws IOException {
Sa1PaymentResponse saleResponse = delegate.sale(new Sa1PaymentRequest.Builder()
._04_currencyCode(643)
._00_amount(aAmount)
._26_stan(configuration.getInvoice())
._27_terminalId(aTerminalId)
.build());
return saleResponse;
}

public Sa29ReversalResponse makeReversal(String aCurrency, BigDecimal aAmount, String aRrn, String aTerminalId) throws IOException {

Sa29ReversalRequest request = new Sa29ReversalRequest.Builder()
._00_amount(aAmount)
._04_currencyCode(643)
._26_stan(configuration.getInvoice())
._14_rrn(aRrn)
._27_terminalId(aTerminalId)
.build();
return delegate.reversal(request);
}

public void makeReconciliation(String aTerminalId) {
try {
Sa59ReconciliationResponse reconciliation = delegate.reconciliation(new Sa59ReconciliationRequest.Builder()._27_terminalId(aTerminalId).build());
} catch (IOException e) {
LOG.error("Cannot make reconciliation", e);
}
}

public void closeConnection() {
try {
delegate.close();
} catch (Exception e) {
LOG.error("Error while closing connection", e);
}
}

public void sendEot() {
try {
delegate.sendEot();
} catch (Exception e) {
LOG.error("Cannot send EOT", e);
}
}

public Sa26TestConnectionResponse checkConnection(String aTerminalId ) {
try {
LOG.debug("InpasNetworkClient; checkConnection new branch");
return delegate.testConnectionToHost(aTerminalId);
} catch (IOException e) {
LOG.error("Error while testConnectionLocal", e);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public InpasNetworkManager(String amount, String currency, String aPosAddress) {
}

public interface IInpasOperationHandler {
PaymentResponse invokeOperation(InpasNetworkClient aClient) throws IOException;
PaymentResponse invokeOperation(InpasNetworkClientExtended aClient) throws IOException;
}

public PaymentResponse makeOperation(IInpasOperationHandler aHandler) {
InpasNetworkClient client = new InpasNetworkClient(posAddress, new InpasTerminalConfiguration.Builder()
InpasNetworkClientExtended client = new InpasNetworkClientExtended(posAddress, new InpasTerminalConfiguration.Builder()
.packetOptions(new DefaultClientPacketOptions())
.throwExceptionIfCannotConnect(true)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public PaymentResponse pay(PaymentRequest aRequest) {
InpasNetworkManager manager = new InpasNetworkManager(aRequest.getAmount(), aRequest.getCurrency(), aRequest.getPosAddress());

return manager.makeOperation(aClient -> {
Sa1PaymentResponse saResponse = aClient.makeSale(aRequest.getCurrency(), new BigDecimal(aRequest.getAmount()));
Sa1PaymentResponse saResponse = aClient.makeSale(
aRequest.getCurrency()
, new BigDecimal(aRequest.getAmount())
, aRequest.getTerminalId()
);

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

return manager.makeOperation(aClient -> {
Sa29ReversalResponse saResponse = aClient.makeReversal(aRequest.getCurrency(), new BigDecimal(aRequest.getRefundAmount()), toRrn(aRequest.getOrderId()));
Sa29ReversalResponse saResponse = aClient.makeReversal(
aRequest.getCurrency()
, new BigDecimal(aRequest.getRefundAmount())
, toRrn(aRequest.getOrderId())
, aRequest.getTerminalId()
);

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

PaymentResponse response = manager.makeOperation(aClient -> {
aClient.makeReconciliation();
aClient.makeReconciliation(aRequest.getTerminalId());
return PaymentResponse.builder()
.responseCode("00")
.currency("RUB")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class CloseDayRequest {
@NonNull
private final String posType;

private final String terminalId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public class PaymentRequest {
@NonNull
private final String posType;

private final String terminalId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class RefundRequest {
@NonNull
private final String posType;

private final String terminalId;
}
5 changes: 4 additions & 1 deletion swagger/messages/CloseDayRequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ properties:
description: "POS terminal type"
example: "INPAS"


posAddress:
type: "string"
description: "POS terminal address"
example: "10.0.1.20:27015"

terminalId:
type: "string"
description: "Terminal ID"
example: "3A123456"
5 changes: 5 additions & 0 deletions swagger/messages/PaymentRequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ properties:
description: "POS terminal address"
example: "10.0.1.20:27015"

terminalId:
type: "string"
description: "Terminal ID"
example: "3A123456"

4 changes: 4 additions & 0 deletions swagger/messages/RefundRequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ properties:
description: "POS terminal address"
example: "10.0.1.20:27015"

terminalId:
type: "string"
description: "Terminal ID"
example: "3A123456"

0 comments on commit c4001b2

Please sign in to comment.