kna / yandex-checkout-bundle
A Symfony Wrapper for the yandex-money/yandex-checkout-sdk-php library
Installs: 375
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.2
- ext-json: *
- symfony/framework-bundle: ^4.0|^5.0
- yandex-money/yandex-checkout-sdk-php: ^1.4
Requires (Dev)
- doctrine/doctrine-bundle: ^1.11|^2.0
- doctrine/orm: ^2.6
- kna/payum-yandex-checkout: dev-master
- payum/payum-bundle: ^2.3
- php-http/guzzle6-adapter: ^2.0
- symfony/console: ^4.0|^5.0
- symfony/phpunit-bridge: ^4.0|^5.0
- symfony/serializer: ^4.0|^5.0
- symfony/yaml: ^4.0|^5.0
Suggests
- doctrine/doctrine-bundle: For integration with Doctrine
- doctrine/orm: For integration with Doctrine ORM
- kna/payum-yandex-checkout: For integration with Payum
README
A Symfony wrapper for the yandex-money/yandex-checkout-sdk-php library.
Installation
composer require kna/yandex-checkout-bundle
Configuring
Add config:
// config/packages/kna_yandex_checkout.yaml kna_yandex_checkout: shop_id: '%env('YANDEX_CHECKOUT_SHOP_ID')%' secret_key: '%env('YANDEX_CHECKOUT_SECRET_KEY')%' validate_ip: true valid_ips: - 192.168.1.0/16
Add routing:
// config/routes.yaml // ... kna_yandex_checkout: resource: "@KnaYandexCheckoutBundle/Resources/config/routes.yaml" prefix: <prefix> // ...
Set https://<domain.tld>/<prefix>/<secret_key>
as URL for notifications and events in the store settings.
Usage
Use dependency injection:
<?php // src/EventListener/DefaultController.php namespace App\Controller; use YandexCheckout\Client; public function __constructor(Client $client) { $this->client = $client; }
Create event listener:
<?php // src/EventListener/YandexCheckoutSubscriber.php namespace App\EventListener; use Kna\YandexCheckoutBundle\Event\NotificationEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class YandexCheckoutSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ NotificationEvent::class => 'onNotificationReceived' ]; } public function onNotificationReceived(NotificationEvent $event) { $notification = $event->getNotification(); // dispatch notification $event->setAccepted(true); } }
Payum support
payum/payum-bundle and kna/payum-yandex-checkout should be installed.
Configuring
Add config:
// config/packages/kna_yandex_checkout.yaml kna_yandex_checkout: // ... payum: enable: true payment_class: App\Entity\Payment # default payment_id_key: payment_id force_payment_id: true
Create event listener:
<?php // src/EventListener/YandexCheckoutSubscriber.php namespace App\EventListener; use Kna\YandexCheckoutBundle\Event\CaptureRequestedEvent; use Kna\YandexCheckoutBundle\Event\PaymentCanceledEvent; use Kna\YandexCheckoutBundle\Event\PaymentCapturedEvent; use Kna\YandexCheckoutBundle\Event\PaymentSucceededEvent; use Kna\YandexCheckoutBundle\Event\RefundSucceededEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class YandexCheckoutSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ CaptureRequestedEvent::class => 'onCaptureRequested', PaymentCanceledEvent::class => 'onPaymentCancelled', PaymentCapturedEvent::class => 'onPaymentCaptured', PaymentSucceededEvent::class => 'onPaymentSucceeded', RefundSucceededEvent::class => 'onRefundSucceeded', ]; } public function onCaptureRequested(CaptureRequestedEvent $event) { // ... } public function onPaymentCancelled(PaymentCanceledEvent $event) { // ... } public function onPaymentCaptured(PaymentCapturedEvent $event) { // ... } public function onPaymentSucceeded(PaymentSucceededEvent $event) { // ... } public function onRefundSucceeded(RefundSucceededEvent $event) { // ... } }