Listing credit orders
listSmsCreditSales() and iterateSmsCreditSales() list the credit orders (SMS credit sales) of your account: the same orders as the orders page of the web application. Use them, for example, to reconcile purchases and VAT for a period.
Iterate over every order
Section titled “Iterate over every order”iterateSmsCreditSales() returns a Generator. It fetches the pages one at a time, as you consume them, and yields each order as an SmsCreditSale:
use DateTimeImmutable;use DateTimeZone;
$athens = new DateTimeZone('Europe/Athens');
$orders = $client->iterateSmsCreditSales([ 'dateFrom' => new DateTimeImmutable('2026-12-01 00:00:00', $athens), 'dateTo' => new DateTimeImmutable('2027-01-01 00:00:00', $athens),]);
foreach ($orders as $order) { printf( "%s | %s | %d credits | %.2f %s (VAT %d%%: %.2f) | %s\n", $order->getSoldAtInUserTimeZone(), $order->getId(), $order->getNumberOfCredits(), $order->getAmountPaid(), $order->getCurrency(), $order->getVatPercentage(), $order->getVatAmount(), $order->getPaymentMethod() );}The query is validated as soon as iterateSmsCreditSales() is called, before iteration starts. The generator sends each page’s next cursor back with the same sort, dateFrom, and dateTo.
Fetch one page at a time
Section titled “Fetch one page at a time”listSmsCreditSales() returns one page of at most 25 orders as an SmsCreditSalesResponse. To get the next page, send the same query again with the page’s next cursor:
use Rayo\SmsSdk\Models\SmsCreditSalesQuery;
$query = new SmsCreditSalesQuery( SmsCreditSalesQuery::SORT_DESC, '2026-12-01T00:00:00+02:00');
do { $page = $client->listSmsCreditSales($query);
foreach ($page->getSmsCreditSales() as $order) { // ... }
if ($page->getNextCursor() !== null) { // Keeps the same sort, dateFrom, and dateTo. $query = $query->withCursor($page->getNextCursor()); }} while ($page->getNextCursor() !== null);The SmsCreditSalesQuery constructor takes sort, dateFrom, dateTo, and cursor, in that order. You can pass an associative array with the same keys instead.
Each page also exposes getRequestId(), getTimeZone() (the IANA time zone of your account, used for the …InUserTimeZone timestamps), getLimit(), getSort(), and hasMore(). Treat the cursor as opaque.
Query parameters
Section titled “Query parameters”| Parameter | Description |
|---|---|
sort |
asc (default) returns the oldest orders first, desc the newest first. Orders are sorted by the time they were created. |
dateFrom |
Only orders sold at or after this moment. |
dateTo |
Only orders sold before this moment. dateTo itself is excluded and must be later than dateFrom. |
cursor |
The next cursor of the previous page. Omit it for the first page. |
dateFrom and dateTo take a DateTimeInterface or an RFC 3339 string with an offset, such as 2026-12-01T00:00:00+02:00 or 2026-11-30T22:00:00Z. Because dateTo is excluded, set it to the start of the next period: for December, 2027-01-01T00:00:00+02:00. The dateTo of one period can then be the dateFrom of the next without missing or repeating an order. The SDK URL-encodes the + of an offset for you.
The SmsCreditSale model
Section titled “The SmsCreditSale model”| Getter | Description |
|---|---|
getId() |
The order’s ID. |
getAmount() |
The amount, excluding VAT. |
getVatPercentage(), getVatAmount() |
The VAT rate and amount of the order. |
getAmountPaid() |
The amount including VAT. |
getCurrency() |
The currency of the amounts. |
getNumberOfCredits() |
The credits bought. |
getPaymentMethod() |
SmsCreditSale::PAYMENT_METHOD_CREDIT_OR_DEBIT_CARD, PAYMENT_METHOD_BANK_DEPOSIT, or PAYMENT_METHOD_UNKNOWN. |
isAcknowledged() |
Whether the order has been acknowledged. |
getSoldAtUtc(), getSoldAtInUserTimeZone() |
When the order was sold. dateFrom and dateTo use this time. |
getCreatedAtUtc(), getCreatedAtInUserTimeZone() |
When the order was registered. sort uses this time. |
getSourceSmsCreditSaleId() |
For brand owners only; see below. |
Brand owners
Section titled “Brand owners”If you own a brand, an order that records credits transferred from your balance to one of your users has a source order: getSourceSmsCreditSaleId() returns the ID of that user’s order. It returns null for your own orders, and always for accounts that are not brand owners.
Errors
Section titled “Errors”The SDK validates the query before it sends a request and throws a RayoException for an unknown sort, a date without an offset, a date without a time, a date that does not exist (such as 2026-02-30), a dateFrom that is not before dateTo, an empty cursor, or an unknown key.
Invalid parameters that reach the server, such as a cursor issued for another sort, come back as HTTP status 422 and are thrown as a RayoException.
