|
- <?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;
- }
- }
|