|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use yii\filters\AccessControl;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use common\models\User;
- use common\models\Etablissement;
- use c006\paypal_ipn\PayPal_Ipn;
-
- /**
- * ProduitController implements the CRUD actions for Produit model.
- */
- class PaiementController extends BackendController {
-
- var $enableCsrfValidation = false;
-
- public function behaviors() {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => ['ipn'],
- 'allow' => true,
- 'roles' => ['?'],
- ],
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return Yii::$app->user->identity->status == USER::STATUS_ADMIN
- || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
- }
- ]
- ],
- ],
- ];
- }
-
- /**
- * Lists all Produit models.
- * @return mixed
- */
- public function actionIndex() {
-
- return $this->render('index', [
- ]);
- }
-
- public function actionAnnuler() {
-
- return $this->render('annuler', [
- ]);
- }
-
- public function actionSucces() {
- return $this->render('succes', [
- ]);
- }
-
- public function beforeAction($action) {
- if (Yii::$app->controller->action->id == "ipn")
- $this->enableCsrfValidation = false;
- return parent::beforeAction($action);
- }
-
- public function actionIpn() {
- if (isset($_POST)) {
- $ipn = new PayPal_Ipn(false);
- if ($ipn->init()) {
- $custom = $ipn->getKeyValue('custom');
- $txn_type = $ipn->getKeyValue('txn_type');
-
- if ($txn_type == 'subscr_payment' && $custom) {
- $user = User::findOne($custom);
- if ($user) {
- $etablissement = Etablissement::findOne($user->id_etablissement);
- if ($etablissement) {
- $etablissement->date_paiement = date('Y-m-d H:i:s', time());
- $etablissement->save();
- }
- }
- }
- }
- }
- /* Enable again if you use it */
- Yii::$app->request->enableCsrfValidation = true;
- }
-
- }
|