1. Go to this page and download the library: Download malpka32/inpost-buy-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/ */
malpka32 / inpost-buy-sdk example snippets
use malpka32\InPostBuySdk\Client\InPostBuyClient;
use malpka32\InPostBuySdk\Dto\Common\ListSort;
use malpka32\InPostBuySdk\Dto\Offer\OfferStatus;
use malpka32\InPostBuySdk\Dto\Order\OrderStatus;
use Symfony\Component\HttpClient\HttpClient;
$client = new InPostBuyClient(
httpClient: HttpClient::create(),
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
organizationId: 'your-org-uuid',
sandbox: true, // use false for production
);
// Fetch categories
$categories = $client->getCategories();
foreach ($categories as $category) {
echo $category->name . " (" . $category->id . ")\n";
}
// Fetch offers
$offers = $client->getOffers(offerStatus: [OfferStatus::PUBLISHED], limit: 20);
// Fetch orders
$orders = $client->getOrders(status: OrderStatus::CREATED, sort: [ListSort::CREATED_AT_DESC]);
use malpka32\InPostBuySdk\Config\Language;
// Polish (default)
$client = new InPostBuyClient(..., language: Language::Polish);
// English
$client = InPostBuyClient::createWithTokenProvider(..., language: Language::English);
$tree = $client->getCategories(); // one API call, returns CategoryTreeCollection
foreach ($tree as $root) {
echo $root->name . "\n";
foreach ($root->children as $child) {
echo " " . $child->name . "\n";
}
}
use malpka32\InPostBuySdk\Client\InPostBuyClient;
use malpka32\InPostBuySdk\Dto\Offer\OfferDto;
use malpka32\InPostBuySdk\Dto\Offer\PriceDto;
use malpka32\InPostBuySdk\Dto\Offer\Product\DimensionDto;
use malpka32\InPostBuySdk\Dto\Offer\Product\ProductDto;
use malpka32\InPostBuySdk\Dto\Offer\StockDto;
use malpka32\InPostBuySdk\Collection\AttributeValueCollection;
use malpka32\InPostBuySdk\Dto\Attribute\AttributeValueDto;
$product = new ProductDto(
name: 'Cool T-Shirt',
description: 'Comfortable cotton t-shirt in various sizes.',
brand: 'MyBrand',
categoryId: '67909821-cc25-45ec-80ce-5ac4f2f01032', // from getCategories()
sku: 'TSHIRT-001',
ean: '5901234567890',
attributes: AttributeValueCollection::fromAttributes(
new AttributeValueDto('attr-color-uuid', ['Red'], 'en'),
new AttributeValueDto('attr-size-uuid', ['M', 'L'])
),
dimension: new DimensionDto(width: 200, height: 50, length: 300, weight: 200) // mm, g
);
$offer = new OfferDto(
externalId: 'SKU-TSHIRT-001',
product: $product,
stock: new StockDto(quantity: 10, unit: 'UNIT'),
price: new PriceDto(amount: 99.99, currency: 'PLN', taxRateInfo: '23%')
);
$result = $client->putOffer($offer);
echo "Created offer ID: {$result->offerId}\n";
use malpka32\InPostBuySdk\Collection\OfferCollection;
$offers = OfferCollection::fromOffers($offer1, $offer2, $offer3);
$ids = $client->putOffers($offers);
foreach ($ids as $id) {
echo "Created: $id\n";
}