lan143 / yii2-interkassa
用于整合Interkassa到yii2项目的扩展
这个包的官方仓库似乎已经不存在,因此该包已被冻结。
0.1.0
2017-02-23 09:53 UTC
Requires
- php: >=7.0.0
- yiisoft/yii2: *
- yiisoft/yii2-httpclient: ~2.0.0
This package is not auto-updated.
Last update: 2023-04-29 12:25:59 UTC
README
Yii2 Interkassa
用于整合Interkassa到yii2项目的扩展。正在进行中(WIP)。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
php composer.phar require --prefer-dist lan143/yii2-interkassa "*"
或者在您的 composer.json 文件的 require 部分添加:
"lan143/yii2-interkassa": "*"
更新配置文件 config/web.php
return [ 'components' => [ 'interkassa' => [ 'class' => 'lan143\interkassa\Component', 'co_id' => '', // Cashbox identifier 'secret_key' => '', // Cashbox secret key 'test_key' => '', // Cashbox test secret key 'sign_algo' => 'md5', // Sign algoritm. Allow: md5, sha1 'api_user_id' => '', // Api user id 'api_user_key' => '' // Api user secret key ], ], ]
使用方法
示例支付
class InterkassaController extends Controller { public function actions() { return [ 'result' => [ 'class' => 'lan143\interkassa\ResultAction', 'callback' => [$this, 'resultCallback'], ], 'success' => [ 'class' => 'lan143\interkassa\SuccessAction', 'callback' => [$this, 'successCallback'], ], 'fail' => [ 'class' => 'lan143\interkassa\FailAction', 'callback' => [$this, 'failCallback'], ], ]; } public function actionInvoice() { $model = new Invoice(); if ($model->load(Yii::$app->request) && $model->save()) { $params = [ 'ik_pm_no' => $model->id, 'ik_am' => $model->ammount, 'ik_desc' => 'Site payment', ]; return Yii::$app->interkassa->payment($params); } return $this->render('invoice', compact($model)); } public function successCallback($ik_am, $ik_inv_st, $ik_pm_no) { return $this->render('success'); } public function failCallback($ik_am, $ik_inv_st, $ik_pm_no) { return $this->render('fail'); } public function resultCallback($ik_am, $ik_inv_st, $ik_pm_no) { switch ($ik_inv_st) { case 'new': $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_NEW]); break; case 'waitAccept': $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_PENDING]); break; case 'process': $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_PROCESS]); break; case 'success': $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_SUCCESS]); break; case 'canceled': $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_CANCELED]); break; case 'fail': $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_FAIL]) break; } } protected function loadModel($id) { $model = Invoice::findOne($id); if ($model === null) throw new BadRequestHttpException; return $model; } }
示例提现
class Withdraw { protected $purse_name = 'My Purse Name'; public function process($id) { $withdraw = Withdraw::findOne($id); if ($withdraw === null) throw new BadRequestHttpException; try { $result = Yii::$app->interkassa->withdraw( $withdraw->id, $this->purse_name, $withdraw->payway_name, ['purse' => $withdraw->purse], $withdraw->amount, 'psPayeeAmount', 'process' ); } catch (WithdrawException $e) { return $e->getMessage(); } } }