PHP code example of yehia-tarek / salla-toolkit
1. Go to this page and download the library: Download yehia-tarek/salla-toolkit library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yehia-tarek / salla-toolkit example snippets
use YehiaTarek\SallaToolkit\Facades\Salla;
$orders = Salla::orders()->all(['status' => 'pending']);
$order = Salla::orders()->find($orderId);
$product = Salla::products()->create([
'name' => 'T-Shirt',
'price' => 100,
'product_type' => 'product',
]);
Salla::customers()->ban($customerId);
// Redirect a merchant to install your app:
return redirect(Salla::oauth()->installationUrl($appId));
// routes/web.php
Route::get('/salla/connect', function () {
return redirect(Salla::oauth()->authorizationUrl());
});
Route::get('/salla/callback', function (Illuminate\Http\Request $request) {
$tokens = Salla::oauth()->exchangeCodeForToken($request->query('code'));
$me = Salla::oauth()->userInfo($tokens['access_token']);
app(\YehiaTarek\SallaToolkit\Contracts\SallaTokenRepository::class)->store(
storeId: $me['data']['merchant']['id'] ?? $me['data']['id'],
accessToken: $tokens['access_token'],
refreshToken: $tokens['refresh_token'] ?? null,
expiresAt: time() + ($tokens['expires_in'] ?? 0),
scope: $tokens['scope'] ?? null,
);
return redirect('/dashboard');
});
Salla::forStore($storeId)->orders()->all();
Salla::forStore($storeId)->products()->find($productId);
Salla::withToken($accessToken)->orders()->all();
$response = Salla::orders()->all(['page' => 2]);
$orders = $response['data'];
$pagination = $response['pagination']; // count, total, perPage, currentPage, totalPages, links
$allOrders = Salla::orders()->allPages();
use YehiaTarek\SallaToolkit\Webhooks\Events\SallaWebhookReceived;
// Catch-all listener
Event::listen(SallaWebhookReceived::class, function (SallaWebhookReceived $event) {
logger("Salla event: {$event->event}", $event->data());
});
// Or listen for one specific event by name
Event::listen('salla.order.created', function (array $payload) {
// $payload['data'] is the created order
});
Route::post('/my-webhook', MyWebhookController::class)
->middleware(\YehiaTarek\SallaToolkit\Middleware\VerifySallaWebhook::class);
use YehiaTarek\SallaToolkit\Exceptions\{
SallaAuthenticationException,
SallaRateLimitException,
SallaRequestException,
};
try {
Salla::forStore($storeId)->orders()->create($data);
} catch (SallaRequestException $e) {
// $e->statusCode(), $e->errors() (422 field errors), $e->getMessage()
} catch (SallaRateLimitException $e) {
// $e->retryAfter() in seconds, if provided
} catch (SallaAuthenticationException $e) {
// token missing/expired and could not be refreshed — merchant likely
// needs to reinstall the app
}
$this->app->bind(
\YehiaTarek\SallaToolkit\Contracts\SallaTokenRepository::class,
\App\Services\RedisSallaTokenRepository::class
);
bash
composer salla:install
php artisan migrate