1. Go to this page and download the library: Download basalam/php-sdk 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/ */
basalam / php-sdk example snippets
use Basalam\BasalamClient;
use Basalam\Auth\PersonalToken;
// Personal Token (Token-based authentication)
$auth = new PersonalToken(
token: "your-access-token",
refreshToken: "your-refresh-token"
);
$client = new BasalamClient(auth: $auth);
function main()
{
// Setup
$auth = new PersonalToken(
token: "your-access-token",
refreshToken: "your-refresh-token"
);
$client = new BasalamClient(auth: $auth);
// Get products
$products = $client->getProducts();
echo "Found " . count($products) . " products\n";
// Print first few products
foreach (array_slice($products, 0, 3) as $product) {
echo "Product: {$product->getName()} - Price: {$product->getPrice()}\n";
}
return $products;
}
// Run the function
$result = main();
use Basalam\BasalamClient;
use Basalam\Auth\PersonalToken;
$auth = new PersonalToken(
token: "your_existing_access_token",
refreshToken: "your_existing_refresh_token"
);
$client = new BasalamClient(auth: $auth);
use Basalam\BasalamClient;
use Basalam\Auth\AuthorizationCode;
use Basalam\Auth\Scope;
// Create auth object
$auth = new AuthorizationCode(
clientId: "your-client-id",
clientSecret: "your-client-secret",
redirectUri: "https://your-app.com/callback",
scopes: [Scope::CUSTOMER_WALLET_READ, Scope::CUSTOMER_ORDER_READ]
);
// Get authorization URL
$authUrl = $auth->getAuthorizationUrl(state: "optional_state_parameter");
echo "Visit: {$authUrl}\n";
// Exchange code for tokens (after user authorization)
$tokenInfo = $auth->getToken(code: "authorization_code_from_callback");
// Create authenticated client
$client = new BasalamClient(auth: $auth);
use Basalam\BasalamClient;
use Basalam\Auth\ClientCredentials;
use Basalam\Auth\Scope;
$auth = new ClientCredentials(
clientId: "your-client-id",
clientSecret: "your-client-secret",
scopes: [Scope::CUSTOMER_WALLET_READ, Scope::VENDOR_PRODUCT_WRITE]
);
$client = new BasalamClient(auth: $auth);
use Basalam\Core\Models\CreateVendorSchema;
// Create a new vendor
$vendor = $client->createVendor(
userId: 123,
request: new CreateVendorSchema([
'title' => "My Store",
'identifier' => "store123",
'category_type' => 1,
'city' => 1,
'summary' => "A great store for all your needs"
])
);
// Get vendor details
$vendorDetails = $client->getVendor(vendorId: $vendor->getId());
use Basalam\Chat\Models\MessageRequest;
// Create a message
$message = $client->createMessage(
request: new MessageRequest([
'chat_id' => 123,
'content' => "Hello, how can I help you?",
'message_type' => "text"
]),
userAgent: "MyApp/1.0",
xClientInfo: "web"
);
// Get messages from a chat
$messages = $client->getMessages(
chatId: 123,
limit: 20,
order: "DESC"
);
use Basalam\Order\Models\CreatePaymentRequestModel;
// Get active baskets
$baskets = $client->getBaskets(refresh: true);
// Create payment for invoice
$payment = $client->createInvoicePayment(
invoiceId: 123,
request: new CreatePaymentRequestModel([
'payment_method' => "credit_card",
'amount' => 10000
])
);
use Basalam\OrderProcessing\Models\OrderFilter;
// Get orders with filters
$orders = $client->getCustomerOrders(
filters: new OrderFilter([
'coupon_code' => "SAVE10",
'cursor' => "next_cursor_123",
'customer_ids' => "123,456,789",
'customer_name' => "John Doe"
])
);
// Get specific order details
$order = $client->getCustomerOrder(orderId: 123);
use Basalam\Wallet\Models\SpendCreditRequest;
// Get user balance
$balance = $client->getBalance(userId: 123);
// Create an expense
$expense = $client->createExpense(
userId: 123,
request: new SpendCreditRequest([
'reason_id' => 1,
'reference_id' => 456,
'amount' => 10000,
'description' => "Payment for order #456",
'types' => [1, 2],
'settleable' => true
])
);