nikitakls / yii2-unitpay-gate
UnitPay billing gate
Installs: 3 043
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4.0
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-04-02 07:09:57 UTC
README
Unitpay gate for Yii2
Installation
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist nikitakls/yii2-unitpay-gate "*"
or add
"nikitakls/yii2-unitpay-gate": "*"
to the require section of your composer.json
file.
Configuration
'components' => [
'unitpay' => [
'class' => '\nikitakls\unitpay\Merchant',
'secretKey' => '',
'publicKey' => '',
'orderCurrency' => 'RUB', # 'EUR', 'UAH', 'BYR', 'USD', 'RUB'
'locale' => 'ru',
]
...
]
Usage
Once the extension is installed, simply use it in your code by :
You can use result action in you controller:
class PaymentController extends Controller { public $enableCsrfValidation = false; public $unitpay = 'unitpay'; public function actionInvoice() { $model = new Invoice(); if ($model->load(Yii::$app->request->post()) && $model->save()) { /** @var \nikitakls\unitpay\Merchant $merchant */ $merchant = Yii::$app->get($this->unitpay); return $this->redirect($merchant->payment($model->sum, $model->id, 'Пополнение счета', Yii::$app->user->identity->email, $model->phone)); } else { return $this->render('invoice', [ 'model' => $model, ]); } } /** * @inheritdoc */ public function actions() { return [ 'result' => [ 'class' => ResultAction::class, 'payCallback' => [$this, 'payCallback'], 'checkCallback' => [$this, 'checkCallback'], 'failCallback' => [$this, 'failCallback'], ], ]; } public function payCallback(ResultParam $param) { $this->loadModel($nInvId)->updateAttributes(['status' => Invoice::STATUS_ACCEPTED]); return Yii::$app->get('unitpay')->getSuccessResponse('Pay Success'); } public function checkCallback(ResultParam $param) { if($this->loadModel($nInvId)){ return Yii::$app->get('unitpay')->getSuccessResponse('Check Success. Ready to pay.'); }; return Yii::$app->get('unitpay')->getErrorResponse('Message about error'); } public function failCallback(ResultParam $param) { $this->loadModel($nInvId)->updateAttributes(['status' => Invoice::STATUS_FAIL]); Yii::$app->errorHandler->logException($param->getErrorMessage()); return Yii::$app->get('unitpay')->getSuccessHandlerResponse('Error logged'); } }