1. Go to this page and download the library: Download texhub/laklak-b2b 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/ */
texhub / laklak-b2b example snippets
use TexHub\LaklakB2b\LakLak;
use TexHub\LaklakB2b\Enums\Environment;
$laklak = LakLak::make('YOUR_API_KEY', Environment::Test); // Environment::Production when live
// Addresses
$cities = $laklak->addresses()->cities('Dush');
$terminals = $laklak->addresses()->parcelTerminals(cityId: 39720);
$pickups = $laklak->addresses()->pickupPoints(cityId: 39720);
foreach ($cities->data() as $city) {
echo $city['id'] . ' ' . $city['name'] . PHP_EOL;
}
use TexHub\LaklakB2b\Requests\ShipmentRequest;
use TexHub\LaklakB2b\Enums\DeliveryType;
use TexHub\LaklakB2b\Enums\PaymentStatus;
$shipment = $laklak->shipments()->create(
ShipmentRequest::make(
externalOrderId: 'ORD-100032',
customerPhone: '+992900123456',
deliveryType: DeliveryType::ParcelTerminal,
dropOffLocationId: 2,
paymentStatus: PaymentStatus::Unpaid,
)->customerName('Anu Lily')
);
echo $shipment->get('tracking_number'); // B2B-CODE-100001
echo $shipment->get('label_print_url'); // QR label to print & attach
// Update payment status (+ weight when paid):
$updated = $laklak->shipments()->updatePaymentStatus('ORD-100032', PaymentStatus::Paid, '2.5 KG');
echo $updated->get('parcel_terminal_password');
// Print labels for several shipments:
$laklak->shipments()->labelPrintUrl(['B2B-CODE-100001', 'B2B-CODE-100002']);
use TexHub\LaklakB2b\Enums\DeliveryStatus;
// Verify, then parse:
$laklak->webhooks()->assertValid(
$_SERVER['HTTP_X_WEBHOOK_KEY'] ?? null,
$_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? null,
);
$event = $laklak->webhooks()->parse(file_get_contents('php://input'));
if ($event->isDeliveryStatusChanged()) {
$event->trackingNumber();
$event->externalOrderId();
$event->deliveryStatus(); // DeliveryStatus enum: pending|picked_up|on_the_way|ready_to_pick|delivered|expired
$event->deliveryStatus()->isFinal(); // true for delivered/expired
$event->parcelTerminalPassword();
}
if ($event->isDeliveryAddressChanged()) {
$event->deliveryType(); // DeliveryType enum
$event->dropOffLocationId();
$event->dropOffLocation(); // full location array: id, visible_id, type, cluster, …
}
http_response_code(200); // acknowledge
use TexHub\LaklakB2b\Laravel\LakLak;
$cities = LakLak::addresses()->cities();
LakLak::shipments()->create($request);
use TexHub\LaklakB2b\LakLak;
use TexHub\LaklakB2b\Config;
use TexHub\LaklakB2b\Tests\Support\FakeTransport;
$t = (new FakeTransport())->push(['success' => true, 'data' => []]);
$laklak = new LakLak(new Config('KEY'), $t);
$laklak->addresses()->cities(); // assert on $t->last()