Installation
composer require cmiecom/cmi-pay-bundle
Ensure routes.xml is included in config/routes.yaml:
_cmi_pay:
resource: '@CmiPayBundle/Resources/config/routes.xml'
Configure CMI Gateway
Add CMI credentials to your .env or config/packages/cmi_pay.yaml:
cmi_pay:
merchant_id: 'YOUR_MERCHANT_ID'
merchant_password: 'YOUR_PASSWORD'
test_mode: true # Set to false for production
First Use Case: Render Payment Form
Use the default route /cmi/requestpayment to render the payment form:
// In your controller
return $this->render('your_template.html.twig', [
'cmi_pay_form' => $this->get('cmi_pay.form_builder')->buildForm($orderId, $amount, $currency)
]);
Payment Request Flow
CmiPayFormBuilder (e.g., in Twig):
{{ form_start(cmi_pay_form) }}
{{ form_widget(cmi_pay_form) }}
<button type="submit">Pay with CMI</button>
{{ form_end(cmi_pay_form) }}
/cmi/requestpayment, which redirects the user to CMI’s payment page.Callback Handling
/cmi/callback):
<route id="cmi_pay_callback" path="/cmi/callback" controller="cmi.pay.controller::callback" />
public function callback(Request $request) {
$validator = $this->get('cmi_pay.validator');
if ($validator->validateCallback($request)) {
// Process successful payment (e.g., update order status)
}
return new Response('Callback processed');
}
Order Integration
CmiPayFormBuilder:
$form = $this->get('cmi_pay.form_builder')->buildForm(
$order->getId(),
$order->getAmount(),
$order->getCurrency()
);
CmiPayFormBuilder.symfony/workflow) to transition order states post-callback.$this->get('logger')->info('CMI Callback', ['data' => $request->request->all()]);
Callback Validation
CmiPayValidator to prevent fraud:
if (!$validator->validateCallback($request)) {
throw new \RuntimeException('Invalid CMI callback');
}
test_mode: true) before going live.Redirect URLs
okUrl (success) and failUrl (failure) in the form are absolute URLs (e.g., https://yourdomain.com/payment/success).UrlGeneratorInterface for dynamic URLs:
$okUrl = $this->generateUrl('payment_success', [], UrlGeneratorInterface::ABSOLUTE_URL);
Deprecated Package
test_mode: true to simulate transactions without real payments.var/log/dev.log for CMI API errors.Custom Form Fields Override the form builder service:
# config/services.yaml
CmiPayBundle\Form\CmiPayFormBuilder:
arguments:
- '@form.factory'
- '@cmi_pay.default_options'
tags: ['cmi_pay.form_builder']
Extend CmiPayFormBuilder to add fields like customer_email.
Webhook Handling For async notifications, create a custom controller to handle CMI’s webhook payloads.
Refunds/Voids The bundle doesn’t support these out-of-the-box. Implement via CMI’s API directly or extend the bundle.
How can I help you explore Laravel packages today?