PHP code example of ar2rsoft / yii2-yandex-kassa

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

    

ar2rsoft / yii2-yandex-kassa example snippets


php composer.phar 

'components' => [
	...
	'yakassa' => [
		'class' => 'ar2rsoft\yakassa\YaKassa',
		'paymentAction' => YII_DEBUG ? 'https://demomoney.yandex.ru/eshop.xml' : 'https://money.yandex.ru/eshop.xml',
		'shopPassword' => 'password',
		'securityType' => 'MD5',
		'shopId' => '12345',
		'scId' => '123',
		'currency' => '10643',
		'disableErrors' => true, # disable any error codes for yandex callback
	]
	...
]

class YaKassaController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'order-check' => ['post'],
                    'payment-notification' => ['post'],
                ],
            ]
        ];
    }

    public function actions()
    {
        return [
            'order-check' => [
                'class' => 'app\components\yakassa\actions\CheckOrderAction',
                'beforeResponse' => function ($request) {
                    /**
                     * @var \yii\web\Request $request
                     */
                    $invoice_id = (int) $request->post('orderNumber');
		                Yii::warning("Кто-то хотел купить несуществующую подписку! InvoiceId: {$invoice_id}", Yii::$app->yakassa->logCategory);
                    return false;
                }
            ],
            'payment-notification' => [
                'class' => 'app\components\yakassa\actions\PaymentAvisoAction',
                'beforeResponse' => function ($request) {
                    /**
                     * @var \yii\web\Request $request
                     */
                }
            ],
        ];
    }
}

echo ar2rsoft\yakassa\widgets\Payment::widget([
    'order' => $order,
    'userIdentity' => Yii::$app->user->identity,
	'data' => ['customParam' => 'value'],
	'paymentType' => ['PC' => 'Со счета в Яндекс.Деньгах', 'AC' => 'С банковской карты']
]);