cleentfaar/docdata-orderapi
Laravel package for integrating with Docdata’s Order API. Provides helpers to create and manage orders, send requests, and parse responses, making it easier to connect your Laravel/PHP app to Docdata payment and checkout flows.
Installation
composer require cleentfaar/docdata-orderapi
Add the service provider to config/app.php under providers:
Cleentfaar\DocDataOrderApi\DocDataOrderApiServiceProvider::class,
Configuration Publish the config file:
php artisan vendor:publish --provider="Cleentfaar\DocDataOrderApi\DocDataOrderApiServiceProvider" --tag="config"
Update .env with your DocData API credentials (e.g., DOCDATA_API_KEY, DOCDATA_API_SECRET).
First Use Case: Create an Order
use Cleentfaar\DocDataOrderApi\Facades\DocDataOrderApi;
$order = DocDataOrderApi::createOrder([
'orderNumber' => 'ORD-12345',
'amount' => 100.00,
'currency' => 'EUR',
'customer' => [
'email' => '[email protected]',
'name' => 'John Doe',
],
]);
Order Management
DocDataOrderApi::createOrder() for new orders.orderNumber or id:
$order = DocDataOrderApi::getOrder('ORD-12345');
DocDataOrderApi::updateOrder().DocDataOrderApi::cancelOrder() with a reason.Payment Integration
$payment = DocDataOrderApi::createPayment($orderId, [
'amount' => 100.00,
'paymentMethod' => 'ideal',
]);
$paymentStatus = DocDataOrderApi::getPaymentStatus($paymentId);
Webhooks
config/docdata-orderapi.php:
'webhook' => [
'enabled' => true,
'secret' => env('DOCDATA_WEBHOOK_SECRET'),
'route' => 'docdata.webhook',
],
routes/web.php:
Route::post('/docdata/webhook', [DocDataWebhookController::class, 'handle']);
event(new OrderCreated($order));
DocDataOrderApi::dispatchCreateOrder($data)->onQueue('docdata');
$validated = $request->validate([
'amount' => 'required|numeric|min:0.01',
'currency' => 'required|in:EUR,USD',
]);
API Rate Limits
try {
$response = DocDataOrderApi::getOrder($orderId);
} catch (RateLimitException $e) {
sleep($e->retryAfter);
retry();
}
Webhook Verification
secret:
$valid = hash_equals(
env('DOCDATA_WEBHOOK_SECRET'),
$request->header('X-DocData-Signature')
);
Idempotency
idempotencyKey for critical operations to avoid duplicate processing:
$order = DocDataOrderApi::createOrder($data, [
'idempotencyKey' => 'unique-key-123',
]);
Enable Logging
Add to config/docdata-orderapi.php:
'debug' => env('APP_DEBUG', false),
Logs will appear in storage/logs/laravel.log.
Mock API Calls Use Laravel’s HTTP client mocking for testing:
Http::fake([
'api.docdata.com/*' => Http::response(['success' => true], 200),
]);
Custom Responses Override default responses by binding a custom handler:
DocDataOrderApi::extend(function ($api) {
$api->onResponse(function ($response) {
// Transform response data
return $response->transform(function ($data) {
$data['custom_field'] = 'value';
return $data;
});
});
});
Middleware Add middleware to modify requests/responses globally:
DocDataOrderApi::middleware(function ($request) {
$request->header('X-Custom-Header', 'value');
});
Model Bindings Bind DocData responses to Eloquent models:
class Order extends Model {
public static function fromDocData(array $data) {
return self::create([
'docdata_id' => $data['id'],
'amount' => $data['amount'],
]);
}
}
How can I help you explore Laravel packages today?