コード例 #1
0
 /**
  * @Route("/ipn", name="ipn")
  * @Template()
  */
 public function ipnAction(Request $request)
 {
     $paypalHandler = new PaypalIPNHandler();
     $message = "";
     if ($paypalHandler->validate()) {
         $postedData = $paypalHandler->getPostedData();
         $message .= print_r($postedData, true);
         $txnId = $postedData["txn_id"];
         $receiverEmail = $postedData["receiver_email"];
         $payerStatus = $postedData["payer_status"];
         $itemName = $postedData["item_name"];
         $itemNumber = $postedData["item_number"];
         $mcCurrency = $postedData["mc_currency"];
         $payerEmail = $postedData["payer_email"];
         $amount = $postedData["mc_gross"];
         $paymentStatus = $postedData["payment_status"];
         $dateTime = date("Y-m-d h:i:s a");
         $payment = $this->getDoctrine()->getRepository('BackendUserBundle:Payment')->findOneByTxnId($txnId);
         $users = $this->getDoctrine()->getRepository('BackendUserBundle:Users')->findOneByUserName($itemNumber);
         /*$em = $this->getDoctrine()->getManager();
           $repository = $em->getRepository("BackendUserBundle:Users");
           $users = $repository->findOneBy(array("userName" => $itemNumber )); */
         $message .= "Condition1 " . $receiverEmail . "==" . $paypalHandler->getBusinessEmail() . " <br />" . " Condition2 - " . $paymentStatus . "<br />" . "Condition3 - " . is_object($payment) . "<br/>" . "Condition4 -" . is_object($users);
         //echo "<pre/>"; print_r($payment); exit;
         if ($receiverEmail == $paypalHandler->getBusinessEmail() && $paymentStatus == "Completed" && !is_object($payment) && is_object($users)) {
             $payment = new Payment();
             $payment->setItemName($itemName)->setDate($dateTime)->setExtra(json_encode($postedData))->setItemNumber($itemNumber)->setMcCurrency($mcCurrency)->setPayerEmail($payerEmail)->setPayerStatus($payerStatus)->setMcGross($amount)->setReceiverEmail($receiverEmail)->setTxnId($txnId)->setUserId($users->getId())->setPaymentStatus($paymentStatus);
             $em = $this->getDoctrine()->getManager();
             $em->persist($payment);
             $em->flush();
             $paymentId = $payment->getId();
             $iTelSwitch = $this->get("iTelSwitch");
             if ($iTelSwitch) {
                 // It may be needed to convert currency
                 if ($iTelSwitch->recharge($users->getPinCode(), $amount, $txnId)) {
                     $phoneNumber = $itemNumber;
                     $topupHistory = new TopupHistory();
                     $topupHistory->setAmount($amount)->setPaymentId($paymentId)->setPhoneNumber($phoneNumber)->setUserId($users->getId())->setDate($dateTime);
                     $em = $this->getDoctrine()->getManager();
                     $em->persist($topupHistory);
                     $em->flush();
                     $message .= "Yes! Perfectly Done";
                 } else {
                     $message .= "Payment Done! But recharge not yet done";
                 }
             }
         } else {
             $message .= "Not Properly Verified";
         }
     }
     mail("*****@*****.**", "IPN Alert", $message);
     return array();
 }
コード例 #2
0
 /**
  * @Route("/card-payment",  name="cardPayment")
  * @Template()
  */
 public function cardPaymentAction(Request $request)
 {
     $session = $request->getSession();
     $userType = $session->get("userType", "");
     $userId = $session->get("id", 0);
     //$host = "http://" . $request->server->get("HTTP_HOST");
     $host = "http://munlink.com";
     if (trim($userType) == "") {
         return $this->redirect($this->generateUrl("userLogin"));
     }
     $myBalance = 0;
     $iTelSwitch = $this->get("iTelSwitch");
     if ($iTelSwitch) {
         $phoneNumber = $userName = $session->get("userName", "");
         if (trim($userName) != "") {
             $myBalance = $iTelSwitch->getBalance($userName);
         }
     }
     $em = $this->getDoctrine()->getManager();
     $repository = $em->getRepository("BackendUserBundle:Users");
     $userObj = $repository->findOneBy(array("id" => $userId));
     //Load Country
     $shortCountry = "";
     if (intval($userObj->getCountryId()) > 0) {
         $repository = $em->getRepository("BackendUserBundle:Country");
         $country = $repository->findOneBy(array("id" => $userObj->getCountryId()));
         $shortCountry = $country->getCountryShortName();
     }
     $currency = $userObj->getCurrency();
     $paypalHandler = new PaypalIPNHandler();
     $paypalHandler->add_field('business', $paypalHandler->getBusinessEmail());
     $paypalHandler->add_field('return', $host . '/munlink/web/mybalance');
     $paypalHandler->add_field('cancel_return', $host . '/munlink/web/mybalance');
     //$paypalHandler->add_field('notify_url',     $host.'/munlink/web/ipn');
     $paypalHandler->add_field('item_name', 'Top Up');
     $paypalHandler->add_field('amount', '5');
     $paypalHandler->add_field('quantity', '1');
     $paypalHandler->add_field('currency_code', $currency);
     $paypalHandler->add_field('item_number', $phoneNumber);
     $paypalHandler->add_field('address_override', '1');
     $paypalHandler->add_field('first_name', $userObj->getFirstName());
     $paypalHandler->add_field('last_name', $userObj->getLastName());
     $paypalHandler->add_field('address1', $userObj->getAddress1());
     $paypalHandler->add_field('city', $userObj->getCity());
     $paypalHandler->add_field('state', $userObj->getState());
     $paypalHandler->add_field('zip', $userObj->getZipCode());
     $paypalHandler->add_field('country', $shortCountry);
     $paypalFields = $paypalHandler->getFields();
     return $this->render('BackendUserBundle:Admin:topup.html.twig', array("myBalance" => $myBalance, 'paypalFields' => $paypalFields, 'paypalUrl' => $paypalHandler->getPaypalUrl(), 'currency' => $currency));
 }