Download the PHP package laraditz/tiktok without Composer
On this page you can find all versions of the php package laraditz/tiktok. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laraditz/tiktok
More information about laraditz/tiktok
Files in laraditz/tiktok
Package tiktok
Short Description Laravel package for interacting with TikTok API.
License MIT
Homepage https://github.com/laraditz/tiktok
Informations about the package tiktok
Laravel TikTok
A comprehensive Laravel package for seamless integration with the TikTok Shop API. This package provides a clean, intuitive interface for managing TikTok shops, handling authentication, processing orders, managing products, and receiving webhooks.
Features
- π Complete Authentication Flow - Automatic token management with refresh capabilities
- πͺ Multi-Shop Support - Manage multiple TikTok shops within a single application
- π¦ Product Management - Full CRUD operations for TikTok Shop products
- π Order Processing - Comprehensive order management and tracking
- π Return Handling - Complete return and refund management
- π° Finance Tracking - Statements, transactions, payments, and withdrawals
- π‘ Webhook Integration - Real-time event handling with built-in webhook endpoints
- ποΈ Database Logging - Automatic request logging for debugging and monitoring
- π Auto Token Refresh - Background token refresh to maintain API connectivity
Requirements
- PHP 8.2 and above.
- Laravel 10 and above.
Installation
You can install the package via composer:
Quick Start
1. TikTok Shop App Setup
Before using this package, you need to create a TikTok Shop app:
- Visit TikTok Shop Partner Center
- Create a new app or use an existing one
- Note your
App KeyandApp Secret - Configure the redirect URL:
https://your-app-url.com/tiktok/seller/authorized
2. Environment Configuration
Add your TikTok Shop credentials to your .env file:
3. Publish Migration
You can publish the migration file via this command:
4. Run Migration
Run the migration command to create the necessary database tables:
This creates tables for shops, access tokens, requests, webhooks, orders, and returns.
5. Configuration (Optional)
Publish the configuration file if you need to customize settings:
6. Authorization Flow
To authorize a TikTok shop with your app:
-
In Partner Center, go to
App & Serviceand select your app. On the right side, you can findAuthorizationsection withCopy authorization linkbutton. Copy the URL and paste it into your browser address. The URL look like this: -
Login using the seller account that you want to authorized to be use for the app.
- TikTok redirects back to
https://your-app-url.com/tiktok/seller/authorized - Package automatically handles the authorization code exchange and token storage
- Shop is now ready for API calls
Available Methods
Hereβs the full list of methods available in this package. Each method uses the same parameters defined in the TikTok Shop API Documentation. You donβt need to worry about adding common parameters like app_key, sign, timestamp, or shop_cipher because theyβll be automatically included whenever required.
Authentication Service auth()
| Method | Description | Parameters |
|---|---|---|
accessToken() |
Generate access token from authorization code | query: app_key, app_secret, auth_code, grant_type |
refreshAccessToken() |
Refresh access token before it expired. | TiktokAccessToken tiktokAccessToken |
Authorization Service authorization()
| Method | Description |
|---|---|
shops() |
Retrieves the list of shops that a seller has authorized for an app. |
Event Service event()
| Method | Description | Parameters |
|---|---|---|
webhookList() |
Retrieves a shop's webhooks and the corresponding webhook URLs. | |
updateWebhook() |
Updates the shop's webhook URL for a specific event topic. | body: event_type, address |
deleteWebhook() |
Deletes the shop's webhook URL for a specific event topic. | body: event_type |
Seller Service seller()
| Method | Description |
|---|---|
shops() |
Retrieves all active shops that belong to a seller. |
Order Service order()
Full parameters refer to API documentation
| Method | Description | Parameters |
|---|---|---|
list() |
Returns a list of orders created or updated during the timeframe indicated by the specified parameters. | query: page_size and more |
body: order_status and more |
||
detail() |
Get the detailed order information of an order. | query: ids |
priceDetail() |
Get the detailed pricing calculation information of an order or a line item, including vouchers, tax, etc. | params: order_id |
Product Service product()
Full parameters refer to API documentation
| Method | Description | Parameters |
|---|---|---|
list() |
Retrieve a list of products that meet the specified conditions. | query: page_size, page_token |
body: status, update_time_ge and more |
||
get() |
Retrieve all properties of a product that is in the DRAFT, PENDING, or ACTIVATE status. | params: product_id |
updateInventory() |
Retrieve all properties of a product that is in the DRAFT, PENDING, or ACTIVATE status. | params: product_id |
body: skus |
Return Service return()
Full parameters refer to API documentation
| Method | Description | Parameters |
|---|---|---|
list() |
Use this API to retrieve one or more returns. | query: page_size, page_token and more |
get() |
Use this API to get a list of return records. | params: return_id |
Finance Service finance()
Full parameters refer to API documentation
| Method | Description | Parameters |
|---|---|---|
statements() |
Retrieve a list of statements. | query: page_size, page_token and more |
transactionsByOrder() |
Retrieve the statement transactions of an order. | params: order_id |
transactionsByStatement() |
Retrieve the statement transactions of a statement. | params: statement_id |
unsettledTransactions() |
Retrieve a list of unsettled transactions. | query: page_size, page_token and more |
payments() |
Retrieve a list of payments. | query: page_size, page_token and more |
withdrawals() |
Retrieve a list of withdrawals. | query: page_size, page_token and more |
Usage Examples
Basic Usage
Working with Products
Order Management
Return Order
Finance Tracking
Multi-Shop Support
By default, the package uses TIKTOK_SHOP_ID from your .env file. For multi-shop applications, specify the shop ID per request:
Error Handling
Events & Webhooks
Available Events
This package provides events that you can listen to in your application:
| Event | Description |
|---|---|
Laraditz\TikTok\Events\WebhookReceived |
Triggered when TikTok sends webhook data |
Laraditz\TikTok\Events\TikTokRequestFailed |
Triggered when API request fails |
Creating Event Listeners
Create listeners for these events in your application:
Register the listener in your EventServiceProvider (Laravel 10 and below):
Webhook Configuration
1. Universal Webhook Endpoint
Configure this URL in your TikTok Shop App Management section under Manage Webhook to receive all webhook events:
2. Event-Specific Webhooks
You can also register individual webhooks for specific events:
3. Managing Webhooks
Read more about TikTok Webhooks in the official documentation and webhook section.
Token Management
Artisan Commands
The package provides Artisan commands for token management:
Automated Token Refresh
Set up automatic token refresh in your app/Console/Kernel.php:
Token Lifecycle
Understanding TikTok token duration:
| Token Type | Duration | Notes |
|---|---|---|
| Access Token | 7 days | Used for API calls |
| Refresh Token | ~2 months | Used to refresh access tokens |
Important: If tokens expire and refresh fails, sellers must re-authorize your app.
Testing
Running Tests
Debug Mode
Enable debug logging by listening to the TikTokRequestFailed event:
Changelog
Please see CHANGELOG for more information about recent changes.
Contributing
We welcome contributions! Please see CONTRIBUTING for guidelines on:
- Reporting bugs
- Suggesting enhancements
- Submitting pull requests
- Code style standards
Security
If you discover any security vulnerabilities, please email [email protected] instead of using the issue tracker. All security vulnerabilities will be promptly addressed.
Support
- π TikTok Shop API Documentation
- π Issue Tracker
- π¬ Discussions
Credits
- Raditz Farhan - Creator and maintainer
- All Contributors - Thank you for your contributions!
License
The MIT License (MIT). Please see License File for more information.
