-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include refund functionality for terminal and ecom. Include QR paymen… (
#11) - Added refund functionality for terminal and ecom - Added paymentMethodType for terminal payment --------- Co-authored-by: Simon Billingsley <[email protected]>
- Loading branch information
1 parent
f3e571d
commit ce860a2
Showing
6 changed files
with
186 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,54 @@ | ||
package ecom; | ||
|
||
import com.kodypay.grpc.ecom.v1.GetPaymentsResponse.Response.PaymentDetails; | ||
import com.kodypay.grpc.ecom.v1.PaymentInitiationResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class EcomBlockingJavaClient { | ||
private static final Logger LOG = LoggerFactory.getLogger(EcomBlockingJavaClient.class.getName()); | ||
private final EcomAsyncJavaClient asyncClient; | ||
|
||
public EcomBlockingJavaClient() { | ||
asyncClient = new EcomAsyncJavaClient(); | ||
} | ||
|
||
public void sendOnlinePaymentBlocking(long amountStr) throws ExecutionException, InterruptedException, TimeoutException { | ||
asyncClient.sendPaymentAsync(amountStr).get(1, TimeUnit.MINUTES); | ||
public PaymentInitiationResponse sendOnlinePaymentBlocking(long amountStr) throws ExecutionException, InterruptedException, TimeoutException { | ||
return asyncClient.sendPaymentAsync(amountStr).get(1, TimeUnit.MINUTES); | ||
} | ||
|
||
public void requestOnlineRefund(String paymentId, long amountStr) { | ||
asyncClient.requestRefundAsync(paymentId, amountStr).thenAccept(it -> LOG.info("Requested refund response: {}", it)); | ||
} | ||
|
||
public void getPaymentsBlocking() throws ExecutionException, InterruptedException, TimeoutException { | ||
asyncClient.getPayments().get(1, TimeUnit.MINUTES); | ||
public List<PaymentDetails> getPaymentsBlocking() throws ExecutionException, InterruptedException, TimeoutException { | ||
return asyncClient.getPayments().get(1, TimeUnit.MINUTES); | ||
} | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException { | ||
EcomBlockingJavaClient ecomBlockingJavaClient = new EcomBlockingJavaClient(); | ||
|
||
long amountInPence = 100; | ||
ecomBlockingJavaClient.getPaymentsBlocking(); | ||
ecomBlockingJavaClient.sendOnlinePaymentBlocking(amountInPence); | ||
Optional<PaymentDetails> payment; | ||
PaymentInitiationResponse paymentResponse = ecomBlockingJavaClient.sendOnlinePaymentBlocking(amountInPence); | ||
|
||
// Wait for payment to be complete before refunding it | ||
do { | ||
LOG.info("Waiting for online payment to complete"); | ||
Thread.sleep(5000); | ||
payment = ecomBlockingJavaClient | ||
.getPaymentsBlocking() | ||
.stream() | ||
.filter(c -> c.getPaymentId().equals(paymentResponse.getResponse().getPaymentId())) | ||
.findFirst(); | ||
} while (payment.isEmpty() || payment.stream().allMatch(e -> e.getStatus() == PaymentDetails.PaymentStatus.PENDING)); | ||
|
||
ecomBlockingJavaClient.requestOnlineRefund(paymentResponse.getResponse().getPaymentUrl(), amountInPence); | ||
} | ||
} |
Oops, something went wrong.