PHP code example of salla / laravel-starter-kit

1. Go to this page and download the library: Download salla/laravel-starter-kit 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/ */

    

salla / laravel-starter-kit example snippets


// set the current user or any user you want to use his access tokens
app('salla.auth')->forUser(auth()->user());

// Get the get the store details
/** Salla\OAuth2\Client\Provider\SallaUser::class **/
app('salla.auth')->getResourceOwner();

// Made an API request using the current access token of the user
app('salla.auth')->request('GET', 'https://api.salla.dev/admin/v2/products')['data'];
    
// Request a new access token
app('salla.auth')->getNewAccessToken();

// Save the access token
auth()->user()->token()->create([
    'merchant'      => 'id',
    'access_token'  => 'access token',
    'expires_in'    => 'expires in sec',
    'refresh_token' => 'refresh token'
]);

try {
    // set the current user
    // or any user you want to refresh his access token
    app('salla.auth')
        ->forUser(auth()->user())
        ->getNewAccessToken();
    
    // by default the function `getNewAccessToken` will get a new access token 
    // and save the new access token to the same user you are set it in the `forUser` function
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $exception) {
    // in case the token access token & refresh token is expired
    // you should redirect the user again to Salla authorization service to get a new token
    // return redirect()->route('oauth.redirect');
}