PHP code example of kejubayer / redx-api-integration
1. Go to this page and download the library: Download kejubayer/redx-api-integration 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/ */
kejubayer / redx-api-integration example snippets
'endpoints' => [
'create_parcel' => env('REDX_CREATE_PARCEL_ENDPOINT', '/parcel'),
'track_parcel' => env('REDX_TRACK_PARCEL_ENDPOINT', '/parcel/track/{tracking_id}'),
'parcel_details' => env('REDX_PARCEL_DETAILS_ENDPOINT', '/parcel/info/{tracking_id}'),
'update_parcel' => env('REDX_UPDATE_PARCEL_ENDPOINT', '/parcels'),
'areas' => env('REDX_AREAS_ENDPOINT', '/areas'),
'create_pickup_store' => env('REDX_CREATE_PICKUP_STORE_ENDPOINT', '/pickup/store'),
'pickup_stores' => env('REDX_PICKUP_STORES_ENDPOINT', '/pickup/stores'),
'pickup_store_details' => env('REDX_PICKUP_STORE_DETAILS_ENDPOINT', '/pickup/store/info/{pickup_store_id}'),
'charge_calculator' => env('REDX_CHARGE_CALCULATOR_ENDPOINT', '/charge/charge_calculator'),
],
use Kejubayer\RedxApiIntegration\Facades\Redx;
$data = Redx::createParcel([
'customer_name' => 'Customer Name',
'customer_phone' => '01700000000',
'delivery_area' => 'Dhaka',
'delivery_area_id' => 1,
'customer_address' => 'Dhaka, Bangladesh',
'cash_collection_amount' => 1000,
'parcel_weight' => 1,
'value' => 1000,
]);
use Kejubayer\RedxApiIntegration\RedxApiIntegration;
class ParcelController
{
public function store(RedxApiIntegration $redx)
{
return $redx->createParcel([
'customer_name' => 'Customer Name',
'customer_phone' => '01700000000',
'delivery_area' => 'Dhaka',
'delivery_area_id' => 1,
'customer_address' => 'Dhaka, Bangladesh',
'cash_collection_amount' => 1000,
'parcel_weight' => 1,
'value' => 1000,
]);
}
}
use Kejubayer\RedxApiIntegration\Facades\Redx;
$parcel = Redx::createParcel([
'customer_name' => 'Customer Name',
'customer_phone' => '01700000000',
'delivery_area' => 'Dhaka',
'delivery_area_id' => 1,
'customer_address' => 'House 1, Road 2, Dhaka',
'merchant_invoice_id' => 'INV-1001',
'cash_collection_amount' => '1500',
'parcel_weight' => 1,
'instruction' => 'Handle with care',
'value' => 1500,
'is_closed_box' => false,
'pickup_store_id' => 1,
'parcel_details_json' => [
[
'name' => 'Product name',
'category' => 'Product category',
'value' => 1500,
],
],
]);
$parcel = Redx::parcelDetails('21A427TU4BN3R');
$tracking = Redx::trackParcel('25A223SU17V6CH');
$result = Redx::updateParcel(
trackingId: '21A427TU4BN3R',
propertyName: 'status',
newValue: 'cancelled',
reason: 'Customer cancelled the order'
);
$result = Redx::updateParcelRaw([
'entity_type' => 'parcel-tracking-id',
'entity_id' => '21A427TU4BN3R',
'update_details' => [
'property_name' => 'status',
'new_value' => 'cancelled',
'reason' => 'Customer cancelled the order',
],
]);
$result = Redx::cancelParcel('21A427TU4BN3R', 'Customer cancelled the order');
$areas = Redx::areas();
$areas = Redx::areas([
'district_name' => 'Dhaka',
]);
$areas = Redx::areasByPostCode(1206);
$areas = Redx::areasByDistrictName('Dhaka');
$store = Redx::createPickupStore([
'name' => 'Test Pickup Store',
'phone' => '8801898000999',
'address' => 'Test Address',
'area_id' => 1,
]);
$stores = Redx::pickupStores();
$store = Redx::pickupStoreDetails(1);
$charge = Redx::calculateCharge([
'delivery_area_id' => 12,
'pickup_area_id' => 1,
'cash_collection_amount' => 1500,
'weight' => 500,
]);
'endpoints' => [
'create_parcel' => '/parcel',
'track_parcel' => '/parcel/track/{tracking_id}',
'parcel_details' => '/parcel/info/{tracking_id}',
'update_parcel' => '/parcels',
'my_custom_endpoint' => '/merchant/custom/{id}',
],
$data = Redx::getEndpoint(
name: 'my_custom_endpoint',
replacements: ['id' => 123],
query: ['page' => 1]
);
$data = Redx::postEndpoint(
name: 'create_parcel',
payload: [
'customer_name' => 'Customer Name',
'customer_phone' => '01700000000',
]
);
$data = Redx::putEndpoint(
name: 'my_custom_endpoint',
payload: ['status' => 'updated'],
replacements: ['id' => 123]
);
$data = Redx::patchEndpoint(
name: 'my_custom_endpoint',
payload: ['status' => 'updated'],
replacements: ['id' => 123]
);
$data = Redx::deleteEndpoint(
name: 'my_custom_endpoint',
payload: ['reason' => 'Not needed'],
replacements: ['id' => 123]
);
$data = Redx::callEndpoint(
method: 'post',
name: 'my_custom_endpoint',
payload: ['key' => 'value'],
replacements: ['id' => 123]
);
$uri = Redx::endpoint('parcel_details', [
'tracking_id' => '21A427TU4BN3R',
]);
// Result: /parcel/info/21A427TU4BN3R
$data = Redx::get('/parcel/track/25A223SU17V6CH');
$data = Redx::post('/parcel', [
'customer_name' => 'Customer Name',
'customer_phone' => '01700000000',
]);
$data = Redx::put('/parcel/12345', [
'customer_address' => 'Updated address, Dhaka',
]);
$data = Redx::patch('/parcel/12345', [
'customer_address' => 'Updated address, Dhaka',
]);
$data = Redx::delete('/parcel/12345');
$data = Redx::delete('/parcel/12345', [
'reason' => 'Duplicate order',
]);
$response = Redx::request()
->withHeaders(['X-Custom-Header' => 'value'])
->post('/custom-endpoint', [
'key' => 'value',
]);
Kejubayer\RedxApiIntegration\Models\RedxWebhookRequest
use Kejubayer\RedxApiIntegration\Models\RedxWebhookRequest;
$latest = RedxWebhookRequest::query()
->latest()
->take(10)
->get();
$requests = RedxWebhookRequest::query()
->where('tracking_number', '25A223SU17V6CH')
->get();
$delivered = RedxWebhookRequest::query()
->where('status', 'delivered')
->get();
$webhookRequest->markAsProcessed();
'webhook_model' => App\Models\RedxWebhookRequest::class,
Kejubayer\RedxApiIntegration\Events\RedxWebhookReceived
use Illuminate\Support\Facades\Event;
use Kejubayer\RedxApiIntegration\Events\RedxWebhookReceived;
Event::listen(RedxWebhookReceived::class, function (RedxWebhookReceived $event) {
$webhookRequest = $event->webhookRequest;
if ($webhookRequest->status === 'delivered') {
// Update your order status here.
}
});
namespace App\Listeners;
use Kejubayer\RedxApiIntegration\Events\RedxWebhookReceived;
class ProcessRedxWebhook
{
public function handle(RedxWebhookReceived $event): void
{
$webhookRequest = $event->webhookRequest;
// Match your order by invoice number or tracking number.
$invoiceNumber = $webhookRequest->invoice_number;
$status = $webhookRequest->status;
$webhookRequest->markAsProcessed();
}
}
$response = Redx::getResponse('/parcel/track/25A223SU17V6CH');
if ($response->successful()) {
return $response->json();
}
if ($response->failed()) {
report($response->body());
}
$response->throw();
$data = Redx::createParcel($payload);
if (isset($data['validation_errors'])) {
return $data['validation_errors'];
}
bash
php artisan vendor:publish --tag=redx-config
bash
php artisan vendor:publish --tag=redx-migrations
bash
php artisan migrate
text
config/redx-api-integration.php
text
POST /redx/webhook
bash
php artisan make:listener ProcessRedxWebhook