<commit_before><?php

namespace App\Controller;

use App\Controller\AppController;
use Cake\Event\Event;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Routing\Router;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;

/**
 * Paypals Controller
 *
 * @property \App\Model\Table\PaypalsTable $Paypal
 */
class PaypalsController extends AppController {

    public function initialize() {
        parent::initialize();
        $this->Auth->allow(['notify']);
    }

    public function success() {
        //$this->Flash->success(__('The subsciption has been saved.'));
        //return $this->redirect(['action' => 'success']);
    }

    public function notify() {

        if ($this->request->is('post')) {
            Log::write(LOG_ERR, "Request is post");

            
            $data = $this->request->data();

            
            Log::write(LOG_ERR, "Data enoyée");
            Log::write(LOG_ERR, $data);


            $email_account = Configure::read('Paypal.email');


            $req = 'cmd=_notify-validate';
            foreach ($_POST as $key => $value) {
                $value = urlencode(stripslashes($value));
                $req .= "&$key=$value";
            }
            
            Log::write(LOG_ERR, "Données récupérées sur la variable post");
            Log::write(LOG_ERR, $req);


            $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
            $header .= "Host: www." . Configure::read('Paypal.sandbox') . "paypal.com\r\n";
            $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
            $fp = fsockopen('ssl://www.' . Configure::Read(Configure::read('Paypal.sandbox')) . 'paypal.com', 443, $errno, $errstr, 30);
            
            
            
            $item_name = $data['item_name'];
            $item_number = $data['item_number'];
            $payment_status = $data['payment_status'];
            $payment_amount = $data['mc_gross'];
            $payment_tax = $data['tax'];
            $payment_witout_tax = $payment_amount - $payment_tax;
            $payment_amount = $data['mc_gross'];
            $payment_currency = $data['mc_currency'];
            $txn_id = $data['txn_id'];
            $receiver_email = $data['receiver_email'];
            $payer_email = $data['payer_email'];
            parse_str($data['custom'], $custom);

            


            if (!$fp) {
            Log::write(LOG_ERR, "Socket non ouvert");    
            } else {
                Log::write(LOG_ERR, "Socket ouvert");
                fputs($fp, $header . $req);
                while (!feof($fp)) {
                    $res = fgets($fp, 1024);
                    //if (strcmp($res, "VERIFIED") == 0) {
                        Log::write(LOG_ERR, "Action a clarifier verified");
                        // vérifier que payment_status a la valeur Completed
                        if ($payment_status == "Completed") {
                            Log::write(LOG_ERR, "Paiement completed");
                            
                            if ($email_account == $receiver_email) {
                                Log::write(LOG_ERR, "Email correspondent");
                       
                                if ($custom['action'] == 'subscribe') {
                                    Log::write(LOG_ERR, "L'action est bien subscribe");
                                    $duration = $custom['duration'];
                                    $uid = $custom['uuid'];
                                    if ($payment_witout_tax == Configure::read("Site.prices.$duration")) {
                                        Log::write(LOG_ERR, "Le montant  correspond à un montant existant.");
                                        $transaction_data = [
                                            'transaction_name' => $txn_id,
                                            'price' => $payment_amount,
                                            'taxe' => "$payment_tax",
                                            'user_id' => "$uid",
                                        ];

                                        $transactions = TableRegistry::get('Transactions');
                                        $transaction = $transactions->newEntity($transaction_data);

                                        $this->User->id = $uid;
                                        $date = new DateTime();
                                        $date->add(new DateInterval("P" . $duration . "M"));
                                        $this->User->saveField('end_subcription', $date->format('Y-m-d H:i:s'));

                                        //Log::write(LOG_ERR, $this->request->data);

                                        if ($this->Users->save($user)) {
                                            $this->Flash->success(__('The user has been saved.'));
                                            return $this->redirect(['action' => 'index']);
                                        } else {
                                            $this->Flash->error(__('The user could not be saved. Please, try again.'));
                                        }
                                    }else{
                                        Log::write(LOG_ERR, "Le montant ne correspond pas un montant existant.");
                                    }
                                    
                                }else{
                                    Log::write(LOG_ERR, "L'action n'est pas subscribe");
                                }
                            }else{
                                Log::write(LOG_ERR, "Email ne correspondent pas");
                            }
                        } else {
                            // Statut de paiement: Echec
                            Log::write(LOG_ERR, "Paiement invalid");
                            
                        }
                        //exit();
                    //} else if (strcmp($res, "INVALID") == 0) {
                        // Transaction invalide
                        Log::write(LOG_ERR, "Action a clarifier INVALID");
                    //}
                }


                fclose($fp);
            }
        }
    }

}
<commit_msg>Correct some trouble.<commit_after><?php

namespace App\Controller;

use App\Controller\AppController;
use Cake\Event\Event;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Routing\Router;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use Cake\I18n\Time;

