Installation
composer require beyerz/check-book-io-bundle
Add the bundle to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):
Beyerz\CheckBookIOBundle\CheckBookIOBundle::class => ['all' => true],
Configuration
Add to .env:
CHECKBOOK_PUBLISHABLE_KEY=your_publishable_key
CHECKBOOK_SECRET_KEY=your_secret_key
CHECKBOOK_SANDBOX=true
CHECKBOOK_DEBUG=false
CHECKBOOK_MERCHANT_NAME="Your Merchant"
CHECKBOOK_OAUTH_CLIENT_ID=your_client_id
Publish the default config (if needed):
php bin/console config:dump-reference check_book_io
First Use Case Inject the service in a controller or command:
use Beyerz\CheckBookIOBundle\Service\CheckBookIOService;
public function __construct(private CheckBookIOService $checkBookIO) {}
public function createCustomer(Request $request)
{
$customer = $this->checkBookIO->createCustomer([
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john@example.com',
]);
return new JsonResponse($customer);
}
Customer Management
// Create
$customer = $checkBookIO->createCustomer($data);
// Retrieve
$customer = $checkBookIO->getCustomer($customerId);
// Update
$updated = $checkBookIO->updateCustomer($customerId, $data);
// List
$customers = $checkBookIO->listCustomers(['limit' => 10]);
Payment Processing
// Create a payment
$payment = $checkBookIO->createPayment($customerId, [
'amount' => 100.00,
'currency' => 'USD',
'description' => 'Subscription',
]);
// Capture a payment
$captured = $checkBookIO->capturePayment($paymentId, $amount);
Webhooks & Events Subscribe to events via Symfony’s event dispatcher:
$dispatcher->addListener(
'checkbookio.payment.created',
[$this, 'handlePaymentCreated']
);
CHECKBOOK_SANDBOX=true) before going live.CheckBookIOException:
try {
$payment = $checkBookIO->createPayment(...);
} catch (CheckBookIOException $e) {
$this->addFlash('error', $e->getMessage());
}
oauth.handler in config.yml:
oauth:
handler: App\Service\CustomOAuthHandler
/customers, /payments) still match checkbook.io’s current docs.symfony/http-client or guzzlehttp/guzzle (if used internally) is installed.php bin/console config:dump-reference check_book_io > config/packages/check_book_io.yaml
CHECKBOOK_DEBUG=true to log raw API responses.getResponse() method for raw API errors:
try {
$checkBookIO->createPayment(...);
} catch (CheckBookIOException $e) {
error_log($e->getResponse()->getContent());
}
Custom Responses: Extend the base response handler:
class CustomResponseHandler extends \Beyerz\CheckBookIOBundle\Response\Handler
{
protected function transformResponse($response, $data)
{
// Custom logic
return parent::transformResponse($response, $data);
}
}
Then configure in config.yml:
oauth:
handler: App\Service\CustomResponseHandler
Event Subscribers: Create a subscriber for webhook events:
class CheckBookIOWebhookSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'checkbookio.payment.created' => 'onPaymentCreated',
];
}
public function onPaymentCreated(CheckBookIOEvent $event) { ... }
}
$customers = $this->cache->get('checkbook_customers', function() use ($checkBookIO) {
return $checkBookIO->listCustomers();
});
How can I help you explore Laravel packages today?