Some payments require the buyer to complete one-time password (OTP) verification before the authorization can be confirmed. When OTP verification is required, client.authorize() returns AuthorizeOutcome.OtpRequired instead of Accepted or Declined.
Check the authorization outcome to determine whether OTP verification is required.
switch (outcome.kind()) {
case OTP_REQUIRED -> {
var otp = (AuthorizeOutcome.OtpRequired) outcome;
System.out.println(otp.getOtpDetails().getMessage().getEn());
}
// ... ACCEPTED, DECLINED
}The returned otpDetails object contains information needed to complete the verification process:
| Field | Description |
|---|---|
links.verify | Link to the API resource for verifying the OTP. |
links.regenerate | Link to the API resource for requesting a new OTP. |
message.en / message.de | Localized message to display to the buyer. |
regenerationPossibleInSeconds | Optional waiting period, in seconds, before a new OTP can be requested. |
timeToLiveInSeconds | Optional validity period of the OTP, in seconds. |
The SDK provides the following methods for completing or restarting OTP verification:
| Method | Purpose | Return type |
|---|---|---|
verifyOtp(String, String) | Submit an OTP for verification. | OtpVerificationOutcome |
regenerateOtp(String) | Request a new OTP. | OtpRegenerationOutcome |
Both methods return typed Accepted or Declined outcomes. OTP-related errors may also throw RatepayOtpException, which includes an otpError property.