Yandex Kassa
Yandex kassa as Yii2 component, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist kroshilin/yii2-yandex-kassa "*"
or add, (*4)
"kroshilin/yii2-yandex-kassa": "*"
to the require section of your composer.json
file., (*5)
Usage
First, add extension under the components section of your config.php, (*6)
'components' => [
...
'yakassa' => [
'class' => 'kroshilin\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'
]
...
]
Create controller and configure actions for checkOrder and paymentAviso yandex requests
If need, you can use callable 'beforeResponse' property of actions, to define additional checks of Yandex's requests.
Depends on result of 'beforeResponse' (true||false) action would generate corresponding response., (*7)
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
*/
}
],
];
}
}
Using widget is simple. You have to implement 2 interfaces. First is OrderInterface for your order model, to pass sum and id to form.
Second is Customer interface, to pass customer id and pre-fill phone and email if exist., (*8)
echo kroshilin\yakassa\widgets\Payment::widget([
'order' => $order,
'userIdentity' => Yii::$app->user->identity,
'data' => ['customParam' => 'value'],
'paymentType' => ['PC' => 'Со счета в Яндекс.Деньгах', 'AC' => 'С банковской карты']
]);