Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Tokopedia Php Sdk Laravel Package

gandung/tokopedia-php-sdk

A PHP SDK for integrating Tokopedia's API into Laravel or plain PHP apps, offering convenient wrappers for authentication and common seller endpoints so you can manage products, orders, and shop data with less boilerplate.

View on GitHub
Deep Wiki
Context7

Getting Started

The package is a framework-agnostic Composer library — it does not ship a Laravel service provider or config file, so treat it as a thin client you wire yourself.

composer require gandung/tokopedia-php-sdk

Where to look first

  1. vendor/gandung/tokopedia-php-sdk/composer.json — check require (PHP and Guzzle versions). The 2021-09-01 release predates PHP 8.2/Laravel 10+, so confirm it installs cleanly before writing any code.
  2. vendor/gandung/tokopedia-php-sdk/src/ — identify the main client class and namespace (typically Gandung\Tokopedia\...). Use composer show gandung/tokopedia-php-sdk and grep -r "function " src/ to map the public methods.
  3. README.md in the repo — the constructor signature (client ID / client secret / token) and the base URL it targets.

Get credentials

Create an app in the Tokopedia Seller dashboard (Open API / Developer section) to obtain a Client ID and Client Secret. Tokopedia issues short-lived bearer tokens via its accounts endpoint; the SDK either handles that for you or expects you to pass a token in.

First use case — read your shop's catalog

use Gandung\Tokopedia\Tokopedia; // confirm the real class name in vendor/

$client = new Tokopedia(config('services.tokopedia.client_id'), config('services.tokopedia.client_secret'));

$products = $client->getProducts($shopId, ['page' => 1, 'per_page' => 20]);

The lowest-risk first integration is a read-only catalog sync: pull products/orders into your database, render them in a Laravel resource or dashboard, and prove auth + error handling before adding write calls.

Implementation Patterns

Bind as a singleton and centralise config

// config/services.php
'tokopedia' => [
    'client_id'     => env('TOKOPEDIA_CLIENT_ID'),
    'client_secret' => env('TOKOPEDIA_CLIENT_SECRET'),
    'shop_id'       => env('TOKOPEDIA_SHOP_ID'),
    'base_url'      => env('TOKOPEDIA_BASE_URL', 'https://fs.tokopedia.net'),
],

// app/Providers/AppServiceProvider.php
$this->app->singleton(Tokopedia::class, fn () => new Tokopedia(
    config('services.tokopedia.client_id'),
    config('services.tokopedia.client_secret'),
));

Wrap it in your own service, don't scatter SDK calls

namespace App\Services;

use Gandung\Tokopedia\Tokopedia;

class TokopediaCatalog
{
    public function __construct(private Tokopedia $client) {}

    public function firstPageOfProducts(int $shopId): array
    {
        return $this->client->getProducts($shopId, ['page' => 1, 'per_page' => 50]);
    }
}

This gives you one place to swap the SDK out (see Gotchas) without touching controllers/jobs.

Token caching pattern — if the SDK re-authenticates on every call, cache the token yourself:

$token = Cache::remember('tokopedia:token', now()->addMinutes(50), function () {
    return $this->client->requestToken(); // check the actual method name
});

Queue long-running work

Catalog and order syncs paginate. Push them to jobs so HTTP timeouts don't hit the request cycle:

SyncTokopediaProducts::dispatch($shopId)->onQueue('tokopedia');

Inside the job, app(Tokopedia::class) resolves the singleton; loop pages with usleep() between requests to stay under Tokopedia's rate limits.

Use a facade for ergonomics

// config/app.php (Laravel 10) or bootstrap/app.php aliases
'aliases' => ['Tokopedia' => App\Facades\Tokopedia::class],

Create App\Facades\Tokopedia extending Illuminate\Support\Facades\Facade and returning Tokopedia::class. This keeps call sites readable and avoids constructor noise.

Integration tip: for endpoints the SDK doesn't cover, don't abandon it — keep a tokopedia Laravel HTTP client with the same token so you get Http::fake() testability alongside the SDK's coverage.

Gotchas and Tips

  • Maintenance risk (12 stars, 0 dependents, last release 2021). Tokopedia's API has evolved since; some routes may 404 or return new fields. Mitigate by wrapping the SDK in your own service class (above) and by pinning the version. If a critical endpoint breaks, forking the one class is often faster than waiting for an update.
  • PHP/Laravel compatibility. If composer require fails on PHP 8.2+/Laravel 11, check the require block — you may need --ignore-platform-reqs locally, or a fork with bumped Guzzle/PHP constraints. Don't ship --ignore-platform-reqs to production.
  • No auto-discovery. Unlike typical Laravel packages, this won't register anything. Every binding, config key, and facade is your responsibility; forgetting the singleton means a new client (and possibly a new token request) per injection.
  • Auth is the #1 failure point. Tokopedia tokens expire (roughly hourly) and invalid/expired tokens surface as 401s that the SDK may rethrow as generic exceptions. Cache the token, and on a 401 invalidate the cache and retry once.
  • Error bodies aren't always exceptions. Tokopedia returns structured JSON like {"error": {"message": ...}} with non-2xx codes. If the SDK only returns an array, inspect header.status/HTTP status — don't assume a missing key means "no products."
  • Rate limits. Expect 429s under pagination. Implement exponential backoff (retry(3, 1000)) or usleep(200_000) between pages. Tokopedia's documented limits are per-app, so one aggressive sync can starve your other integrations.
  • Timezones and IDs. Tokopedia timestamps are typically UTC+7 (WIB) and IDs are large integers — store shop_id, product_id, order_id as bigInteger/string, never int(11) assumptions, and normalise dates into Carbon at the boundary.
  • Testing. Because the SDK likely uses Guzzle directly, mock the handler rather than Http::fake():
    $mock = new \GuzzleHttp\Handler\MockHandler([new \GuzzleHttp\Psr7\Response(200, [], json_encode($fixture))]);
    $client = new Tokopedia(..., ['handler' => \GuzzleHttp\HandlerStack::create($mock)]);
    
    If the constructor doesn't accept a handler, test your TokopediaCatalog wrapper instead and keep the wrapper's methods small.
  • Extension points. The best leverage is your wrapper plus a custom Guzzle HandlerStack middleware (for logging raw requests/responses and retries) injected into the SDK if it accepts a config array. Log correlation IDs from Tokopedia's response headers so support tickets are debuggable.
  • Secrets. Put credentials in .env only, never in config/services.php defaults, and add TOKOPEDIA_* to .env.example. If you later fork the package, keep the token-fetching code out of version control diffs.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core