/**
 * Paypals Controller
 *
 * @property \App\Model\Table\PaypalsTable $Paypal
 */
class PaypalsController extends AppController {

    public function initialize() {
        parent::initialize();
        $this->Auth->allow(['notify']);
    }

    public function success() {
        //$this->Flash->success(__('The subsciption has been saved.'));
        //return $this->redirect(['action' => 'success']);
    }

    public function notify() {

        if ($this->request->is('post')) {
            Log::write(LOG_ERR, "Request is post");

            
            $data = $this->request->data();

            
            Log::write(LOG_ERR, "Data enoyée");
            Log::write(LOG_ERR, $data);


            $email_account = Configure::read('Paypal.email');


            $req = 'cmd=_notify-validate';
            foreach ($_POST as $key => $value) {
                $value = urlencode(stripslashes($value));
                $req .= "&$key=$value";
            }
            
            Log::write(LOG_ERR, "Données récupérées sur la variable post");
            Log::write(LOG_ERR, $req);


            $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
            $header .= "Host: www." . Configure::read('Paypal.sandbox') . "paypal.com\r\n";
            $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
            $fp = fsockopen('ssl://www.' . Configure::Read(Configure::read('Paypal.sandbox')) . 'paypal.com', 443, $errno, $errstr, 30);
            
            
            
            $item_name = $data['item_name'];
            $item_number = $data['item_number'];
            $payment_status = $data['payment_status'];
            $payment_amount = $data['mc_gross'];
            $payment_tax = $data['tax'];
            $payment_witout_tax = $payment_amount - $payment_tax;
            $payment_amount = $data['mc_gross'];
            $payment_currency = $data['mc_currency'];
            $txn_id = $data['txn_id'];
            $receiver_email = $data['receiver_email'];
            $payer_email = $data['payer_email'];
            parse_str($data['custom'], $custom);

            


            if (!$fp) {
            Log::write(LOG_ERR, "Socket non ouvert");    
            } else {
                Log::write(LOG_ERR, "Socket ouvert");
                fputs($fp, $header . $req);
                while (!feof($fp)) {
                    $res = fgets($fp, 1024);
                    //if (strcmp($res, "VERIFIED") == 0) {
                        Log::write(LOG_ERR, "Action a clarifier verified");
                        // vérifier que payment_status a la valeur Completed
                        if ($payment_status == "Completed") {
                            Log::write(LOG_ERR, "Paiement completed");
                            
                            if ($email_account == $receiver_email) {
                                Log::write(LOG_ERR, "Email correspondent");
                       
                                if ($custom['action'] == 'subscribe') {
                                    Log::write(LOG_ERR, "L'action est bien subscribe");
                                    $duration = $custom['duration'];
                                    $uid = $custom['uuid'];
                                    if ($payment_witout_tax == Configure::read("Site.prices.$duration")) {
                                        Log::write(LOG_ERR, "Le montant  correspond à un montant existant.");
                                        $transaction_data = [
                                            'transaction_name' => $txn_id,
                                            'price' => $payment_amount,
                                            'taxe' => "$payment_tax",
                                            'user_id' => "$uid",
                                        ];

                                        $transactions = TableRegistry::get('Transactions');
                                        $transaction = $transactions->newEntity($transaction_data);

                                        $this->User->id = $uid;
                                        //Log::write(LOG_ERR, "UUID de l'utilisateur ".$this->User->id);
                                        $date = new Date();
                                        $date->add(new DateInterval("P" . $duration . "M"));
                                        $this->User->saveField('end_subcription', $date->format('Y-m-d H:i:s'));

                                        //Log::write(LOG_ERR, $this->request->data);

                                        if ($this->Users->save($user)) {
                                            $this->Flash->success(__('The user has been saved.'));
                                            return $this->redirect(['action' => 'index']);
                                        } else {
                                            $this->Flash->error(__('The user could not be saved. Please, try again.'));
                                        }
                                    }else{
                                        Log::write(LOG_ERR, "Le montant ne correspond pas un montant existant.");
                                    }
                                    
                                }else{
                                    Log::write(LOG_ERR, "L'action n'est pas subscribe");
                                }
                            }else{
                                Log::write(LOG_ERR, "Email ne correspondent pas");
                            }
                        } else {
                            // Statut de paiement: Echec
                            Log::write(LOG_ERR, "Paiement invalid");
                            
                        }
                        //exit();
                    //} else if (strcmp($res, "INVALID") == 0) {
                        // Transaction invalide
                        Log::write(LOG_ERR, "Action a clarifier INVALID");
                    //}
                }


                fclose($fp);
            }
        }
    }

}

{'fraction_non_alphanumeric': 0.13043478260869565, 'fraction_numerical': 0.0021856217313246428, 'mean_word_length': 1.0934640522875816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 81, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2998902', 'n_tokens_mistral': 3152, 'n_tokens_neox': 2997, 'n_words': 587}