Pre-authorize a payment
1 Create a pre-authorized payment
When creating Checkout session, set the value of preAuth
property to 'y'.
The value is
y
:indicates that the current payment is pre-authorized. After the cardholder completes the authorization, the status of the payment is'uncaptured'. And you need to capture funds, the payment can be finalized.The value is
n
:indicates this is an ordinary payment and 'n'is the default value.
// Use your private key
MoneyCollect.apiKey = "test_pr_NWZsa******";
SessionCreateParams params =
SessionCreateParams.builder()
.setReturnUrl("http://localhost:4242/success.html")
.setCancelUrl("http://localhost:4242/cancel.html")
.setNotifyUrl("http://localhost:4242/success.html")
.setAmountTotal(19 * 100L)
.setCurrency("USD")
.setOrderNo("C"+System.currentTimeMillis())
.setWebsite("https://www.mc.com")
.setPreAuth(SessionCreateParams.PreAuth.YES)
.build();
Session session = Session.create(params);
When a payment is pre-authorized, but it cannot be captured or canceled in 7days, MoneyCollect will automatically cancel this payment.
2 Capture a pre-authorized payment
Use API Capture a Payment to capture payment in 'uncaptured' status.
paymentId
The ID of the payment you capture.comment
the description for capture.
// Use your private key
MoneyCollect.apiKey = "test_pr_NWZsa******";
PaymentCaptureParams params = PaymentCaptureParams.builder()
.setPaymentId("py_1451067513881452545")
.setComment("capture all")
.build();
Payment payment = Payment.capture(params);
return JSONObject.toJSONString(payment);
2. Use MoneyCollect Dashboard to capture
Capture a pre-authorized payment, only supports to capture full amount. That is to say, we don't support partially capture a payment.
3 Cancel the pre-authorization
Use API Cancel a Payment to cancel the payment in 'uncaptured' status.
paymentId
the ID of the payment you cancel.cancellationReason
The reason why you cancel the pre-authorization.
// Use your private key
MoneyCollect.apiKey = "test_pr_NWZsa******";
PaymentCancelParams params = PaymentCancelParams.builder()
.setPaymentId("py_1451067513881452545")
.setCancellationReason("I want to cancel.")
.build();
Payment payment = Payment.cancel(params);
return JSONObject.toJSONString(payment);
You can also cancel a Pre-auth payment in your MoneyCollect Dashboard.
Last updated