PHP code example of mikefinch / yii2-yandex-kassa-api

1. Go to this page and download the library: Download mikefinch/yii2-yandex-kassa-api 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/ */

    

mikefinch / yii2-yandex-kassa-api example snippets


'components' => [
    ...
    'kassa' => [
        'class' => 'mikefinch\YandexKassaAPI\YandexKassaAPI',
        'returnUrl' => '',
        'shopId' => '',
        'key' => '',
    ],

class Orders extends Model implements OrderInterface {
    
    ...
      
    public function setInvoiceId($invoiceId) {
        $this->invoice_id = $invoiceId;
    }

    
    public function getInvoiceId() {
        return $this->invoice_id;
    }

    
    public function getPaymentAmount() {
        return $this->amount;
    }

    
    public function findByInvoiceId($invoiceId) {
        return self::find()->where(['invoice_id' => $invoiceId]);
    }
    
    public function findById($id) {
        return self::findOne($id);
    }

}


 public function actions() {
        return [
            'create-payment' => [
                'class'=>'mikefinch\YandexKassaAPI\actions\CreatePaymentAction',
                'orderClass' => Orders::className(),
                'beforePayment' => function($order) {
                    return $order->status == Orders::STATUS_NEW;
                }
            ],
            'notify' => [
                'class'=>'mikefinch\YandexKassaAPI\actions\ConfirmPaymentAction',
                'orderClass' => Orders::className(),
                'beforeConfirm' => function($payment, $order) {
                    $order->status = Orders::STATUS_PAID; 
                    return $order->save();
                }
            ]
        ];
    }



if ($order->payment_type == $order::PAYTYPE_ONLINE) {
    return $this->redirect(['order/create-payment', 'id' =>$order->id]);
} else {
    return $this->redirect(['order/success']);
}

php composer.phar