avaibooksports / redsys-messages
Redsys/Sermepa/Servired gateway message lists
Installs: 5 615
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 5
Open Issues: 0
pkg:composer/avaibooksports/redsys-messages
Requires
- php: ^7.4||^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^9.6
Suggests
- avaibooksports/omnipay-redsys: An Omnipay driver for Redsys
- league/omnipay: A payment processing library compatible with multiple payment gateways
README
Installation
composer require avaibooksports/redsys-messages
Usage
To use the built-in translations, just load the standard catalog:
use AvaiBookSports\Component\RedsysMessages; $redsysMessages = new RedsysMessages\Factory(new RedsysMessages\Loader\CatalogLoader()); // Returns "Expired card" $redsysMessages->createCatalogByLanguage('en')->getDsResponseMessage('0101'); // You can load catalogs by ISO 639-1 and ISO 639-2 $redsysMessages->createCatalogByLanguage('eng')->getDsResponseMessage('0101'); // There is a different library for error messages. Those error codes can be provided by Redsys in two different formats: $redsysMessages->createCatalogByLanguage('en')->getErrorMessage('9002')); $redsysMessages->createCatalogByLanguage('en')->getErrorMessage('SIS0002')); // Alias of '9002'
Creating and loading custom catalogs
To load a custom catalog, you must implement one or multiple classes implementing AvaiBookSports\Component\RedsysMessages\CatalogInterface.
After that, you just have to invoke the factory with an ArrayLoader:
// src/Redsys/Messages/Italian.php namespace App\Redsys\Messages; use AvaiBookSports\Component\RedsysMessages\CatalogInterface; class English implements CatalogInterface { /** * @var string[] */ private $dsResponseMessages = [ '0101' => 'Carta scaduta', // ... ]; /** * {@inheritdoc} */ public static function getIso639Alpha2() { return 'it'; } /** * {@inheritdoc} */ public static function getIso639Alpha3() { return 'ita'; } /** * {@inheritdoc} */ public function getDsResponseMessage($code) { if (array_key_exists($code, $this->dsResponseMessages)) { return $this->dsResponseMessages[$code]; } return null; } }
use AvaiBookSports\Component\RedsysMessages; $redsysMessages = new RedsysMessages\Factory( new RedsysMessages\Loader\ArrayLoader([ \App\Redsys\Messages\Italian::class, // ... ]) ); // "Carta scaduta" $redsysMessages->createCatalogByLanguage('it')->getDsResponseMessage('0101');
Loading multiple catalogs
Probably you will want to load all the catalogs included in this library, and some custom catalogs for not supported languages.
You can use the ChainLoader for that purpose:
use AvaiBookSports\Component\RedsysMessages; $redsysMessages = new RedsysMessages\Factory( new RedsysMessages\ChainLoader([ new RedsysMessages\Loader\CatalogLoader(), new RedsysMessages\Loader\ArrayLoader([ \App\Redsys\Messages\Italian::class, // ... ]) new App\Redsys\Loader\MyCustomLoader(), // Maybe you want to implement your own loader? ]) );
AvaiBookSports\Component\RedsysMessages\CatalogInterface\Factory will allow as a parameter any class implementing
AvaiBookSports\Component\RedsysMessages\CatalogInterface\CatalogLoaderInterface, and ChainLoader will allow you to load
multiple catalogs at once, so nothing stops you from making your custom catalog loader.
Contributing
Contributions are very welcome, especially catalog translations. If you made your catalog to support your native language, please consider making a pull request.
- Just keep an eye on the tests vendor/bin/simple-phpunitand don't use type-hinting except forarrayandobjectto support PHP 5. Use phpDoc.
- Fix your code formatting with vendor/bin/php-cs-fixer fix
- Take a look at psalmto check what you can improve
Following these steps will guarantee you a green check in the pull request!