### Get Products List with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core This example shows how to fetch a list of products using the Basalam SDK. It allows for pagination and sorting by providing query parameters such as page number, items per page, and sort order. This is useful for displaying product listings. ```php getProducts( queryParams: new GetProductsQuerySchema( page: 1, perPage: 20, sort: 'price:asc' ) ); return $products; } ``` -------------------------------- ### PHP SDK Wallet Service: Get User Balance Source: https://developers.basalam.com/docs/sdk/php/wallet This example shows how to retrieve a user's wallet balance using the `getBalance` method. It accepts a user ID and optional filters to specify the type of balance to retrieve (e.g., cash, settleable). ```php getBalance( userId: 123, filters: [ new BalanceFilter( cash: true, settleable: true, vendor: false, customer: true ) ] ); return $balance; } ``` -------------------------------- ### Install Basalam PHP SDK using Composer Source: https://developers.basalam.com/docs/sdk/php/intro This snippet shows how to install the Basalam PHP SDK using Composer, a dependency manager for PHP. Ensure you have Composer installed on your system. ```bash composer require basalam/php-sdk ``` -------------------------------- ### Get Vendor Products with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core Provides an example of retrieving a vendor's products using the Basalam SDK. Requires the vendor ID and allows filtering by status, page number, and items per page via query parameters. Returns the product list. ```php getVendorProducts( vendorId: 456, queryParams: new GetVendorProductsSchema( statuses: [ProductStatusInputEnum::PUBLISHED], page: 1, perPage: 10 ) ); return $products; } ``` -------------------------------- ### Get Vendor with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core Provides an example of how to retrieve a specific vendor's details using the Basalam SDK. Requires the vendor ID and an optional 'prefer' parameter for customizing the return format. Returns the vendor object. ```php getVendor( vendorId: 456, prefer: 'return=minimal' ); return $vendor; } ``` -------------------------------- ### Get Me API (GET) Source: https://developers.basalam.com/docs/sdk/php/chat Retrieves information about the bot using a GET request. ```APIDOC ## GET /getMe ### Description Retrieves information about the bot. ### Method GET ### Endpoint /getMe ### Parameters #### Query Parameters - **token** (string) - Required - The token of the bot. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the request was successful. - **result** (object) - Contains bot information such as 'id', 'first_name', and 'username'. ``` -------------------------------- ### Configure Basalam SDK PHP Client Source: https://developers.basalam.com/docs/sdk/php/order Initializes the Basalam PHP SDK client using personal access tokens for authentication. This setup is required before making any service calls. ```php getWorkingShippingMethods( vendorId: 456 ); return $workingMethods; } ``` -------------------------------- ### Get Webhook Info API (GET) Source: https://developers.basalam.com/docs/sdk/php/chat Retrieves the current webhook information for a bot using a GET request. ```APIDOC ## GET /getWebhookInfo ### Description Retrieves the current webhook information for a bot. ### Method GET ### Endpoint /getWebhookInfo ### Parameters #### Query Parameters - **token** (string) - Required - The token of the bot. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the request was successful. - **result** (object) - Contains webhook details if successful (e.g., 'url'). ``` -------------------------------- ### Get Me API (POST) Source: https://developers.basalam.com/docs/sdk/php/chat Retrieves information about the bot using a POST request. ```APIDOC ## POST /getMePost ### Description Retrieves information about the bot using a POST request. ### Method POST ### Endpoint /getMePost ### Parameters #### Request Body - **token** (string) - Required - The token of the bot. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the request was successful. - **result** (object) - Contains bot information. ``` -------------------------------- ### Get Bot Info (GET/POST) using Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/chat Retrieves information about the bot, including its ID, first name, and username. This can be done via GET (`getMe`) or POST (`getMePost`) requests, both requiring the bot's token. The GET method also demonstrates how to access and display bot details. ```php getMe(token: $botToken); if ($botInfo->getOk()) { $bot = $botInfo->getResult(); echo 'شناسه بات: ' . $bot['id']; echo 'نام بات: ' . $bot['first_name']; echo 'نام کاربری بات: @' . $bot['username']; } return $botInfo; } ``` ```php getMePost(token: $botToken); return $botInfo; } ``` -------------------------------- ### Get Webhook Info (GET/POST) using Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/chat Fetches the current webhook information for a bot. This can be done using either a GET request (`getWebhookInfo`) or a POST request (`getWebhookInfoPost`). Both methods require the bot's token and return webhook details. ```php getWebhookInfo(token: $botToken); if ($webhookInfo->getOk()) { echo 'Webhook URL: ' . $webhookInfo->getResult()['url'] ?? 'تنظیم نشده'; } return $webhookInfo; } ``` ```php getWebhookInfoPost(token: $botToken); return $webhookInfo; } ``` -------------------------------- ### GET /items Source: https://developers.basalam.com/docs/sdk/php/order-processing Retrieves a list of order items based on specified filters. ```APIDOC ## GET /items ### Description Retrieves order items based on provided filters. ### Method GET ### Endpoint `/items` ### Parameters #### Query Parameters - **`filters`** (ItemFilter) - Optional - An object containing various filters to narrow down the item search. See `ItemFilter` documentation for available properties. ### Request Example ```php getOrderItems( filters: new ItemFilter( createdAt: '2024-01-01', cursor: 'next_cursor_123', customerIds: '123,456,789', ids: '1,2,3', orderIds: '1,2,3', perPage: 20, productIds: '1,2,3', sort: 'created_at:desc', vendorIds: '456,789' ) ); print_r($items); ?> ``` ### Response #### Success Response (200) - **items** (array) - A list of order item objects. - **meta** (object) - Pagination and meta information. #### Response Example ```json { "items": [ { "id": 789, "order_id": 123, "product_id": 101, "quantity": 1, "price": 75.50, "created_at": "2024-01-10T10:00:00Z" } ], "meta": { "current_page": 1, "last_page": 5, "next_page_url": "/items?page=2", "prev_page_url": null, "per_page": 20, "total": 100 } } ``` ``` -------------------------------- ### Get All Shipping Methods with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core Illustrates how to retrieve all available shipping methods using the Basalam SDK. This function does not require any parameters and returns an array containing all shipping methods. ```php getShippingMethods(); return $shippingMethods; } ``` -------------------------------- ### PHP SDK Chat: Retrieve Messages Source: https://developers.basalam.com/docs/sdk/php/chat This example illustrates how to fetch messages from a chat using the `getMessages` method. It takes a `GetMessagesRequest` object, allowing filtering by `chatId`, `messageId`, `limit`, and `order`. ```php getMessages(request: $request); return $messages; } ``` -------------------------------- ### PHP SDK Wallet Service: Get Expense Details Source: https://developers.basalam.com/docs/sdk/php/wallet This snippet shows how to retrieve detailed information about a specific expense using the `getExpense` method. It requires both the user ID and the expense ID as parameters. ```php getExpense( userId: 123, expenseId: 456 ); return $expense; } ``` -------------------------------- ### Create Product with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core This example shows how to create a new product using the Basalam SDK. It involves providing product details such as name, description, price, stock, and category ID. The function also handles uploading product images by accepting file handles. ```php createProduct(456, $request, photoFiles: $photoFiles); // Close file handles foreach ($photoFiles as $file) { fclose($file); } return $product; } ``` -------------------------------- ### Fetch Products using Basalam PHP SDK Source: https://developers.basalam.com/docs/sdk/php/intro This PHP snippet illustrates how to make your first API call to fetch products using the Basalam PHP SDK. It assumes the BasalamClient has been successfully initialized. ```php // دریافت محصولات $products = $client->getProducts(); echo "Found " . count($products) . " products\n"; ``` -------------------------------- ### Search Products using Basalam PHP SDK Source: https://developers.basalam.com/docs/sdk/php/search This example showcases how to search for products using the `searchProducts` method of the Basalam PHP SDK. It utilizes the `ProductSearchModel` and `FiltersModel` to define search criteria, including free shipping, price range, minimum rating, and vendor score. The function returns an array of search results. ```php searchProducts( request: new ProductSearchModel( filters: new FiltersModel( freeShipping: 1, maxPrice: 10000000, minPrice: 1000000, minRating: 4, vendorScore: 1 ), q: 'عسل' ) ); return $results; } ``` -------------------------------- ### Initialize BasalamClient with Personal Token Source: https://developers.basalam.com/docs/sdk/php/webhook Demonstrates how to set up the BasalamClient using a personal access token and refresh token for authentication. This is the initial step before making any API calls. ```php getAuthorizationUrl(state: 'user_session_id'); return Redirect::to($authUrl); } public function callback(Request $request) { $code = $request->get('code'); $state = $request->get('state'); $auth = new AuthorizationCode( clientId: 'your-client-id', clientSecret: 'your-client-secret', redirectUri: 'https://your-app.com/callback' ); // تبادل کد با توکن‌ها $tokenInfo = $auth->getToken(code: $code); // ذخیره امن توکن‌ها // ... ذخیره $tokenInfo->accessToken, $tokenInfo->refreshToken return 'Authentication successful!'; } } ``` -------------------------------- ### Create Vendor with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core Demonstrates how to create a new vendor using the Basalam SDK. Requires vendor details like title, identifier, category, city, and summary. Returns the created vendor object. ```php createVendor( userId: 123, request: new CreateVendorSchema( title: 'My Store', identifier: 'store123', categoryType: 1, city: 1, summary: 'A great store for all your needs' ) ); return $vendor; } ``` -------------------------------- ### Get Unseen Chat Count using Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/chat Retrieves the total number of unread chats for the authenticated bot. This is a simple GET request to the SDK client that returns an integer representing the count. ```php getUnseenChatCount(); return $unseenCount; } ``` -------------------------------- ### Create Bulk Products Action Request with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core This function demonstrates how to create a bulk action request for products using the Basalam SDK. It allows specifying a filter for products (e.g., by stock range) and defining actions to be performed on them, such as setting a new stock value. ```php createProductsBulkActionRequest( vendorId: 456, request: new BulkProductsUpdateRequestSchema( productFilter: new ProductFilterSchema( stock: new RangeFilterItem( start: 1, end: 5 ) ), action: [ new BulkActionItem( field: ProductBulkFieldInputEnum::STOCK, action: ProductBulkActionTypeEnum::SET, value: 50 ) ] ) ); return $bulkRequest; } ``` -------------------------------- ### PHP SDK Wallet Service: Create Expense Source: https://developers.basalam.com/docs/sdk/php/wallet This example illustrates how to create a new expense record using the `createExpense` method. It takes a user ID and a `SpendCreditRequest` object containing details like reason, reference, amount, and types. ```php createExpense( userId: 123, request: new SpendCreditRequest( reasonId: 1, referenceId: 456, amount: 10000, description: 'Payment for order #456', types: [1, 2], settleable: true, references: [ 'order_id' => 456, 'payment_method' => 1 ] ) ); return $expense; } ``` -------------------------------- ### Get Product Details with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core This function demonstrates how to retrieve detailed information about a specific product using its ID via the Basalam SDK. It includes an option to specify the 'prefer' parameter for controlling the return data format, such as 'return=minimal'. ```php getProduct( productId: 24835037, prefer: 'return=minimal' ); return $product; } ``` -------------------------------- ### GET /parcels/{parcelId} Source: https://developers.basalam.com/docs/sdk/php/order-processing Retrieves the details of a specific parcel using its ID. ```APIDOC ## GET /parcels/{parcelId} ### Description Retrieves the detailed information for a specific parcel. ### Method GET ### Endpoint `/parcels/{parcelId}` ### Parameters #### Path Parameters - **`parcelId`** (integer) - Required - The unique identifier of the parcel. ### Request Example ```php getOrderParcel( parcelId: 789 ); print_r($parcel); ?> ``` ### Response #### Success Response (200) - **parcel** (object) - An object containing the full details of the parcel. #### Response Example ```json { "parcel": { "id": 789, "order_id": 123, "vendor_id": 456, "status": "delivered", "tracking_code": "ABC123XYZ", "estimated_delivery_date": "2024-01-20", "created_at": "2024-01-12T12:00:00Z", "updated_at": "2024-01-19T15:00:00Z" } } ``` ``` -------------------------------- ### Authenticate with Basalam API using Personal Access Token Source: https://developers.basalam.com/docs/sdk/php/intro This PHP code demonstrates how to set up authentication with the Basalam API using a Personal Access Token (PAT). It initializes the BasalamClient with the provided token and refresh token. ```php getOrder( orderId: 123 ); print_r($order); ?> ``` ### Response #### Success Response (200) - **order** (object) - An object containing the full details of the order. #### Response Example ```json { "order": { "id": 123, "customer_id": 456, "created_at": "2024-01-10T10:00:00Z", "status": "processing", "total_amount": 75.50, "items": [ { "id": 789, "product_id": 101, "quantity": 1, "price": 75.50 } ] } } ``` ``` -------------------------------- ### Create Shelve - PHP Source: https://developers.basalam.com/docs/sdk/php/core This function creates a new product shelf. It requires a schema object containing the shelf's title, description, and the vendor ID. The function returns an object representing the newly created shelf. ```php createShelve( request: new ShelveSchema( title: 'مجموعه تابستانه', description: 'بهترین محصولات برای فصل تابستان', vendorId: 456 ) ); return $shelve; } ``` -------------------------------- ### GET /orders Source: https://developers.basalam.com/docs/sdk/php/order-processing Retrieves a list of customer orders based on specified filters. ```APIDOC ## GET /orders ### Description Retrieves customer orders based on provided filters. ### Method GET ### Endpoint `/orders` ### Parameters #### Query Parameters - **`filters`** (OrderFilter) - Optional - An object containing various filters to narrow down the order search. See `OrderFilter` documentation for available properties. ### Request Example ```php getOrders( filters: new OrderFilter( couponCode: 'SAVE10', cursor: 'next_cursor_123', customerIds: '123,456,789', customerName: 'John Doe', ids: '1,2,3', itemsTitle: 'laptop', paidAt: '2024-01-01', parcelEstimateSendAt: '2024-01-15', parcelStatuses: ['posted', 'delivered'], perPage: 20, sort: 'paid_at:desc', vendorIds: '456,789' ) ); print_r($orders); ?> ``` ### Response #### Success Response (200) - **orders** (array) - A list of order objects. - **meta** (object) - Pagination and meta information. #### Response Example ```json { "orders": [ { "id": 1, "customer_id": 123, "created_at": "2024-01-10T10:00:00Z", "status": "pending", "total_amount": 50.00 } ], "meta": { "current_page": 1, "last_page": 10, "next_page_url": "/orders?page=2", "prev_page_url": null, "per_page": 20, "total": 200 } } ``` ``` -------------------------------- ### Update Single Product with Basalam SDK PHP Source: https://developers.basalam.com/docs/sdk/php/core This example illustrates how to update a single product's details using the Basalam SDK. It allows modifying various product attributes, including status and specific custom attributes, by providing the product ID and a schema with the desired changes. ```php updateProduct( productId: 789, request: new ProductRequestSchema( status: 3790, productAttribute: [ [ 'attribute_id' => 219, 'value' => 'Suitable for formal ceremonies' ], [ 'attribute_id' => 221, 'value' => 'Silk' ], [ 'attribute_id' => 222, 'value' => 'Burgundy, Black, Turquoise' ], [ 'attribute_id' => 1319, 'value' => 'Due to its sensitivity, this fabric should be hand washed gently with cold water.' ] ] ) ); return $updatedProduct; } ``` -------------------------------- ### GET /webhooks/logs Source: https://developers.basalam.com/docs/sdk/php/webhook Retrieves logs for a specific webhook. This is useful for debugging and monitoring webhook activity. ```APIDOC ## GET /webhooks/logs ### Description Retrieves logs for a specific webhook. This is useful for debugging and monitoring webhook activity. ### Method GET ### Endpoint /webhooks/logs ### Parameters #### Query Parameters - **webhookId** (int) - Required - The ID of the webhook to retrieve logs for. ### Request Example ```php getWebhookLogs(webhookId: 123); return $logs; } ``` ### Response #### Success Response (200) - **logs** (array) - A list of webhook log entries. ``` -------------------------------- ### GET /items/{itemId} Source: https://developers.basalam.com/docs/sdk/php/order-processing Retrieves the details of a specific order item using its ID. ```APIDOC ## GET /items/{itemId} ### Description Retrieves the detailed information for a specific order item. ### Method GET ### Endpoint `/items/{itemId}` ### Parameters #### Path Parameters - **`itemId`** (integer) - Required - The unique identifier of the order item. ### Request Example ```php getOrderItem( itemId: 456 ); print_r($item); ?> ``` ### Response #### Success Response (200) - **item** (object) - An object containing the full details of the order item. #### Response Example ```json { "item": { "id": 456, "order_id": 789, "product_id": 101, "quantity": 2, "price": 151.00, "created_at": "2024-01-11T11:00:00Z" } } ``` ``` -------------------------------- ### GET /webhooks/registered Source: https://developers.basalam.com/docs/sdk/php/webhook Retrieves a list of webhooks that the client is registered for. Supports pagination and filtering by service ID. ```APIDOC ## GET /webhooks/registered ### Description Retrieves a list of webhooks that the client is registered for. Supports pagination and filtering by service ID. ### Method GET ### Endpoint /webhooks/registered ### Parameters #### Query Parameters - **page** (int) - Optional - The page number for pagination. - **perPage** (int) - Optional - The number of results per page. - **serviceId** (int) - Optional - The ID of the service to filter registered webhooks by. ### Request Example ```php getRegisteredWebhooks( page: 1, perPage: 10, serviceId: 1 ); return $webhooks; } ``` ### Response #### Success Response (200) - **webhooks** (array) - A list of registered webhook objects. - **pagination** (object) - Pagination details. ``` -------------------------------- ### احراز هویت با اعتبارنامه‌های کلاینت در PHP Source: https://developers.basalam.com/docs/sdk/php/auth این کد نحوه احراز هویت با استفاده از اعتبارنامه‌های کلاینت را نشان می‌دهد. این روش برای برنامه‌های با ماهیت حقوقی و دسترسی‌های خاص مانند کیف پول مناسب است. کلاس `ClientCredentials` برای مدیریت این نوع احراز هویت استفاده می‌شود. ```php getWebhookCustomers( page: 1, perPage: 10, webhookId: 123 ); return $customers; } ``` ### Response #### Success Response (200) - **customers** (array) - A list of customer objects. - **pagination** (object) - Pagination details. ``` -------------------------------- ### دریافت اطلاعات توکن با اعتبارنامه‌های کلاینت در PHP Source: https://developers.basalam.com/docs/sdk/php/auth این کد نحوه دریافت اطلاعات توکن با استفاده از اعتبارنامه‌های کلاینت را نشان می‌دهد. متد `getToken()` از کلاس `ClientCredentials` توکن موجود را در صورت عدم انقضا بازمی‌گرداند یا توکن جدیدی دریافت می‌کند. ```php getToken(); return $tokenInfo; } ``` -------------------------------- ### GET /stats Source: https://developers.basalam.com/docs/sdk/php/order-processing Retrieves statistics related to orders, potentially filtered by vendor, product, or customer. ```APIDOC ## GET /stats ### Description Retrieves statistics about orders. The type of statistics returned depends on the `resourceCount` parameter. ### Method GET ### Endpoint `/stats` ### Parameters #### Query Parameters - **`resourceCount`** (string) - Required - Specifies the type of statistics to retrieve. Use constants from `Basalam\SDK\OrderProcessing\Models\ResourceStats` class (e.g., `ResourceStats::NUMBER_OF_ORDERS_PER_VENDOR`). - **`vendorId`** (integer) - Optional - Filters statistics for a specific vendor. - **`productId`** (integer) - Optional - Filters statistics for a specific product. - **`customerId`** (integer) - Optional - Filters statistics for a specific customer. - **`couponCode`** (string) - Optional - Filters statistics for orders with a specific coupon code. - **`cacheControl`** (string) - Optional - Controls caching behavior for the request. ### Request Example ```php getOrderStats( resourceCount: ResourceStats::NUMBER_OF_ORDERS_PER_VENDOR, vendorId: 456 ); print_r($stats); ?> ``` ### Response #### Success Response (200) - **stats** (object or array) - An object or array containing the requested order statistics. The structure depends on the `resourceCount` parameter. #### Response Example (Example for `NUMBER_OF_ORDERS_PER_VENDOR`) ```json { "stats": [ { "vendor_id": 456, "order_count": 50 }, { "vendor_id": 789, "order_count": 30 } ] } ``` ``` -------------------------------- ### Create a New Webhook Source: https://developers.basalam.com/docs/sdk/php/webhook Creates a new webhook subscription for a given service and event IDs. It allows configuration of request method, headers, URL, and activation status. ```php createWebhook( request: new CreateWebhookRequest( serviceId: 1, eventIds: [1, 2], requestHeaders: 'Content-Type: application/json', requestMethod: RequestMethodType::POST, // Enum: POST, PUT, PATCH url: 'https://your-app.com/webhook', isActive: true ) ); return $webhook; } ```