Otp
in package
OTP resource for managing one-time password sessions.
OTPs provide secure verification for sensitive operations. Initialize sessions, send codes via SMS or email, verify customer-provided codes, and manage OTP lifecycle. Used for payment confirmations, account verification, and authentication flows.
Tags
Table of Contents
Methods
- __construct() : mixed
- cancel() : OTPTransaction
- Cancel an active OTP session, preventing further verification attempts.
- initiate() : OTPTransaction
- Create a new OTP session and deliver the code to the recipient.
- lookup() : OTPTransaction
- Retrieve details of an OTP session.
- verify() : OTPVerification
- Verify a customer-provided OTP code against an active session.
Methods
__construct()
public
__construct(HttpClient $http) : mixed
Parameters
- $http : HttpClient
cancel()
Cancel an active OTP session, preventing further verification attempts.
public
cancel(array<string|int, mixed> $payload) : OTPTransaction
Invalidates an OTP session immediately. Use this when the customer abandons the verification flow or when the operation requiring OTP is cancelled. Cancelled sessions cannot be resumed or verified.
Parameters
- $payload : array<string|int, mixed>
-
Cancellation parameters
- transaction_id: string - OTP transaction to cancel (required)
- reason: string - Reason for cancellation (required)
Tags
Return values
OTPTransaction —Cancelled session
initiate()
Create a new OTP session and deliver the code to the recipient.
public
initiate(array<string|int, mixed> $payload) : OTPTransaction
Initializes an OTP session and sends a verification code via SMS or email. The code is typically 6 digits and expires after a configured time period. Use OTPs for payment confirmations, sensitive account changes, or multi-factor authentication.
Parameters
- $payload : array<string|int, mixed>
-
OTP initiation parameters
- recipient: string - Phone number in international format (required)
- sender: string - Sender identifier (required)
- service_name: string - Service name in message (required)
- request_meta: array - Request controls such as idempotency_key (optional)
- purpose: string - Description of why OTP is needed (optional)
- Additional transaction configuration parameters
Tags
Return values
OTPTransaction —Created OTP session
lookup()
Retrieve details of an OTP session.
public
lookup(array<string|int, mixed> $payload) : OTPTransaction
Returns session information including status, expiration time, verification attempts, and recipient details. Use this to check session state or display remaining attempts to customers.
Parameters
- $payload : array<string|int, mixed>
-
Lookup parameters
- transaction_id: string - OTP transaction identifier to retrieve (required)
Tags
Return values
OTPTransaction —OTP session details
verify()
Verify a customer-provided OTP code against an active session.
public
verify(array<string|int, mixed> $payload) : OTPVerification
Validates the OTP code entered by the customer. If the code matches and hasn't expired, verification succeeds and the session is marked complete. Failed verification attempts are tracked, and excessive failures may lock the session.
Parameters
- $payload : array<string|int, mixed>
-
Verification parameters
- transaction_id: string - OTP transaction identifier (required)
- recipient: string - Recipient phone number (required)
- token: string - Customer-provided OTP code (required, typically 6 digits)
Tags
Return values
OTPVerification —Verification result