An open API service indexing awesome lists of open source software.

https://github.com/tarikmanoar/laravel-steadfast

A Laravel package that provides seamless integration with Steadfast Courier API services.
https://github.com/tarikmanoar/laravel-steadfast

courier laravel-steadfast steadfast

Last synced: 10 months ago
JSON representation

A Laravel package that provides seamless integration with Steadfast Courier API services.

Awesome Lists containing this project

README

          

# Laravel Steadfast Courier API

A Laravel package that provides seamless integration with Steadfast Courier API services.

## Installation

Install the package via Composer:

```bash
composer require manoar/laravel-steadfast
```

## Configuration

1. Publish the configuration file:

```bash
php artisan vendor:publish --provider="Manoar\Steadfast\SteadfastServiceProvider"
```

2. Configure your credentials in your `.env` file:

```env
STEADFAST_API_KEY=your_api_key
STEADFAST_API_SECRET=your_api_secret
STEADFAST_API_URL=https://api.steadfast.com
```

## Usage

### Facade Usage

```php
'INV-123',
'recipient_name' => 'John Doe',
'recipient_phone' => '01700000000',
'recipient_address' => '123 Main St, Dhaka',
'cod_amount' => 1500,
'note' => 'Please handle with care'
]);

$consignmentId = $response['consignment']['consignment_id'];
$trackingCode = $response['consignment']['tracking_code'];

// Get order status
$status = Steadfast::getStatusByConsignmentId($consignmentId);

// Check balance
$balance = Steadfast::getBalance();
} catch (SteadfastApiException $e) {
// Handle errors
$message = $e->getMessage();
$responseData = $e->getApiErrorData();
$statusCode = $e->getCode();
}
```

### Dependency Injection

```php
steadfast = $steadfast;
}

public function placeOrder(Request $request)
{
try {
$response = $this->steadfast->createOrder([
'invoice' => $request->invoice_id,
'recipient_name' => $request->name,
'recipient_phone' => $request->phone,
'recipient_address' => $request->address,
'cod_amount' => $request->amount,
'note' => $request->note
]);

return response()->json(['success' => true, 'data' => $response]);
} catch (SteadfastApiException $e) {
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
}
}
}
```

## Available Methods

| Method | Description |
|--------|-------------|
| `createOrder(array $data)` | Create a new order/consignment |
| `placeBulkOrders(array $orders)` | Place multiple orders in bulk (max 500) |
| `getStatusByConsignmentId(string\|int $consignmentId)` | Get status by Consignment ID |
| `getStatusByInvoice(string $invoiceId)` | Get status by Invoice ID |
| `getStatusByTrackingCode(string $trackingCode)` | Get status by Tracking Code |
| `getBalance()` | Get merchant account balance |

## Error Handling

The package throws `SteadfastApiException` on API failures, providing:

- Error message via `getMessage()`
- HTTP status code via `getCode()`
- API error data via `getApiErrorData()`
- Full HTTP response via `getResponse()`

## Local Development

To develop this package locally:

1. Create a directory structure:
```bash
packages/manoar/laravel-steadfast/
```

2. Add to your Laravel project's `composer.json`:
```json
"repositories": [
{
"type": "path",
"url": "packages/manoar/laravel-steadfast"
}
],
"require": {
"manoar/laravel-steadfast": "@dev"
}
```

3. Run `composer update manoar/laravel-steadfast`

## License

The MIT License (MIT). Please see License File for more information.

## Contributing

Contributions are welcome! Please follow the coding standards and include tests for new features or bug fixes.