Overview

The OTP Code feature allows you to implement secure one-time password authentication through WhatsApp. This provides a familiar and secure way for users to verify their identity during login, registration, or sensitive operations.

How It Works

  1. Your application requests an OTP code to be sent to a user’s WhatsApp
  2. CrunchzApp generates a random code and delivers it via WhatsApp
  3. The user enters this code in your application
  4. Your application validates the code through the CrunchzApp API

Available Methods

Request Code

Send a one-time password to a WhatsApp contact.

use CrunchzApp\CrunchzApp;

CrunchzApp::otp('code')
  ->contact('xxx@c.us')
  ->send();

By default, OTP codes expire after 5 minutes. The user will receive a message containing the generated code.

Validate Code

Verify an OTP code entered by the user.

use CrunchzApp\CrunchzApp;

CrunchzApp::otp('code')
  ->contact('xxx@c.us')
  ->validate('M9TQ');

OTP codes can only be validated once. After successful validation or expiration, a new code must be requested.

Common Use Cases

Error Handling

{
  "success": false,
  "message": "Invalid OTP code",
  "error_code": "OTP_INVALID"
}