Installation
composer require checkout-bundle/checkout:dev-master
(Note: Use dev-master due to outdated releases; prefer direct GitHub dependency if possible.)
Register Bundle
In config/app.php (Laravel 5.5+) or AppKernel.php (Laravel <5.5):
'providers' => [
// ...
Checkout\PaymentBundle\CheckoutPaymentBundle::class,
],
Publish Config
php artisan vendor:publish --provider="Checkout\PaymentBundle\CheckoutPaymentBundle"
(Edit config/checkout.php for API keys, endpoints, etc.)
Route Integration
Add to routes/web.php:
Route::prefix('checkout')->group(function () {
require __DIR__.'/vendor/checkout-bundle/checkout/src/Checkout/PaymentBundle/Resources/config/routing.yml';
});
First Use Case Trigger a payment in a controller:
use Checkout\PaymentBundle\Service\CheckoutService;
public function initiatePayment(CheckoutService $checkout)
{
$response = $checkout->createPaymentSession([
'amount' => 1000, // cents
'currency' => 'EUR',
'success_url' => route('payment.success'),
'failure_url' => route('payment.failure'),
]);
return redirect($response->getRedirectUrl());
}
Payment Initiation
CheckoutService to create sessions:
$session = $checkout->createPaymentSession($params);
$session->setMetadata(['order_id' => 123]);
Webhook Handling
/checkout/webhook and validate signatures:
public function handleWebhook(Request $request, CheckoutService $checkout)
{
if (!$checkout->validateWebhook($request)) {
abort(403);
}
$event = $checkout->parseWebhook($request);
// Process event (e.g., capture, refund)
}
Subscription Management
$subscription = $checkout->createSubscription([
'amount' => 2000,
'interval' => 'month',
'customer' => $customerId,
]);
Service Integration
CheckoutService as a custom driver by extending CashierServiceProvider.dispatch(new ProcessWebhook($event))->onQueue('checkout');
Service Container Binding Bind the service manually if autowiring fails:
$this->app->bind(CheckoutService::class, function ($app) {
return new CheckoutService($app['config']['checkout']);
});
Middleware for API Keys Protect routes with middleware to validate API keys:
Route::middleware(['checkout.auth'])->group(function () {
// Protected routes
});
Testing
Use CheckoutService mocks in PHPUnit:
$mock = Mockery::mock(CheckoutService::class);
$mock->shouldReceive('createPaymentSession')->andReturn(new PaymentSession());
$this->app->instance(CheckoutService::class, $mock);
Deprecated API
Configuration Quirks
config/checkout.php:
'secret_key' => base64_encode('your_secret_key'),
'api_url' => env('CHECKOUT_API_URL', 'https://api.classic.checkout.com'),
Webhook Validation
if (!$checkout->validateWebhook($request, $request->header('X-Signature'))) {
// Reject
}
idempotency_key in requests to avoid duplicate processing.Error Handling
try {
$response = $checkout->createPaymentSession($params);
} catch (\Checkout\PaymentBundle\Exception\ApiException $e) {
Log::error($e->getMessage(), ['error_code' => $e->getCode()]);
abort(500);
}
Enable Logging
Add to config/logging.php:
'channels' => [
'checkout' => [
'driver' => 'single',
'path' => storage_path('logs/checkout.log'),
'level' => 'debug',
],
],
Then configure the service to use the channel:
$checkout = new CheckoutService($config, new \Monolog\Logger('checkout'));
API Request Inspection
Extend CheckoutService to log raw requests:
protected function doRequest($method, $uri, $params)
{
Log::debug('Checkout Request', [
'method' => $method,
'uri' => $uri,
'params' => $params,
]);
return parent::doRequest($method, $uri, $params);
}
Custom Payment Methods
Extend Checkout\PaymentBundle\Model\Payment to add fields:
class CustomPayment extends Payment
{
protected $customField;
public function setCustomField($value)
{
$this->customField = $value;
return $this;
}
}
Event Dispatching Listen for payment events via Laravel’s event system:
// In a service provider
$checkout->on('payment.succeeded', function ($event) {
event(new PaymentSucceeded($event->getPayment()));
});
Testing Environment
Use the sandbox endpoint in .env:
CHECKOUT_API_URL=https://sandbox.classic.checkout.com
CHECKOUT_SECRET_KEY=your_sandbox_key
How can I help you explore Laravel packages today?