You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.6KB

  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 c006\paypal_ipn\PayPal_Ipn;
  11. /**
  12. * ProduitController implements the CRUD actions for Produit model.
  13. */
  14. class PaiementController extends Controller
  15. {
  16. var $enableCsrfValidation = false ;
  17. public function behaviors()
  18. {
  19. return [
  20. 'verbs' => [
  21. 'class' => VerbFilter::className(),
  22. 'actions' => [
  23. ],
  24. ],
  25. 'access' => [
  26. 'class' => AccessControl::className(),
  27. 'rules' => [
  28. [
  29. 'actions' => ['ipn'],
  30. 'allow' => true,
  31. 'roles' => ['?'],
  32. ],
  33. [
  34. 'allow' => true,
  35. 'roles' => ['@'],
  36. 'matchCallback' => function ($rule, $action) {
  37. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  38. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  39. }
  40. ]
  41. ],
  42. ],
  43. ];
  44. }
  45. /**
  46. * Lists all Produit models.
  47. * @return mixed
  48. */
  49. public function actionIndex()
  50. {
  51. return $this->render('index', [
  52. ]);
  53. }
  54. public function actionAnnuler()
  55. {
  56. return $this->render('annuler', [
  57. ]);
  58. }
  59. public function actionSucces()
  60. {
  61. return $this->render('succes', [
  62. ]);
  63. }
  64. public function beforeAction($action)
  65. {
  66. if(Yii::$app->controller->action->id=="ipn")
  67. $this->enableCsrfValidation = false;
  68. return parent::beforeAction($action);
  69. }
  70. public function actionIpn()
  71. {
  72. if (isset($_POST)) {
  73. $ipn = new PayPal_Ipn(false);
  74. if ($ipn->init())
  75. {
  76. /* Get any key/value */
  77. $custom = $ipn->getKeyValue('custom');
  78. /*
  79. Add your code here
  80. */
  81. $message = '' ;
  82. foreach($_POST as $key => $val) {
  83. $message .= $key.' : '.$val."\n" ;
  84. }
  85. mail('guillaume.bourgeois13@laposte.net','Données IPN', $message) ;
  86. }
  87. }
  88. /* Enable again if you use it */
  89. Yii::$app->request->enableCsrfValidation = true;
  90. }
  91. }