Download the PHP package kejubayer/redx-api-integration without Composer
On this page you can find all versions of the php package kejubayer/redx-api-integration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kejubayer/redx-api-integration
More information about kejubayer/redx-api-integration
Files in kejubayer/redx-api-integration
Package redx-api-integration
Short Description Laravel package for integrating the RedX API and storing RedX webhook requests.
License MIT
Informations about the package redx-api-integration
Laravel RedX API Integration Package
kejubayer/redx-api-integration is a Laravel package for RedX courier API integration in Bangladesh. It provides a simple RedX HTTP client, configurable API endpoints, a webhook route, and automatic storage of RedX webhook payloads in a database table.
Use this package to create RedX parcels, track parcels, cancel parcels, call configured RedX API endpoints, and receive RedX delivery status webhook updates in your Laravel application.
Features
- Laravel auto-discovery support
- RedX API client using Laravel HTTP client
- Configurable RedX base URL, API token header, timeout, and endpoints
- Easy named methods for common RedX endpoints
- Generic endpoint-name helpers for all custom RedX endpoints
- Built-in RedX webhook route
- Stores every webhook request in
redx_webhook_requests - Extracts searchable webhook fields like tracking number, status, invoice number, and delivery type
- Optional webhook shared-secret protection
- Event dispatch after every stored webhook request
- Supports Laravel 10, Laravel 11, and Laravel 12
Requirements
- PHP 8.1 or higher
- Laravel 10, 11, or 12
- Composer
Installation
Install the package with Composer:
Publish the configuration file:
Publish the migration:
Run the migration:
Environment Variables
Add your RedX API credentials to .env:
Optional webhook secret protection:
RedX expects the token in this HTTP header:
So REDX_TOKEN_HEADER is the header name, and REDX_API_TOKEN is the full header value.
Configuration
After publishing, the config file is available at:
Default endpoint configuration:
If your RedX merchant account uses different endpoint paths, update the config or set these .env values:
Basic Usage
Use the facade:
Use dependency injection:
Available Methods
Quick method list:
| Method | Purpose |
|---|---|
Redx::createParcel($payload) |
Create a RedX parcel |
Redx::trackParcel($trackingId) |
Track parcel by tracking number |
Redx::parcelDetails($trackingId) |
Get parcel details by tracking ID |
Redx::updateParcel($trackingId, $propertyName, $newValue, $reason) |
Update a parcel property |
Redx::updateParcelRaw($payload) |
Update a parcel with the full RedX payload |
Redx::cancelParcel($trackingId, $reason) |
Cancel parcel by tracking ID |
Redx::areas($query) |
Get RedX areas |
Redx::areasByPostCode($postCode) |
Get areas by postal code |
Redx::areasByDistrictName($districtName) |
Get areas by district name |
Redx::createPickupStore($payload) |
Create pickup store |
Redx::pickupStores($query) |
Get pickup stores |
Redx::pickupStoreDetails($pickupStoreId) |
Get pickup store details |
Redx::calculateCharge($query) |
Calculate parcel charge |
Redx::getEndpoint($name, $replacements, $query) |
Call a configured GET endpoint |
Redx::postEndpoint($name, $payload, $replacements) |
Call a configured POST endpoint |
Redx::putEndpoint($name, $payload, $replacements) |
Call a configured PUT endpoint |
Redx::patchEndpoint($name, $payload, $replacements) |
Call a configured PATCH endpoint |
Redx::deleteEndpoint($name, $payload, $replacements) |
Call a configured DELETE endpoint |
Redx::callEndpoint($method, $name, $payload, $replacements) |
Call any configured endpoint dynamically |
Redx::endpoint($name, $replacements) |
Resolve a configured endpoint path |
Redx::get($uri, $query) |
Raw GET request |
Redx::post($uri, $payload) |
Raw POST request |
Redx::put($uri, $payload) |
Raw PUT request |
Redx::patch($uri, $payload) |
Raw PATCH request |
Redx::delete($uri, $payload) |
Raw DELETE request |
Redx::request() |
Get the configured Laravel HTTP client |
Redx::getResponse($uri, $query) |
Raw GET request with Laravel response object |
Redx::postResponse($uri, $payload) |
Raw POST request with Laravel response object |
Redx::putResponse($uri, $payload) |
Raw PUT request with Laravel response object |
Redx::patchResponse($uri, $payload) |
Raw PATCH request with Laravel response object |
Redx::deleteResponse($uri, $payload) |
Raw DELETE request with Laravel response object |
createParcel
Create a new RedX parcel.
Required RedX create parcel fields usually include:
Use merchant_invoice_id for your invoice number when creating a parcel. Webhook payloads may return that value as invoice_number.
parcelDetails
Get RedX parcel details by tracking ID.
trackParcel
Track a parcel by RedX tracking number.
updateParcel
Update a RedX parcel property.
Send the exact RedX update payload:
cancelParcel
Cancel a parcel by tracking ID. This is a shortcut for updateParcel($trackingId, 'status', 'cancelled', $reason).
areas
Get RedX delivery areas.
With query parameters:
Get areas by post code:
Get areas by district name:
createPickupStore
Create a RedX pickup store.
pickupStores
Get RedX pickup stores.
pickupStoreDetails
Get pickup store details.
calculateCharge
Calculate RedX parcel charge.
Easy Use For All Endpoints
You can add any RedX API endpoint to config/redx-api-integration.php and call it by name.
Example config:
Call a configured GET endpoint:
Call a configured POST endpoint:
Call a configured PUT endpoint:
Call a configured PATCH endpoint:
Call a configured DELETE endpoint:
Call any configured endpoint dynamically:
Resolve only the endpoint path:
get
Call any RedX GET endpoint.
post
Call any RedX POST endpoint.
put
Call any RedX PUT endpoint.
patch
Call any RedX PATCH endpoint.
delete
Call any RedX DELETE endpoint.
With a request body:
request
Get the configured Laravel HTTP pending request instance.
Webhook Route
The package registers this route by default:
You can change the route path:
You can disable the route:
RedX Webhook Payload Structure
Expected RedX webhook JSON payload:
Example payload:
Webhook Database Structure
Webhook requests are stored in the redx_webhook_requests table.
| Column | Type | Description |
|---|---|---|
id |
integer | Primary key |
tracking_number |
string, nullable | RedX tracking number |
redx_timestamp |
timestamp, nullable | Timestamp sent by RedX |
status |
string, nullable | Parcel status |
message_en |
string, nullable | English status message |
message_bn |
string, nullable | Bangla status message |
invoice_number |
string, nullable | Merchant invoice number |
delivery_type |
string, nullable | RedX delivery type |
payload |
json | Full webhook payload |
headers |
json, nullable | Request headers |
ip_address |
string, nullable | Sender IP address |
user_agent |
string, nullable | Request user agent |
signature |
string, nullable | Signature header value, when available |
processed_at |
timestamp, nullable | Processing timestamp for your application |
created_at |
timestamp | Created timestamp |
updated_at |
timestamp | Updated timestamp |
Webhook Model
The default model is:
Query stored webhooks:
Find webhook requests by tracking number:
Find delivered parcels:
Mark a webhook request as processed:
Use your own model:
Your custom model should extend the package model or provide the same fillable columns.
Webhook Event
After storing a webhook request, the package dispatches:
Listen for the event:
Create a listener:
Example listener:
Secure Webhooks
Set a shared secret in your .env:
RedX must send the same secret value in the configured header. If the secret does not match, the package returns 403 Forbidden.
Testing Webhook Locally
You can test the webhook route with curl:
With webhook secret:
Raw Response Usage
Normal package methods return PHP arrays directly. If you need the raw Laravel Illuminate\Http\Client\Response object, use the *Response methods or request().
Error Handling
Because normal methods return arrays, RedX validation errors are available directly:
License
The MIT License.
All versions of redx-api-integration with dependencies
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/routing Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0