PHP code example of sabitahmad / laravel-steadfast
1. Go to this page and download the library: Download sabitahmad/laravel-steadfast 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/ */
sabitahmad / laravel-steadfast example snippets
use SabitAhmad\SteadFast\DTO\OrderRequest;
use SabitAhmad\SteadFast\SteadFast;
$steadfast = new SteadFast();
$order = new OrderRequest(
invoice: 'INV-2025-001',
recipient_name: 'John Doe',
recipient_phone: '01712345678',
recipient_address: 'House 1, Road 2, Dhanmondi, Dhaka-1209',
cod_amount: 1500.00,
note: 'Handle with care'
);
$response = $steadfast->createOrder($order);
echo $response->getTrackingCode();
$order = new OrderRequest(
invoice: 'INV-2025-002',
recipient_name: 'Jane Doe',
recipient_phone: '01812345678',
recipient_address: 'Banani, Dhaka',
cod_amount: 2200,
alternative_phone: '01912345678',
recipient_email: '[email protected] ',
item_description: 'Skin care products',
total_lot: 2,
delivery_type: 0
);
use SabitAhmad\SteadFast\Facades\SteadFast;
$balance = SteadFast::getBalance();
$orders = [
new OrderRequest('INV-001', 'John Doe', '01712345678', 'Address 1', 1000),
new OrderRequest('INV-002', 'Jane Smith', '01787654321', 'Address 2', 1500),
OrderRequest::fromArray([
'invoice' => 'INV-003',
'recipient_name' => 'Bob Wilson',
'recipient_phone' => '01611111111',
'recipient_address' => 'Address 3',
'cod_amount' => 2000,
'delivery_type' => 1,
]),
];
$queued = $steadfast->bulkCreate($orders, true);
$processed = $steadfast->bulkCreate($orders, false);
echo $processed->getSuccessRate();
if ($processed->hasErrors()) {
$failedOrders = $processed->getFailedOrders();
}
$status = $steadfast->checkStatusByTrackingCode('ABC123XYZ');
if ($status->isDelivered()) {
echo 'Delivered';
}
echo $status->getStatusDescription();
$steadfast->checkStatusByInvoice('INV-001');
$steadfast->checkStatusByConsignmentId(12345);
use SabitAhmad\SteadFast\DTO\ReturnRequest;
$request = ReturnRequest::byInvoice('INV-001', 'Customer requested return');
$response = $steadfast->createReturnRequest($request);
$single = $steadfast->getReturnRequest(123);
$all = $steadfast->getReturnRequests();
ReturnRequest::byConsignmentId(12345, 'Damaged item');
ReturnRequest::byTrackingCode('ABC123', 'Wrong item delivered');
$balance = $steadfast->getBalance();
echo $balance->getFormattedBalance();
// Get all payments (supports optional pagination: $steadfast->getPayments(page: 1))
$payments = $steadfast->getPayments();
foreach ($payments as $payment) {
echo "Payment ID: {$payment->id}, Amount: {$payment->amount} BDT, Status: {$payment->status}\n";
}
// Get single payment with consignments list
$payment = $steadfast->getPayment(123);
if ($payment->isCompleted()) {
echo "Payment of {$payment->amount} BDT was cleared.\n";
}
// Inspect linked consignments
foreach ($payment->consignments as $consignment) {
echo "Consignment: {$consignment['tracking_code']} - {$consignment['cod_amount']} BDT\n";
}
// Retrieve police stations (cached automatically)
$policeStations = $steadfast->getPoliceStations();
foreach ($policeStations as $station) {
echo "{$station->name} ({$station->district})\n";
}
// Force-refresh the cache if needed
$freshStations = $steadfast->getPoliceStations(forceRefresh: true);
$orderResponse->getConsignmentId();
$orderResponse->getTrackingCode();
$orderResponse->getInvoice();
$status->isPending();
$status->isCancelled();
$status->isOnHold();
$returnResponse->isPending();
$returnResponse->isCompleted();
try {
$fraud = $steadfast->checkFraud('01712345678');
echo $fraud->success;
echo $fraud->cancel;
echo $fraud->getRiskLevel();
} catch (\SabitAhmad\SteadFast\Exceptions\SteadfastException $e) {
report($e);
}
$fraud->getSuccessRate();
$fraud->getCancelRate();
$fraud->isRisky();
$fraud->getRiskDescription();
use Illuminate\Support\Facades\Event;
use SabitAhmad\SteadFast\Events\BulkOrderCompleted;
use SabitAhmad\SteadFast\Events\BulkOrderFailed;
use SabitAhmad\SteadFast\Events\BulkOrderStarted;
Event::listen(BulkOrderStarted::class, function (BulkOrderStarted $event) {
logger()->info('Bulk order processing started', [
'order_count' => count($event->orders),
'unique_id' => $event->uniqueId,
]);
});
Event::listen(BulkOrderCompleted::class, function (BulkOrderCompleted $event) {
logger()->info('Bulk order processing completed', [
'success_count' => $event->response->success_count,
'error_count' => $event->response->error_count,
'unique_id' => $event->uniqueId,
]);
});
Event::listen(BulkOrderFailed::class, function (BulkOrderFailed $event) {
logger()->error('Bulk order processing failed', [
'error' => $event->exception->getMessage(),
'unique_id' => $event->uniqueId,
]);
});
$steadfast->clearCache('balance');
$steadfast->clearCache();
use SabitAhmad\SteadFast\Exceptions\SteadfastException;
try {
$steadfast->createOrder($order);
} catch (SteadfastException $e) {
match ($e->getCode()) {
401 => report('Invalid credentials'),
422 => report($e->getContext()['validation_errors'] ?? []),
429 => report('Rate limited'),
503 => report('Service unavailable'),
default => report($e->getMessage()),
};
}
use SabitAhmad\SteadFast\Models\SteadfastLog;
$recentErrors = SteadfastLog::errors()->recent(24)->get();
$successful = SteadfastLog::successful()->recent(24)->get();
$bulkOperations = SteadfastLog::bulkOperations()->get();
$stats = SteadfastLog::getStats(24);
bash
php artisan steadfast:test
bash
php artisan steadfast:test
php artisan steadfast:stats
php artisan steadfast:stats --hours=168
php artisan steadfast:cleanup
php artisan steadfast:cleanup --force