API reference
This page summarizes the public API. For implementation details, view the source repository. For the release history, read the changelog.
Rayo\SmsSdk\Client
Section titled “Rayo\SmsSdk\Client”| Member | Returns | Purpose |
|---|---|---|
__construct(string $apiKey, string|array $baseUrlOrOptions, array $options = []) |
Client |
Configure credentials, base URL, and Guzzle options |
getBaseUrl() |
string |
Return the normalized URL ending in /v1/ |
sendSms(SmsRequest|array $payload) |
SmsResponse |
Send immediately or schedule |
getBalance() |
BalanceResponse |
Retrieve credits |
getBalanceInCredits() |
BalanceResponse |
Alias for getBalance() |
listSmsCreditSales(SmsCreditSalesQuery|array $query = []) |
SmsCreditSalesResponse |
List one page of credit orders |
iterateSmsCreditSales(SmsCreditSalesQuery|array $query = []) |
Generator<SmsCreditSale> |
Iterate over every matching credit order |
listMessages(MessagesQuery|array $query = []) |
MessagesResponse |
List one page of sent messages |
iterateMessages(MessagesQuery|array $query = []) |
Generator<Message> |
Iterate over every matching sent message |
checkStatus(?string $serverId, ?string $clientId) |
SmsDeliveryStatusItem[] |
Query using exactly one identifier |
checkStatusByServerRequestId(string $id) |
SmsDeliveryStatusItem[] |
Query by server ID |
checkStatusByClientRequestId(string $id) |
SmsDeliveryStatusItem[] |
Query by client ID |
deleteSchedule(string $id) |
DeleteScheduleResponse |
Delete a schedule with no delivery history |
deleteSmsRequestSchedule(string $id) |
DeleteScheduleResponse |
Alias for deleteSchedule() |
disableSchedule(string $id) |
ScheduleStateChangeResponse |
Pause an active schedule |
disableSmsRequestSchedule(string $id) |
ScheduleStateChangeResponse |
Alias for disableSchedule() |
enableSchedule(string $id) |
ScheduleStateChangeResponse |
Resume a disabled schedule |
enableSmsRequestSchedule(string $id) |
ScheduleStateChangeResponse |
Alias for enableSchedule() |
Constants: Client::DEFAULT_TIMEOUT is 10.0; Client::API_VERSION_PREFIX is v1.
SmsRequest
Section titled “SmsRequest”Constructor:
new SmsRequest( string $fromLabel, string $smsBody, string|array|null $toMobileNumber = null, string|array|null $toGroup = null, ?string $clientRequestId = null, ?bool $callbackWhenProcessedFlag = null, ?bool $simulateSendFlag = null, ?bool $concatFlag = null, SmsSchedule|array|null $schedule = null);Factory and serialization: fromArray(), validate(), toArray(), jsonSerialize().
Getters correspond to every constructor field. SmsRequest::MAXIMUM_SMS_LENGTH is 1000.
SmsSchedule
Section titled “SmsSchedule”Use the factories to build valid API schedule definitions:
SmsSchedule::oneOff(DateTimeInterface|string $startsAt);
SmsSchedule::recurring( string $expression, string $timezone, DateTimeInterface|string $startsAt, DateTimeInterface|string|null $endsAt = null);SmsSchedule::fromArray() accepts the equivalent one_off or recurring API shape. The model provides toArray(), jsonSerialize(), and getters for type, startsAt, expression, timezone, and endsAt.
List queries
Section titled “List queries”Both query models validate their parameters when they are built and throw RayoException for invalid values. Both provide fromArray(), withCursor(?string $cursor) (returns a copy for the next page), toArray() (leaves out unset parameters), jsonSerialize(), and a getter for every parameter. SORT_ASC and SORT_DESC hold asc and desc.
SmsCreditSalesQuery
Section titled “SmsCreditSalesQuery”new SmsCreditSalesQuery( ?string $sort = null, DateTimeInterface|string|null $dateFrom = null, DateTimeInterface|string|null $dateTo = null, ?string $cursor = null);See Listing credit orders for the parameters.
MessagesQuery
Section titled “MessagesQuery”new MessagesQuery( ?string $sort = null, ?int $limit = null, DateTimeInterface|string|null $dateFrom = null, DateTimeInterface|string|null $dateTo = null, string|array|null $status = null, ?string $mobileNumber = null, ?string $clientRequestId = null, string|array|null $smsServerRequestId = null, ?string $smsRequestScheduleId = null, ?bool $returnMessageContent = null, ?string $cursor = null);Call the constructor with named arguments. Constants: MIN_LIMIT is 1, MAX_LIMIT is 100, and MAX_SMS_SERVER_REQUEST_IDS is 100. See Listing sent messages for the parameters.
Response models
Section titled “Response models”All response models are immutable, JSON-serializable, and provide read-only ArrayAccess to their raw response.
SmsResponse
Section titled “SmsResponse”- State:
isSuccess(),isScheduled(). - Getters:
getUsername(),getResultCode(),getResultDescription(),getClientRequestId(),getSmsServerRequestId(),getSmsRequestScheduleId(),getError().
DeleteScheduleResponse
Section titled “DeleteScheduleResponse”- State:
isSuccess(). - Getters:
getUsername(),getResultCode(),getResultDescription(),getSmsRequestScheduleId(),getError().
ScheduleStateChangeResponse
Section titled “ScheduleStateChangeResponse”- State:
isSuccess(),isActive(),isDisabled(),isExpired(). - Getters:
getUsername(),getResultCode(),getResultDescription(),getSmsRequestScheduleId(),getSmsRequestScheduleState(). - Constants:
STATE_ACTIVE,STATE_DISABLED,STATE_EXPIRED.
BalanceResponse
Section titled “BalanceResponse”- Getters:
getRequestId(),getCredits().
SmsCreditSalesResponse and MessagesResponse
Section titled “SmsCreditSalesResponse and MessagesResponse”- Getters:
getRequestId(),getTimeZone(),getLimit(),getSort(),getNextCursor(). - State:
hasMore(). - Items:
SmsCreditSalesResponse::getSmsCreditSales()returnsSmsCreditSale[];MessagesResponse::getMessages()returnsMessage[].
SmsCreditSale
Section titled “SmsCreditSale”- Getters:
getId(),getAmount(),getVatPercentage(),getVatAmount(),getAmountPaid(),getCurrency(),getNumberOfCredits(),getPaymentMethod(),getSoldAtUtc(),getSoldAtInUserTimeZone(),getCreatedAtUtc(),getCreatedAtInUserTimeZone(),getSourceSmsCreditSaleId(). - State:
isAcknowledged(). - Constants:
PAYMENT_METHOD_CREDIT_OR_DEBIT_CARD,PAYMENT_METHOD_BANK_DEPOSIT,PAYMENT_METHOD_UNKNOWN.
Message
Section titled “Message”- State:
isDelivered(),isFinalStatus(),isMasked(),hasMessageContent(). - Getters:
getId(),getSmsServerRequestId(),getSmsRequestScheduleId(),getClientRequestId(),getSenderId(),getMobileNumber(),getMessage(),getStatus(),getErrorDescription(),getCredits(),getCreatedAtUtc(),getCreatedAtInUserTimeZone(),getLastStatusUpdatedAtUtc(),getLastStatusUpdatedAtInUserTimeZone().
getMessage() and isMasked() are filled only when the query sets returnMessageContent to true.
SmsDeliveryStatusItem
Section titled “SmsDeliveryStatusItem”- State:
isDelivered(),isFinalStatus(). - Getters:
getSmsServerRequestId(),getClientRequestId(),getInternalSmsOutDeliveryId(),getMobileNumber(),getStatus().
CallbackPayload
Section titled “CallbackPayload”- Factories:
fromArray(),fromJson(),fromQueryString(). - State:
isDelivered(),isFinalStatus(). - Getters:
getSmsServerRequestId(),getClientRequestId(),getInternalSmsOutDeliveryId(),getSenderId(),getMobileNumber(),getStatus(),getErrorDescription(),getRequestTimestamp(),getLastStatusUpdatedTimestamp().
The timestamp parser accepts the documented requestTimestamp and the server variant requestedTimestamp.
In both SmsDeliveryStatusItem and CallbackPayload, getSmsServerRequestId() and getInternalSmsOutDeliveryId() return UUID strings. getInternalSmsOutDeliveryId() is the same value as Message::getId().
DeliveryStatus
Section titled “DeliveryStatus”Constants: NEW, TEMP_LOCKED, PROCESSING_ERROR, FAILURE, SENT, ERROR, DELIVERED, NOT_DELIVERED, and UNKNOWN_DELIVERY.
Use DeliveryStatus::all() to list every value and DeliveryStatus::isFinal($status) to test terminal status.
WebhookSignatureVerifier
Section titled “WebhookSignatureVerifier”| Method | Purpose |
|---|---|
computeSignature(...) |
Compute the expected HMAC-SHA256 digest |
verify(...) |
Return whether a raw request signature is valid |
verifyOrThrow(...) |
Throw RayoException for an invalid signature |
verifyPsr7Request(...) |
Verify a PSR-7 server request |
RayoException
Section titled “RayoException”Extends RuntimeException. In addition to inherited exception methods, it exposes getStatusCode(), getErrorPayload(), getRawResponseBody(), getErrorMessage(), getResultCode(), and getResultDescription().
