PHP code example of huzaifaalmesbah / bd-courier-customer-delivery-stats
1. Go to this page and download the library: Download huzaifaalmesbah/bd-courier-customer-delivery-stats 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/ */
huzaifaalmesbah / bd-courier-customer-delivery-stats example snippets
use Ham\BdCourier\CustomerDeliveryStats\CourierCustomerStats;
$customerStats = new CourierCustomerStats([
'pathao_user' => '[email protected] ',
'pathao_password' => 'your_pathao_password',
'steadfast_user' => '[email protected] ',
'steadfast_password' => 'your_steadfast_password',
'redx_user' => '[email protected] ',
'redx_password' => 'your_redx_password',
]);
Ham\BdCourier\CustomerDeliveryStats\CourierCustomerStats;
// Initialize (will auto-load from environment variables)
$customerStats = new CourierCustomerStats();
// Check customer delivery history across all services
$result = $customerStats->check('01712345678');
print_r($result);
[
'pathao' => [
'success' => 5,
'cancel' => 2,
'total' => 7
],
'steadfast' => [
'success' => 3,
'cancel' => 1,
'total' => 4
],
'redx' => [
'success' => 6,
'cancel' => 2,
'total' => 8
]
]
use Ham\BdCourier\CustomerDeliveryStats\Helpers\PhoneValidator;
// Validate phone number
if (PhoneValidator::isValid('01712345678')) {
echo "Valid phone number";
}
// Get validation error
$error = PhoneValidator::getValidationError('+8801712345678');
echo $error; // "Invalid Bangladeshi phone number..."
// Sanitize phone number
$clean = PhoneValidator::sanitize('+88 017-1234-5678');
echo $clean; // "01712345678"
// Format with country code
$withCode = PhoneValidator::withCountryCode('01712345678');
echo $withCode; // "+8801712345678"
// Check only Pathao
$pathaoResult = $customerStats->checkPathao('01712345678');
// Check only Steadfast
$steadfastResult = $customerStats->checkSteadfast('01712345678');
// Check only RedX
$redxResult = $customerStats->checkRedX('01712345678');
try {
$result = $customerStats->check('01712345678');
if (isset($result['pathao']['error'])) {
echo "Pathao Error: " . $result['pathao']['error'];
}
if (isset($result['steadfast']['error'])) {
echo "Steadfast Error: " . $result['steadfast']['error'];
}
if (isset($result['redx']['error'])) {
echo "RedX Error: " . $result['redx']['error'];
}
} catch (Exception $e) {
echo "Configuration Error: " . $e->getMessage();
}
$result = $customerStats->check('01712345678');
$totalOrders = ($result['pathao']['total'] ?? 0) + ($result['steadfast']['total'] ?? 0) + ($result['redx']['total'] ?? 0);
$totalCancels = ($result['pathao']['cancel'] ?? 0) + ($result['steadfast']['cancel'] ?? 0) + ($result['redx']['cancel'] ?? 0);
if ($totalOrders > 0) {
$cancellationRate = ($totalCancels / $totalOrders) * 100;
if ($totalOrders < 3) {
$risk = 'NEW CUSTOMER';
} elseif ($cancellationRate > 50) {
$risk = 'HIGH RISK';
} elseif ($cancellationRate > 25) {
$risk = 'MEDIUM RISK';
} else {
$risk = 'LOW RISK';
}
echo "Risk Level: $risk (Cancellation Rate: {$cancellationRate}%)";
}
// In your controller
use Ham\BdCourier\CustomerDeliveryStats\CourierCustomerStats;
class OrderController extends Controller
{
public function checkCustomer(Request $request)
{
$customerStats = new CourierCustomerStats([
'pathao_user' => env('PATHAO_USER'),
'pathao_password' => env('PATHAO_PASSWORD'),
'steadfast_user' => env('STEADFAST_USER'),
'steadfast_password' => env('STEADFAST_PASSWORD'),
'redx_user' => env('REDX_USER'),
'redx_password' => env('REDX_PASSWORD'),
]);
$result = $customerStats->check($request->phone);
return response()->json($result);
}
}
// In functions.php or as a plugin
yStats\CourierCustomerStats;
function check_customer_delivery_stats($phone) {
$customerStats = new CourierCustomerStats([
'pathao_user' => get_option('pathao_user'),
'pathao_password' => get_option('pathao_password'),
'steadfast_user' => get_option('steadfast_user'),
'steadfast_password' => get_option('steadfast_password'),
'redx_user' => get_option('redx_user'),
'redx_password' => get_option('redx_password'),
]);
return $customerStats->check($phone);
}
// Use shortcode: [courier_delivery_stats]
add_shortcode('courier_delivery_stats', function() {
// Return customer stats form HTML
});
// In your controller (CI 3.x)
iveryStats\CourierCustomerStats;
class Customer_stats extends CI_Controller
{
public function check() {
$customerStats = new CourierCustomerStats([
'pathao_user' => $this->config->item('pathao_user'),
'pathao_password' => $this->config->item('pathao_password'),
'steadfast_user' => $this->config->item('steadfast_user'),
'steadfast_password' => $this->config->item('steadfast_password'),
'redx_user' => $this->config->item('redx_user'),
'redx_password' => $this->config->item('redx_password'),
]);
$result = $customerStats->check($this->input->post('phone'));
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
}
}
Error: Missing
Error: HTTP POST request failed: Connection timeout