選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

116 行
2.9KB

  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 BackendController
  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. }