dvsa / mot-cpms-forms
Module that provides re-usable HTML Forms that can be used by scheme to process payments.
Installs: 2 675
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- dvsa/mot-cpms-client: ^3.1.0
- laminas/laminas-cache-storage-adapter-apcu: ^2.0
- laminas/laminas-dependency-plugin: ^2.6.0
- laminas/laminas-http: ^2.14
- laminas/laminas-hydrator: ^4.2
- laminas/laminas-i18n: ^2.9
- laminas/laminas-inputfilter: ^2.13
- laminas/laminas-json: ^3.3
- laminas/laminas-math: ^3.3
- laminas/laminas-mvc: ^3.3.0
- laminas/laminas-router: ^3.4
- laminas/laminas-session: ^2.11
- laminas/laminas-validator: ^2.14
Requires (Dev)
- captainhook/captainhook: ^5.16
- captainhook/plugin-composer: ^5.3
- dvsa/mot-cpms-common: ^3.0.0
- dvsa/mot-cpms-payment-test: ^3.0.0
- laminas/laminas-component-installer: ^3.4.0
- laminas/laminas-test: ^4.0.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-29 15:41:59 UTC
README
Introduction
A module to provide re-usable HTML Forms that can be used by scheme to process payments.
Installation
Main Setup
With composer
The recommended way to install is through Composer.
composer require dvsa/mot-cpms-forms
Post installation
-
Enable it in your application.config.php file.
<?php return array( 'modules' => array( // ... 'CpmsForms', ), // ... );
-
Copy configuration file to your autoload config folder (optional)
cp vendor/dvsa/mot-cpms-forms/config/cpms-forms.global.php.dist config/autoload/cpms-forms.global.php
Usage
For payment form generation please use controller plugin:
$form = $this->getCpmsPaymentForm($payment);
The plugin takes one argument, which must be an object that implements one of the following interfaces:
- CpmsForms\Payment\CardPaymentInterface
- CpmsForms\Payment\StoredCardPaymentInterface
- CpmsForms\Payment\DirectDebitPaymentInterface
- CpmsForms\Payment\CashPaymentInterface
- CpmsForms\Payment\ChequePaymentInterface
- CpmsForms\Payment\ChipPinPaymentInterface
- CpmsForms\Payment\PostalOrderPaymentInterface
As it might be obvious, payment interface determines required data, that needs to be provided by scheme and tells Form Factory Service to build specific for that interface form.
Each payment type always requires common information (amount, user id, etc.), so it's convenient to use CpmsForms\Payment\BasePaymentTrait
trait in your payment classes.
The cpms-forms plugin validates post data and redirects to cpms-forms controller for processing. In regard to redirection, the proper usage should be:
$form = $this->getCpmsPaymentForm($payment); if ($form instanceof \Laminas\Http\Response) { return $form; }
The form should be passed to ViewModel and be rendered via view cpms-forms helper plugin:
<?php echo $this->renderCpmsForm($form); ?>
Configuration
View scripts
If custom view script is needed to render payment form, please add this in your configuration file:
<?php
return [
'cpms_forms' => [
'partials' => [
'form' => 'custom-path/custom-script.phtml',
],
],
];
It's also possible to provide view script for specific payment type:
return [
'cpms_forms' => [
'partials' => [
'form' => 'custom-path/custom-script.phtml',
'stored_card' => 'custom-path/stored-card-script.phtml',
],
],
];
Form customization
Custom form class can be provided for specific payment type. This class must extends CpmsForms\Form\PaymentForm
class to be considered as a valid.
See example:
return [
'cpms_forms' => [
'payment_types' => [
'direct_debit' => [
'form' => 'Scheme\Form\CustomDirectDebitPaymentForm'
],
],
],
];
Form elements can be also customized. The following example sets html class of mandate_collection_day
element and adds e-mail field:
return [
'cpms_forms' => [
'payment_types' => [
'direct_debit' => [
'form_elements' => [
'mandate_collection_day' => [
'attributes' => [
'class' => 'form-control olcs-form-element',
],
],
[
'name' => 'email',
'attributes' => [
'type' => 'email',
'class' => 'form-control',
],
'options' => [
'label' => 'Customer E-mail',
'required' => true,
],
]
],
],
],
],
];
For more options, payment types and form elements please see config/module.config.php
Contributing
Please refer to our Contribution Guide.
TO DO
- Check if client is authorized to use a payment type
- Implement event manager for pre and post payment actions
- Integrate CPMS Miscellaneous Payments Module