Skip to content

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 if OTP verification is required

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:

FieldDescription
links.verifyLink to the API resource for verifying the OTP.
links.regenerateLink to the API resource for requesting a new OTP.
message.en / message.deLocalized message to display to the buyer.
regenerationPossibleInSecondsOptional waiting period, in seconds, before a new OTP can be requested.
timeToLiveInSecondsOptional validity period of the OTP, in seconds.

Verify or regenerate an OTP

The SDK provides the following methods for completing or restarting OTP verification:

MethodPurposeReturn 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.

Next steps

  • Capture a payment once authorization is accepted.
  • Learn how to handle SDK and API errors.