PHP code example of kna / yandex-checkout-bundle

1. Go to this page and download the library: Download kna/yandex-checkout-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kna / yandex-checkout-bundle example snippets



// src/EventListener/DefaultController.php

namespace App\Controller;


use YandexCheckout\Client;

public function __constructor(Client $client)
{
    $this->client = $client;
}



// 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);
    }
}


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