kna / yandex-checkout-bundle
为yandex-money/yandex-checkout-sdk-php库提供的Symfony包装器
v1.0.8
2020-08-30 15:55 UTC
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
为yandex-money/yandex-checkout-sdk-php库提供的Symfony包装器。
安装
composer require kna/yandex-checkout-bundle
配置
添加配置
// 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
添加路由
// config/routes.yaml // ... kna_yandex_checkout: resource: "@KnaYandexCheckoutBundle/Resources/config/routes.yaml" prefix: <prefix> // ...
将https://<domain.tld>/<prefix>/<secret_key>
设置为通知和事件的URL,在商店设置中。
用法
使用依赖注入
<?php // src/EventListener/DefaultController.php namespace App\Controller; use YandexCheckout\Client; public function __constructor(Client $client) { $this->client = $client; }
创建事件监听器
<?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支持
payum/payum-bundle和kna/payum-yandex-checkout应已安装。
配置
添加配置
// 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
创建事件监听器
<?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) { // ... } }