Skip to content

Commit

Permalink
PBBV0-70 Add comment for show tips (#10)
Browse files Browse the repository at this point in the history
## **Associated JIRA tasks**

PBBV0-70

## **What the code does.**

Since the main functionality to have separate total amount, sale amount
and tips amount already exists, I only added a comment to make clear
what showTips does.

## **Does this code change break backwards compatibility?.**

Describe where and how this code change breaks backwards compatibility.
  • Loading branch information
ioannis-kody authored Oct 28, 2024
1 parent 326ddf0 commit f3e571d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions samples/src/main/java/terminal/TerminalJavaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import cli.Command;
import cli.PaymentCommand;
import cli.PaymentInput;
import common.PaymentClient;
import com.kodypay.grpc.pay.v1.PayResponse;
import com.kodypay.grpc.pay.v1.PaymentStatus;
import com.kodypay.grpc.pay.v1.Terminal;
import common.PaymentClient;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.impl.completer.StringsCompleter;
Expand All @@ -31,6 +31,7 @@ public class TerminalJavaClient {
private final PaymentClient client;
private String exTerminalId;
private final long timeout = 1;

public TerminalJavaClient() {
Properties properties = loadProperties();
var address = URI.create(properties.getProperty("address", "http://localhost"));
Expand All @@ -43,14 +44,10 @@ public TerminalJavaClient() {
client = new PaymentClient(address, storeId, apiKey);
}

public PayResponse sendPayment(String amountStr) throws ExecutionException, InterruptedException, TimeoutException {
return sendPayment(amountStr, false);
}

public PayResponse sendPayment(String amountStr, boolean showTips) throws ExecutionException, InterruptedException, TimeoutException {
LOG.info("Sending payment for amount: {} to terminal: {}", amountStr, exTerminalId);
BigDecimal amount = new BigDecimal(amountStr);
CompletableFuture<PayResponse> response = client.sendPayment(exTerminalId, amount, showTips, orderId-> {
CompletableFuture<PayResponse> response = client.sendPayment(exTerminalId, amount, showTips, orderId -> {
LOG.info("onPending: orderId={}", orderId);
// optionally cancel payment after delay
Executor delayed = CompletableFuture.delayedExecutor(30L, TimeUnit.SECONDS);
Expand Down Expand Up @@ -92,9 +89,7 @@ public List<Terminal> getTerminals() throws ExecutionException, InterruptedExcep
response.thenAccept(it -> {
this.exTerminalId = it.stream()
.filter(Terminal::getOnline)
.filter(t -> {
return defaultTerminalId == null || t.getTerminalId().equals(defaultTerminalId);
})
.filter(t -> defaultTerminalId == null || t.getTerminalId().equals(defaultTerminalId))
.findFirst()
.orElse(it.get(0))
.getTerminalId();
Expand All @@ -105,7 +100,9 @@ public List<Terminal> getTerminals() throws ExecutionException, InterruptedExcep
}

public static void main(String[] args) throws Exception {
String amountStr = "1.00";
String amountStr = "3.14";

//Set to true to show tips on the terminal
boolean isShowTips = false;

listTerminals();
Expand Down Expand Up @@ -152,9 +149,9 @@ public SendPaymentCommand() {
@Override
public void execute() {
listTerminals();
String orderId = null;
String orderId;
try {
orderId = terminalClient.sendPayment(String.format("%.2f", (float) input.getAmount()/100), input.isShowTips()).getOrderId();
orderId = terminalClient.sendPayment(String.format("%.2f", (float) input.getAmount() / 100), input.isShowTips()).getOrderId();
LOG.info("Completed order: {}", orderId);

var status = terminalClient.getDetails(orderId).getStatus();
Expand All @@ -169,7 +166,7 @@ public void gatherInput() {
LineReader reader = LineReaderBuilder.builder().build();
input.setAmount(Long.parseLong(reader.readLine("\nAmount (in minor units, only digits): ")));

LineReader booleanReader = LineReaderBuilder.builder().completer(new StringsCompleter("true", "false")) .build();
LineReader booleanReader = LineReaderBuilder.builder().completer(new StringsCompleter("true", "false")).build();
input.setShowTips(Boolean.parseBoolean(booleanReader.readLine("\n Do you want to enable Terminal to show Tips (true/false): ")));
}
}
Expand Down

0 comments on commit f3e571d

Please sign in to comment.