Skip to main content
private fun onOtplessResponse(response: OtplessResponse) {
    OtplessSDK.commit(response)
    when (response.responseType) {
        ResponseTypes.SDK_READY -> {
            // SDK has been initialized successfully, you may enable your continue button or proceed with user authentication.
        }
        ResponseTypes.FAILED -> {
            // Notify that the initialization failed
            if (response.statusCode == 5003) {
                // SDK initialization failed, please try to initialize the SDK again
            }
        }
        ResponseTypes.INITIATE -> {
            // notify that authentication has been initiated
            if (response.statusCode != 200) {
                handleInitiateError(response);
            } else {
                val authType = response.response?.optString("authType") // This is the authentication type
                if (authType == "OTP") {
                    // Take user to OTP verification screen
                } else if (authType == "SILENT_AUTH") {
                    // Handle Silent Authentication initiation by showing loading status for SNA flow.
                }
            }
        }
        ResponseTypes.OTP_AUTO_READ -> {
            val otp = response.response?.optString("otp")
            if (!otp.isNullOrBlank()) {
                // Autofill the OTP in your TextField/EditText
            }
        }
        ResponseTypes.VERIFY -> {
            // notify that verification has failed.
            if (response.response?.optString("authType") == "SILENT_AUTH") {
                if (response.statusCode == 9106) {
                    // Silent Authentication and all fallback authentication methods in SmartAuth have failed.
                    // The transaction cannot proceed further.
                    //  The transaction cannot proceed further. Handle the scenario to gracefully exit the authentication flow
                } else {
                    // Silent Authentication failed. If SmartAuth is enabled, the INITIATE response will include the next available authentication method configured in the dashboard.
                }
            } else {
                handleVerifyError(response)
            }
        }
        ResponseTypes.DELIVERY_STATUS -> {
            // This function is called when delivery is successful for your authType.
            val authType = response.response?.optString("authType") 
            // It is the authentication type (OTP, MAGICLINK, OTP_LINK) for which the delivery status is being sent
            val deliveryChannel = response.response?.optString("deliveryChannel")
            // It is the delivery channel (SMS, WHATSAPP, etc) on which the authType has been delivered
        }
        ResponseTypes.FALLBACK_TRIGGERED -> {
        // A fallback occurs when an OTP delivery attempt on one channel fails,  
        // and the system automatically retries via the subsequent channel selected on Otpless Dashboard.  
        // For example, if a merchant opts for SmartAuth with primary channal as WhatsApp and secondary channel as SMS,
        // in that case, if OTP delivery on WhatsApp fails, the system will automatically retry via SMS.
        // The response will contain the deliveryChannel to which the OTP has been sent.

        if (response.response != null) {
                val newDeliveryChannel = response.response.optString("deliveryChannel"); // This is the deliveryChannel to which the OTP has been sent
            }
        }
        ResponseTypes.ONETAP -> {
            // final response with token
            val token = response.response?.optJSONObject("data")?.optString("token")
            if (!token.isNullOrBlank()) {
                // Process token and proceed.
            }
        }
        ResponseTypes.AUTH_TERMINATED -> {
            // This state indicates that the authentication process was terminated due to a Failure.
        }
    }
}

AUTH_TERMINATED

This state indicates that the authentication process was forcefully stopped due to an expected failure during the flow.

Auth Terminated Flow

This sequence represents the OTPless SDK authentication flow. After the user enters their phone number, the Merchant App initiates the request. The SDK evaluates the response, and if a terminal error occurs during initiation—or if SNA fails with no fallback—it returns AUTH_TERMINATED. otpless overview