Skip to content

Commit

Permalink
PR Review
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannis-kody committed Dec 12, 2024
1 parent 07d3c60 commit 052ba8e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
69 changes: 41 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ Every client library request authenticates with the server using a `storeId` and
Example:
````java
String storeId = "UUID of assigned store"; // STORE_ID
PaymentClient api = new PaymentClient(HOSTNAME, API_KEY);
TerminalsResponse response = api.terminals(storeId);
PaymentClient paymentClient = new PaymentClient(HOSTNAME, API_KEY);

TerminalsRequest terminalsRequest = TerminalsRequest.newBuilder()
.setStoreId(storeId)
.build();

List<Terminal> response = paymentClient.getTerminals(terminalsRequest);
````

Replace the `STORE_ID`, `API_KEY` and `HOSTNAME` with the details provided by the Kody team.
Expand Down Expand Up @@ -315,7 +320,7 @@ String orderId = "UUID of order generated by Kody";

CancelRequest cancelRequest = CancelRequest.newBuilder()
.setStoreId(storeId)
.setAmount(amount.toPlainString())
.setAmount(amount)
.setTerminalId(terminalId)
.setOrderId(orderId)
.build();
Expand Down Expand Up @@ -406,20 +411,19 @@ Send a payment initiation request for an online payment. Returns an object with

#### PayRequest - Payment Request
```java
public class PayRequest {
private String amount = null;
private Boolean showTips = null;
private PaymentMethod paymentMethod = null;
}

public class PaymentMethod {
private PaymentMethodType paymentMethodType = null;
public class PaymentInitiationRequest {
private String storeId = "UUID of assigned store";
private String orderId = "UUID of order generated by Kody";
private String paymentReference = "UUID generated for the request with 'pay_' appended: pay_UUID";
private String amount = "1.00";
private String currency = "GBP";
private String returnUrl = "returnUrl";
private ExpirySettings expirySettings;
}

public enum PaymentMethodType {
CARD("CARD"),
ALIPAY("ALIPAY"),
WECHAT("WECHAT")
public class ExpirySettings {
private bool showTimer;
private int expiringSeconds;
}
```

Expand All @@ -430,8 +434,9 @@ Request parameters:
- `currency` - the currency for this payment in 3 character ISO format, such as `GBP`
- `order_id` - a unique order ID for this payment, sent from the client and returned by the server
- `return_url` - where the payment form will redirect to after the payment has completed, the return url will have additional query parameters appended to indicate the status of the payment request.
- `showTimer` - flag to show countdown timer in payment page
- `expiry` - how long the payment form will wait until the payment expires and the page will redirect to the return url
- `expiry` - (optional) setting expiry settings
- `showTimer` - (optional) flag to show countdown timer in payment page
- `expiringSeconds` - (optional) how long the payment form will wait until the payment expires and the page will redirect to the return url


#### PayResponse : Payment Response
Expand Down Expand Up @@ -468,12 +473,15 @@ import com.kodypay.grpc.pay.v1.*;
PaymentClient paymentClient = new PaymentClient(HOSTNAME, APIKEY);

String storeId = "UUID of assigned store";
String orderId = "UUID of assigned store";
String paymentReference = "payment reference";
String orderId = "UUID of order generated by Kody";
String paymentReference = "UUID generated for the request with 'pay_' appended: pay_UUID";
String amount = "1.00";
String currency = "GBP";
String returnUrl = "returnUrl";
int expiringSeconds = 1800;
ExpirySettings expirySettings = PaymentInitiationRequest.ExpirySettings.newBuilder()
.setShowTimer(true)
.setExpiringSeconds(1800)
.build();

PaymentInitiationRequest paymentInitiationRequest = PaymentInitiationRequest.newBuilder()
.setStoreId(storeId)
Expand All @@ -482,11 +490,8 @@ PaymentInitiationRequest paymentInitiationRequest = PaymentInitiationRequest.new
.setCurrency(currency)
.setOrderId(orderId)
.setReturnUrl(returnUrl)
.setExpiry(PaymentInitiationRequest.ExpirySettings.newBuilder()
.setShowTimer(true)
.setExpiringSeconds(expiringSeconds)
.build()
).build();
.setExpiry(expirySettings)
.build();

PaymentInitiationResponse response = paymentClient.sendOnlinePayment(paymentInitiationRequest);
````
Expand All @@ -495,14 +500,19 @@ PaymentInitiationResponse response = paymentClient.sendOnlinePayment(paymentInit

The payment details request requires the following parameters:
- `storeId` - the ID of your assigned store
- `pageCursor` - the Order ID returned in the initial payment response, a unique UUID value for each payment.
- `pageCursor` - set pagination settings

#### GetPaymentsRequest: Get Payments Request
````java
public class PaymentDetailsRequest {
private String storeId;
private PageCursor pageCursor;
}

public class PageCursor {
private int page;
private int pageSize;
}
````
#### PaymentDetails: Payment Details
````java
Expand All @@ -526,10 +536,13 @@ import com.kodypay.grpc.pay.v1.*;
PaymentClient paymentClient = new PaymentClient(HOSTNAME, APIKEY);

String storeId = "UUID of assigned store";
PageCursor pageCursor = PageCursor.newBuilder()
.setPageSize(1)
.build();

GetPaymentsRequest getPaymentsRequest = GetPaymentsRequest.newBuilder()
.setStoreId(storeId)
.setPageCursor(PageCursor.newBuilder().setPageSize(1).build())
.setPageCursor(pageCursor)
.build();

List<PaymentDetails> response = paymentClient.getPayments(getPaymentsRequest);
Expand Down Expand Up @@ -587,7 +600,7 @@ String amount = "1.00";
RefundRequest refundRequest = RefundRequest.newBuilder()
.setStoreId(storeId)
.setPaymentId(paymentId)
.setAmount(String.valueOf(amount))
.setAmount(amount)
.build();

RefundResponse response = paymentClient.requestOnlineRefund(refundRequest);
Expand Down
3 changes: 2 additions & 1 deletion samples/src/main/java/terminal/TerminalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public PaymentStatus cancelPayment(String amountStr, String orderId) {
}

public RefundResponse requestRefund(String amountStr, String orderId) throws InterruptedException {
Thread.sleep(5000);
LOG.info("Requesting refund for amount: {} for orderId: {}", amountStr, orderId);

BigDecimal amount = new BigDecimal(amountStr);
Expand Down Expand Up @@ -147,6 +146,7 @@ public static void main(String[] args) throws Exception {
var status = terminalClient.getDetails(orderId).getStatus();
LOG.info("Payment status: {}", status);

Thread.sleep(5000);
var refundStatus = terminalClient.requestRefund(amountStr, orderId).getStatus();
LOG.info("Refund status: {}", refundStatus);

Expand Down Expand Up @@ -201,6 +201,7 @@ public void execute() {
var status = terminalClient.getDetails(orderId).getStatus();
LOG.info("Payment status: {}", status);

Thread.sleep(5000);
var refundStatus = terminalClient.requestRefund(String.format("%.2f", (float) input.getAmount() / 100), orderId).getStatus();
LOG.info("Refund status: {}", refundStatus);
} catch (Exception e) {
Expand Down

0 comments on commit 052ba8e

Please sign in to comment.