Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.02 KB | None | 0 0
  1.     public function ConfirmPaypalAction()
  2.     {
  3.         $this->layout('layout/layout_default.phtml');
  4.         $config = $this->getServiceLocator()->get('Config');
  5.         $paypal_config = $config['paypal'];
  6.  
  7.         $endpoint = $paypal_config['real_endpoint'];
  8.  
  9.         $username = $paypal_config['username'];
  10.         $password = $paypal_config['password'];
  11.         $signature = $paypal_config['signature'];
  12.         $curency = $paypal_config['curency'];
  13.  
  14.         $token = $this->getRequest()->getQuery('token');
  15.         $payerId = $this->getRequest()->getQuery('PayerID');
  16.         echo $token . " " . $payerId . $_SESSION['check'] . $_SESSION["Payment_Amount"];
  17.  
  18.         $qb = $this->ORM->createQueryBuilder();
  19.         $qb->select('u')
  20.             ->from('\Application\Entity\Payments', 'u')
  21.             ->where($qb->expr()->andX(
  22.                 $qb->expr()->like('u.payment_channel', "'paypal'"),
  23.                 $qb->expr()->like('u.token_transact', "'" . $token . "'")
  24.             ));
  25.         $query = $qb->getQuery();
  26.         $payment = $query->getResult();
  27.  
  28.         $payment = array_pop($payment);
  29.         print_r($payment);
  30.  
  31.         $id = $payment->getId();
  32.  
  33.         $qb->update('\Application\Entity\Payments', 'u')
  34.             ->set('u.status', '?1')
  35.             ->where("u.id = ?2 And u.status not Like 'paid'")->setParameter(1, 'conformation')->setParameter(2, $id);
  36.         $query = $qb->getQuery();
  37.         $updateResut = $query->execute();
  38.  
  39.         $serverName = $_SERVER['SERVER_NAME'];
  40.  
  41.         $requestCall = new Client();
  42.         $requestCall->setMethod(Request::METHOD_POST);
  43.         $requestCall->setUri('https://api-3t.paypal.com/nvp');
  44.         $requestCall->setOptions(array(
  45.             'timeout' => 60,
  46.         ));
  47.         $requestCall->setParameterPost(array(
  48.             'METHOD' => urlencode('DoExpressCheckoutPayment'),
  49.             'TOKEN' => urlencode($token),
  50.             'PAYERID' => urlencode($payerId),
  51.             'PAYMENTREQUEST_0_AMT' => urlencode($payment->getSum()),
  52.             'PAYMENTREQUEST_0_ITEMAMT' => urlencode($payment->getSum()),
  53.             'PAYMENTREQUEST_0_CURRENCYCODE' => urlencode($payment->getCurrency()),
  54.             'REQCONFIRMSHIPPING' => urlencode('0'),
  55.             'NOSHIPPING' => urlencode('1'),
  56.             'PAYMENTREQUEST_n_ITEMAMT' => urlencode('1'),
  57.             'PAYMENTREQUEST_n_PAYMENTACTION' => urlencode('Sale'),
  58.             'L_BILLINGTYPEn' => urlencode('RecurringPayments'),
  59.             'VERSION' => urlencode('64'),
  60.             'IPADDRESS' => urlencode($serverName),
  61.             'PWD' => urlencode($password),
  62.             'USER' => urlencode($username),
  63.             'SIGNATURE' => urlencode($signature),
  64.         ));
  65.  
  66.         $result = $requestCall->send();
  67.         $ack = strtoupper($this->GetValue($result->getContent(), "ACK"));
  68.         echo "CHECK_ACK:" . $ack;
  69.         echo urldecode($result->getContent());
  70.  
  71.         if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
  72.             $currencyEx = $this->ORM->getRepository('Application\Entity\Currencies')->findBy(array(
  73.                 'code' => $payment->getCurrency(),
  74.             ));
  75.  
  76.             $currencyEx = array_pop($currencyEx);
  77.             print_r($currencyEx);
  78.  
  79.             if ($currencyEx == null) {
  80.                 echo "CURENCY NOT FOUND";
  81.                 $qb->update('\Application\Entity\Payments', 'u')
  82.                     ->set('u.status', '?1')
  83.                     ->where('u.id = ?2')->setParameter(1, 'paid')->setParameter(2, $id);
  84.                 $query = $qb->getQuery();
  85.                 $updateResut = $query->execute();
  86.             } else {
  87.                 $sumPaid = $payment->getSum() / $currencyEx->getNominal() * $currencyEx->getExchangeUsd();
  88.                 $qb->update('\Application\Entity\Payments', 'u')
  89.                     ->set('u.status', '?1')
  90.                     ->set('u.sum', '?2')
  91.                     ->set('u.is_converted_to_tariffs_currency', '?3')
  92.                     ->set('u.USD', '?5')
  93.                     ->set('u.comment', '?6')
  94.                     ->where('u.id = ?4')
  95.                     ->setParameter(1, 'paid')
  96.                     ->setParameter(2, $payment->getSum())
  97.                     ->setParameter(3, true)
  98.                     ->setParameter(4, $id)
  99.                     ->setParameter(5, $sumPaid)
  100.                     ->setParameter(6, $result->getContent());
  101.                 $query = $qb->getQuery();
  102.                 $updateResut = $query->execute();
  103.                 echo "CURENCY FOUND: " . $updateResut;
  104.             }
  105.         $this->redirect()->toUrl('/payment/success');
  106.         }
  107.         else{
  108.             $retMsg = "Response=" . $result->getContent();
  109.             //$qb->update('\Application\Entity\Payments', 'u')
  110.             //        ->set('u.comment', '?1')
  111.             //        ->where('u.id = ?2')->setParameter(1, $retMsg)->setParameter(2, $id);
  112.             //    $query = $qb->getQuery();
  113.             //    $updateResut = $query->execute();
  114.             $payment->setComment($retMsg);
  115.             $this->ORM->persist($payment);
  116.             $this->ORM->flush();
  117.         }
  118.  
  119.         $this->redirect()->toUrl('/payment/success');
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement