neyric / mangopay-bundle
MangoPay bundle for Symfony
Installs: 930
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- mangopay/php-sdk-v2: ^2.12 || ^3.0
- symfony/console: ^4.4 || ^5.0
- symfony/event-dispatcher: ^4.4 || ^5.0
- symfony/framework-bundle: ^4.4 || ^5.0
- symfony/yaml: ^4.4 || ^5.0
Requires (Dev)
- phpunit/phpunit: >=6.0
- symfony/browser-kit: ^4.4
This package is auto-updated.
Last update: 2024-11-08 20:20:52 UTC
README
A Symfony bundle for MangoPay, providing additionnal services on top of the official MangoPay PHP SDK
- Provide a service to access the API for a better Symfony integration
- Add useful commands
- Webhook handler (HTTP controller) + Webhook Event
Requirements
- Php 7.1
- Symfony 4.4
Installation
$ composer require neyric/mangopay-bundle
Load the bundle in your app
$bundles = [ // ... new \Neyric\MangoPayBundle\NeyricMangoPayBundle(), ];
Configuration
The bundle (in particular the MangoPayService), expects those 3 environement variables to be defined
- MANGOPAY_CLIENT_ID
- MANGOPAY_PASSWORD
- MANGOPAY_BASE_URL (should be https://api.sandbox.mangopay.com or https://api.mangopay.com)
Accessing the MangoPay API
Once configured, you can use Symfony dependency injection to access the API from the sdk:
use Neyric\MangoPayBundle\Service\MangoPayService; class MyService { public function __construct(MangoPayService $mangoPayService) { $this->mangoPayService = $mangoPayService; } public function someMethod() { // You can access the public `api` property, which is the // configured instance of MangoPay\MangoPayApi $hooks = $this->mangoPayService->api->Hooks->GetAll(); } }
Symfony Commands
Display a list of installed hooks :
php bin/console neyric_mangopay:hooks:list
Display rate limits (performs 1 api call) :
php bin/console neyric_mangopay:ratelimits
Using the webhook handler
First, setup the route in your routes.yaml file :
neyric_mangopay: path: /mangopay_webook/hook_handler # Customizable url controller: Neyric\MangoPayBundle\Controller\HookController::hookHandlerAction
Then register the webhook, you want using the Mangopay console.
Create a subscriber
use Neyric\MangoPayBundle\Event\MangoPayHookEvent; class MySubscriber implements EventSubscriberInterface { public function onMangopayKycSucceeded(MangoPayHookEvent $event) { // ... } public function onMangopayUboDeclarationValidated(MangoPayHookEvent $event) { // ... } public static function getSubscribedEvents() { return [ 'MANGOPAY_KYC_SUCCEEDED' => ['onMangopayKycSucceeded', 1], 'MANGOPAY_UBO_DECLARATION_VALIDATED' => ['onMangopayUboDeclarationValidated', 1], ]; } }
And eventually declare the service with the kernel.event_subscriber
tag :
App\Subscriber\MySubscriber: class: App\Subscriber\MySubscriber tags: - { name: kernel.event_subscriber }
License
neyric/mangopay-bundle is distributed under MIT license, see the LICENSE file.
Contacts
Report bugs or suggest features using issue tracker on GitHub.