redx_courier 0.0.1
redx_courier: ^0.0.1 copied to clipboard
A Dart/Flutter client for the RedX (redx.com.bd) courier OpenAPI: create parcels, resolve delivery areas from a free-text address, and list your pickup stores (including the shop-ID vs pickup-store-ID [...]
import 'package:redx_courier/redx_courier.dart';
Future<void> main() async {
final client = RedxClient(accessToken: 'YOUR_REDX_ACCESS_TOKEN');
// Always fetch your real pickup store ID like this - don't hardcode your
// shop ID (the number in your merchant dashboard URL) as the pickup
// store ID. They're different things on RedX's side, and using the
// wrong one makes createParcel() fail with "Cannot read property
// 'PHONE' of undefined".
final stores = await client.getPickupStores();
for (final store in stores) {
print('${store.name} -> id: ${store.id}, phone: ${store.phone}');
}
if (stores.isEmpty) {
print('No pickup stores found on this account - add one in the RedX '
'merchant dashboard first.');
return;
}
final pickupStoreId = stores.first.id;
final area = await client.resolveAreaForAddress(
districtName: 'Dhaka',
customerAddress: 'House 5, Road 12, Gulshan 2, Dhaka',
);
if (area == null) {
print('Could not confidently resolve a delivery area - ask the '
'customer to pick one from client.getAreasByDistrict(...) '
'instead.');
return;
}
final result = await client.createParcel(
RedxParcelRequest(
customerName: 'Test Customer',
customerPhone: normalizeBdPhoneForRedx('+8801712345678') ?? '',
customerAddress: 'House 5, Road 12, Gulshan 2, Dhaka',
areaId: area.id,
areaName: area.name,
merchantInvoiceId: 'INV-0001',
cashCollectionAmount: 500,
parcelWeight: 1,
value: 500,
itemName: 'Sample Item',
pickupStoreId: pickupStoreId,
),
);
print('success: ${result.success}, tracking: ${result.trackingId}, '
'message: ${result.message}');
client.close();
}