<commit_before><?php
// src/AppBundle/Controller/PaymentController.php

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Address;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payee;
use PayPal\Api\Payment;
use PayPal\Api\PaymentCard;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Capture;
use PayPal\Api\PaymentExecution;
use PayPal\Exception\PayPalConnectionException;
use AppBundle\Utils\CampaignHelper;
use AppBundle\Entity\Donation;
use AppBundle\Utils\DonationHelper;


use \DateTime;
use \DateTimeZone;

/**
 * Manage Campaign controller.
 *
 * @Route("/{campaignUrl}/donation")
 */
class DonationController extends Controller
{


  /**
   * @Route("/", name="donation_index")
   *
   * @Method({"GET", "POST"})
   */
  public function indexAction(Request $request, $campaignUrl)
  {
    $logger = $this->get('logger');

    $em = $this->getDoctrine()->getManager();

    $campaign = $em->getRepository('AppBundle:Campaign')->findOneByUrl($campaignUrl);

    /*
    * There are 4 types of donations:
    * team = Donation to a specific team
    * classroom = Donation to a specific classroom
    * campaign = Donation to the campaign (Defaulted if type is null)
    * student = Donation to a specific student
    *
    */
    $donation = array();
    if(null !== $request->query->get('type')){
      $donationType = $request->query->get('type');
      if($donationType == 'classroom' || $donationType == 'student'){
        if(null !== $request->query->get('classroomID')){
            $classroomID = $request->query->get('classroomID');
            $logger->debug("ClassroomID is found and set to ".$classroomID);
            //CODE TO CHECK TO SEE IF CLASSROOM EXISTS
            $classroom = $em->getRepository('AppBundle:Classroom')->findOneBy(array('id'=>$classroomID, 'campaign' => $campaign));
            if(!is_null($classroom)){
              $logger->debug("Using Classroom #".$classroom->getId()." in donation form.");
              $donation['classroom'] = $classroom;
            }
          }
      } elseif($donationType == 'team'){
          if(null !== $request->query->get('teamUrl')){
              $teamUrl = $request->query->get('teamUrl');
              $logger->debug("teamUrl is found and set to ".$teamUrl);
              //CODE TO CHECK TO SEE IF TEAM EXISTS
              $team = $em->getRepository('AppBundle:Team')->findOneBy(array('url'=>$teamUrl, 'campaign' => $campaign));
              if(!is_null($team)){
              $logger->debug("Using Team #".$team->getId()." in donation form.");
                $donation['team'] = $team;
              }
            }
    }
    }else{
      $donationType = 'campaign';
    }

    $logger->debug("Donation Object:", $donation);

    if ($request->isMethod('POST')) {
        $fail = false;
        $params = $request->request->all();

        if(!$fail && empty($params['donation']['amount'])){
          $this->addFlash('warning','Donation amount is required');
          $fail = true;
        }

        if(!$fail && empty($params['donation']['firstName'])){
          $this->addFlash('warning','Donor First name is required');
          $fail = true;
        }

        if(!$fail && empty($params['donation']['lastName'])){
          $this->addFlash('warning','DonorLast name is required');<commit_msg>pushing to prod<commit_after><?php
// src/AppBundle/Controller/PaymentController.php

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Address;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payee;
use PayPal\Api\Payment;
use PayPal\Api\PaymentCard;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Capture;
use PayPal\Api\PaymentExecution;
use PayPal\Exception\PayPalConnectionException;
use AppBundle\Utils\CampaignHelper;
use AppBundle\Entity\Donation;
use AppBundle\Utils\DonationHelper;


use \DateTime;
use \DateTimeZone;

/**
 * Manage Campaign controller.
 *
 * @Route("/{campaignUrl}/donation")
 */
class DonationController extends Controller
{


  /**
   * @Route("/", name="donation_index")
   *
   * @Method({"GET", "POST"})
   */
  public function indexAction(Request $request, $campaignUrl)
  {
    $logger = $this->get('logger');

    $em = $this->getDoctrine()->getManager();

    $campaign = $em->getRepository('AppBundle:Campaign')->findOneByUrl($campaignUrl);

    /*
    * There are 4 types of donations:
    * team = Donation to a specific team
    * classroom = Donation to a specific classroom
    * campaign = Donation to the campaign (Defaulted if type is null)
    * student = Donation to a specific student
    *
    */
    $donation = array();
    if(null !== $request->query->get('type')){
      $donationType = $request->query->get('type');
      if($donationType == 'classroom' || $donationType == 'student'){
        if(null !== $request->query->get('classroomID')){
            $classroomID = $request->query->get('classroomID');
            $logger->debug("ClassroomID is found and set to ".$classroomID);
            //CODE TO CHECK TO SEE IF CLASSROOM EXISTS
            $classroom = $em->getRepository('AppBundle:Classroom')->findOneBy(array('id'=>$classroomID, 'campaign' => $campaign));
            if(!is_null($classroom)){
              $logger->debug("Using Classroom #".$classroom->getId()." in donation form.");
              $donation['classroom'] = $classroom;
            }
          }
      } elseif($donationType == 'team'){
          if(null !== $request->query->get('teamUrl')){
              $teamUrl = $request->query->get('teamUrl');
              $logger->debug("teamUrl is found and set to ".$teamUrl);
              //CODE TO CHECK TO SEE IF TEAM EXISTS
              $team = $em->getRepository('AppBundle:Team')->findOneBy(array('url'=>$teamUrl, 'campaign' => $campaign));
              if(!is_null($team)){
              $logger->debug("Using Team #".$team->getId()." in donation form.");
                $donation['team'] = $team;
              }
            }
    }
    }else{
      $donationType = 'campaign';
    }

    $logger->debug("Donation Object:", print_r($donation, true));

    if ($request->isMethod('POST')) {
        $fail = false;
        $params = $request->request->all();

        if(!$fail && empty($params['donation']['amount'])){
          $this->addFlash('warning','Donation amount is required');
          $fail = true;
        }

        if(!$fail && empty($params['donation']['firstName'])){
          $this->addFlash('warning','Donor First name is required');
          $fail = true;
        }

        if(!$fail && empty($params['donation']['lastName'])){
          $this->addFlash('warning','DonorLast name is required');
{'fraction_non_alphanumeric': 0.16238396340643077, 'fraction_numerical': 0.0002690703618996368, 'mean_word_length': 3.1391982182628064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '363456', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2150, 'n_words': 446}