1. Go to this page and download the library: Download devrkb21/czbd-courier 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/ */
devrkb21 / czbd-courier example snippets
use CourierChecker;
$report = CourierChecker::check('01712345678');
use CourierChecker;
$report = CourierChecker::check('01712345678');
use Czbd\CourierChecker\CourierCheckerManager;
class OrderController
{
public function show(CourierCheckerManager $manager)
{
return $manager->check('01712345678');
}
}
use Czbd\CourierChecker\Services\PathaoService;
use Czbd\CourierChecker\Services\SteadfastService;
use Czbd\CourierChecker\Services\RedxService;
use Czbd\CourierChecker\Services\PaperflyService;
use Czbd\CourierChecker\Services\CarrybeeService;
$result = app(PathaoService::class)->getDeliveryStats('01712345678');
use CourierChecker;
class CheckoutController
{
public function placeOrder(Request $request)
{
$report = CourierChecker::check($request->input('phone'));
$ratio = $report['aggregate']['success_ratio'];
$totalOrders = $report['aggregate']['total_deliveries'];
// Only apply the rule once there's enough history to judge -
// a brand-new customer with 0 orders isn't "risky", just unknown.
if ($totalOrders >= 3 && $ratio < 50.0) {
return back()->withErrors([
'phone' => 'This number has a high cancellation rate. COD is unavailable; please pay online.',
]);
}
// ...proceed with order creation
}
}
// Invalid input, courier auth failure, unexpected/malformed response, etc.
[
'error' => 'Failed to authenticate with Pathao',
'status' => 401, // present when caused by an HTTP response
]
// Courier not configured at all (missing credentials)
[
'error' => 'pathao is not configured',
'message' => 'No valid credentials configured for Pathao. Set at least one account.',
]
[
'error' => 'Service unavailable or failed to process',
'message' => '<exception message>',
]
foreach (['steadfast', 'pathao', 'redx', 'paperfly', 'carrybee'] as $courier) {
if (isset($report[$courier]['error'])) {
// handle/log the per-courier failure
}
}