Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PaiementController.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. var $enableCsrfValidation = false;
  17. public function behaviors() {
  18. return [
  19. 'verbs' => [
  20. 'class' => VerbFilter::className(),
  21. 'actions' => [
  22. ],
  23. ],
  24. 'access' => [
  25. 'class' => AccessControl::className(),
  26. 'rules' => [
  27. [
  28. 'actions' => ['ipn'],
  29. 'allow' => true,
  30. 'roles' => ['?'],
  31. ],
  32. [
  33. 'allow' => true,
  34. 'roles' => ['@'],
  35. 'matchCallback' => function ($rule, $action) {
  36. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  37. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  38. }
  39. ]
  40. ],
  41. ],
  42. ];
  43. }
  44. /**
  45. * Lists all Produit models.
  46. * @return mixed
  47. */
  48. public function actionIndex() {
  49. return $this->render('index', [
  50. ]);
  51. }
  52. public function actionAnnuler() {
  53. return $this->render('annuler', [
  54. ]);
  55. }
  56. public function actionSucces() {
  57. return $this->render('succes', [
  58. ]);
  59. }
  60. public function beforeAction($action) {
  61. if (Yii::$app->controller->action->id == "ipn")
  62. $this->enableCsrfValidation = false;
  63. return parent::beforeAction($action);
  64. }
  65. public function actionIpn() {
  66. if (isset($_POST)) {
  67. $ipn = new PayPal_Ipn(false);
  68. if ($ipn->init()) {
  69. $custom = $ipn->getKeyValue('custom');
  70. $txn_type = $ipn->getKeyValue('txn_type');
  71. if ($txn_type == 'subscr_payment' && $custom) {
  72. $user = User::findOne($custom);
  73. if ($user) {
  74. $etablissement = Etablissement::findOne($user->id_etablissement);
  75. if ($etablissement) {
  76. $etablissement->date_paiement = date('Y-m-d H:i:s', time());
  77. $etablissement->save();
  78. }
  79. }
  80. }
  81. }
  82. }
  83. /* Enable again if you use it */
  84. Yii::$app->request->enableCsrfValidation = true;
  85. }
  86. }