Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function ConfirmPaypalAction()
- {
- $this->layout('layout/layout_default.phtml');
- $config = $this->getServiceLocator()->get('Config');
- $paypal_config = $config['paypal'];
- $endpoint = $paypal_config['real_endpoint'];
- $username = $paypal_config['username'];
- $password = $paypal_config['password'];
- $signature = $paypal_config['signature'];
- $curency = $paypal_config['curency'];
- $token = $this->getRequest()->getQuery('token');
- $payerId = $this->getRequest()->getQuery('PayerID');
- echo $token . " " . $payerId . $_SESSION['check'] . $_SESSION["Payment_Amount"];
- $qb = $this->ORM->createQueryBuilder();
- $qb->select('u')
- ->from('\Application\Entity\Payments', 'u')
- ->where($qb->expr()->andX(
- $qb->expr()->like('u.payment_channel', "'paypal'"),
- $qb->expr()->like('u.token_transact', "'" . $token . "'")
- ));
- $query = $qb->getQuery();
- $payment = $query->getResult();
- $payment = array_pop($payment);
- print_r($payment);
- $id = $payment->getId();
- $qb->update('\Application\Entity\Payments', 'u')
- ->set('u.status', '?1')
- ->where("u.id = ?2 And u.status not Like 'paid'")->setParameter(1, 'conformation')->setParameter(2, $id);
- $query = $qb->getQuery();
- $updateResut = $query->execute();
- $serverName = $_SERVER['SERVER_NAME'];
- $requestCall = new Client();
- $requestCall->setMethod(Request::METHOD_POST);
- $requestCall->setUri('https://api-3t.paypal.com/nvp');
- $requestCall->setOptions(array(
- 'timeout' => 60,
- ));
- $requestCall->setParameterPost(array(
- 'METHOD' => urlencode('DoExpressCheckoutPayment'),
- 'TOKEN' => urlencode($token),
- 'PAYERID' => urlencode($payerId),
- 'PAYMENTREQUEST_0_AMT' => urlencode($payment->getSum()),
- 'PAYMENTREQUEST_0_ITEMAMT' => urlencode($payment->getSum()),
- 'PAYMENTREQUEST_0_CURRENCYCODE' => urlencode($payment->getCurrency()),
- 'REQCONFIRMSHIPPING' => urlencode('0'),
- 'NOSHIPPING' => urlencode('1'),
- 'PAYMENTREQUEST_n_ITEMAMT' => urlencode('1'),
- 'PAYMENTREQUEST_n_PAYMENTACTION' => urlencode('Sale'),
- 'L_BILLINGTYPEn' => urlencode('RecurringPayments'),
- 'VERSION' => urlencode('64'),
- 'IPADDRESS' => urlencode($serverName),
- 'PWD' => urlencode($password),
- 'USER' => urlencode($username),
- 'SIGNATURE' => urlencode($signature),
- ));
- $result = $requestCall->send();
- $ack = strtoupper($this->GetValue($result->getContent(), "ACK"));
- echo "CHECK_ACK:" . $ack;
- echo urldecode($result->getContent());
- if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
- $currencyEx = $this->ORM->getRepository('Application\Entity\Currencies')->findBy(array(
- 'code' => $payment->getCurrency(),
- ));
- $currencyEx = array_pop($currencyEx);
- print_r($currencyEx);
- if ($currencyEx == null) {
- echo "CURENCY NOT FOUND";
- $qb->update('\Application\Entity\Payments', 'u')
- ->set('u.status', '?1')
- ->where('u.id = ?2')->setParameter(1, 'paid')->setParameter(2, $id);
- $query = $qb->getQuery();
- $updateResut = $query->execute();
- } else {
- $sumPaid = $payment->getSum() / $currencyEx->getNominal() * $currencyEx->getExchangeUsd();
- $qb->update('\Application\Entity\Payments', 'u')
- ->set('u.status', '?1')
- ->set('u.sum', '?2')
- ->set('u.is_converted_to_tariffs_currency', '?3')
- ->set('u.USD', '?5')
- ->set('u.comment', '?6')
- ->where('u.id = ?4')
- ->setParameter(1, 'paid')
- ->setParameter(2, $payment->getSum())
- ->setParameter(3, true)
- ->setParameter(4, $id)
- ->setParameter(5, $sumPaid)
- ->setParameter(6, $result->getContent());
- $query = $qb->getQuery();
- $updateResut = $query->execute();
- echo "CURENCY FOUND: " . $updateResut;
- }
- $this->redirect()->toUrl('/payment/success');
- }
- else{
- $retMsg = "Response=" . $result->getContent();
- //$qb->update('\Application\Entity\Payments', 'u')
- // ->set('u.comment', '?1')
- // ->where('u.id = ?2')->setParameter(1, $retMsg)->setParameter(2, $id);
- // $query = $qb->getQuery();
- // $updateResut = $query->execute();
- $payment->setComment($retMsg);
- $this->ORM->persist($payment);
- $this->ORM->flush();
- }
- $this->redirect()->toUrl('/payment/success');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement