kna/yandex-checkout-bundle

为yandex-money/yandex-checkout-sdk-php库提供的Symfony包装器

安装: 373

依赖关系: 1

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

公开问题: 0

类型:symfony-bundle

v1.0.8 2020-08-30 15:55 UTC

This package is auto-updated.

Last update: 2024-08-29 04:54:32 UTC


README

Build Status

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-bundlekna/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)
    {
        // ...
    }
}