1. Go to this page and download the library: Download foodkit/lalamove-php-api 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/ */
foodkit / lalamove-php-api example snippets
$settings = new \Lalamove\Client\V3\Settings(
'https://sandbox-rest.lalamove.com',
'API_KEY',
'API_SECRET',
\Lalamove\Client\V3\Settings::COUNTRY_SINGAPORE // country
);
$client = new Lalamove\Client\V3\Client($settings);
//////
// Create a quote:
$quotation = new \Lalamove\Requests\V3\Quotation(/* parameters here */);
// ...prepare the quotation object...
$quotationResponse = $client->quotations()->create($quotation);
// Get quotation by id
$quotationDetailsResponse = $client->quotations()->get($quotation->quotationId);
//////
// Create an order
// Provide the quotationID and stopId received from create quote and add contact information for both the sender and recipients
$contact = new \Lalamove\Requests\V3\Contact('Contact Name', '+65991111110', 'stop_id_from_quotation');
// recipient contact and instruction per stop
$recipients = [
[
'stopId' => 'stop_id_1',
'name' => 'name',
// Must be a valid number with region code (ex: +65)
'phone' => '+65991111111',
], [
'stopId' => 'stop_id_2',
'name' => 'name',
// Must be a valid number with region code (ex: +65)
'phone' => '+65991111112',
]
];
$order = new \Lalamove\Requests\V3\Order($quotationId, $sender, $recipients);
$orderResponse = $client->orders()->create($order);
// Fetch order details:
$details = $client->orders()->details($orderResponse->orderId);
// Get the driver:
// driverId from create order or by order details response
$driver = $client->drivers()->get($details->orderId, $details->driverId);
// Cancel the order:
$details = $client->orders()->cancel($orderResponse->orderId);
//////
// Create a webhook
$webhook = new \Lalamove\Requests\V3\Webhook('https://webhook.site/fd8ccc58-7447-4122-8a0c-f9c31eb79ad3');
$webhook = $client->webhooks()->create($webhook));
try {
$client->orders()->create($order);
} catch (\Lalamove\Exceptions\PaymentRequiredException $ex) {
echo 'Error: not enough funds in Lalamove wallet to create the order';
}
try {
$client->orders()->create($order);
} catch (\Lalamove\Exceptions\LalamoveException $ex) {
echo "Error: I don't know what happened, but the request failed for some reason.";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.