Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

PaiementController.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\filters\AccessControl;
  5. use yii\data\ActiveDataProvider;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. use common\models\User;
  10. use common\models\Etablissement;
  11. use c006\paypal_ipn\PayPal_Ipn;
  12. /**
  13. * ProduitController implements the CRUD actions for Produit model.
  14. */
  15. class PaiementController extends Controller
  16. {
  17. var $enableCsrfValidation = false ;
  18. public function behaviors()
  19. {
  20. return [
  21. 'verbs' => [
  22. 'class' => VerbFilter::className(),
  23. 'actions' => [
  24. ],
  25. ],
  26. 'access' => [
  27. 'class' => AccessControl::className(),
  28. 'rules' => [
  29. [
  30. 'actions' => ['ipn'],
  31. 'allow' => true,
  32. 'roles' => ['?'],
  33. ],
  34. [
  35. 'allow' => true,
  36. 'roles' => ['@'],
  37. 'matchCallback' => function ($rule, $action) {
  38. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  39. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  40. }
  41. ]
  42. ],
  43. ],
  44. ];
  45. }
  46. /**
  47. * Lists all Produit models.
  48. * @return mixed
  49. */
  50. public function actionIndex()
  51. {
  52. return $this->render('index', [
  53. ]);
  54. }
  55. public function actionAnnuler()
  56. {
  57. return $this->render('annuler', [
  58. ]);
  59. }
  60. public function actionSucces()
  61. {
  62. return $this->render('succes', [
  63. ]);
  64. }
  65. public function beforeAction($action)
  66. {
  67. if(Yii::$app->controller->action->id=="ipn")
  68. $this->enableCsrfValidation = false;
  69. return parent::beforeAction($action);
  70. }
  71. public function actionIpn()
  72. {
  73. if (isset($_POST)) {
  74. $ipn = new PayPal_Ipn(false);
  75. if ($ipn->init())
  76. {
  77. $custom = $ipn->getKeyValue('custom');
  78. $txn_type = $ipn->getKeyValue('txn_type');
  79. if($txn_type == 'subscr_payment' && $custom)
  80. {
  81. $user = User::findOne($custom) ;
  82. if($user)
  83. {
  84. $etablissement = Etablissement::findOne($user->id_etablissement) ;
  85. if($etablissement)
  86. {
  87. $etablissement->date_paiement = date('Y-m-d H:i:s',time()) ;
  88. $etablissement->save() ;
  89. }
  90. }
  91. }
  92. }
  93. }
  94. /* Enable again if you use it */
  95. Yii::$app->request->enableCsrfValidation = true;
  96. }
  97. }