public static function checkout_response($registrationid, $PayerID, $token)
 {
     //we will be using these two variables to execute the "DoExpressCheckoutPayment"
     //Note: we haven't received any payment yet.
     $token = $_GET["token"];
     $payer_id = $_GET["PayerID"];
     $PayPalMode = Config::get('billing.paypalmode');
     // sandbox or live
     $PayPalApiUsername = Config::get('billing.paypalapiusername');
     //PayPal API Username
     $PayPalApiPassword = Config::get('billing.paypalapipassword');
     //Paypal API password
     $PayPalApiSignature = Config::get('billing.paypalapisignature');
     //Paypal API Signature
     $totalitemstring = Session::get('totalitemstring');
     $GrandTotal = Session::get('grandtotal');
     if ($totalitemstring == NULL || $GrandTotal == NULL) {
         return Redirect::to('/billing')->with('message', 'Your session has timed out, your card has not been charged, please try again.');
     }
     $padata = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payer_id) . '&PAYMENTREQUEST_0_PAYMENTACTION=' . urlencode("SALE") . $totalitemstring . '&PAYMENTREQUEST_0_AMT=' . urlencode($GrandTotal) . '&PAYMENTREQUEST_0_CUSTOM=' . urlencode($registrationid);
     //We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
     $paypal = new PayPal();
     $httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
     // we can retrive transection details using either GetTransactionDetails or GetExpressCheckoutDetails
     // GetTransactionDetails requires a Transaction ID, and GetExpressCheckoutDetails requires Token returned by SetExpressCheckOut
     $paypal = new PayPal();
     if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
         $orderid = urldecode($httpParsedResponseAr['PAYMENTINFO_0_TRANSACTIONID']);
         $status = urldecode($httpParsedResponseAr['PAYMENTINFO_0_PAYMENTSTATUS']);
     } else {
         $orderid = 'N/A';
     }
     $padata = '&TOKEN=' . urlencode($token);
     $httpParsedResponseAr = $paypal->PPHttpPost('GetExpressCheckoutDetails', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
     $totalamount = urldecode($httpParsedResponseAr['AMT']);
     $registrationid = Auth::user()->registration->registrationid;
     $status = str_replace('PaymentAction', '', urldecode($httpParsedResponseAr['CHECKOUTSTATUS']));
     $order = new Bill();
     $order->registrationid = $registrationid;
     $order->method = "PayPal";
     $order->currency = 'USD';
     $order->description = 'PayPal Order Number: ' . $orderid;
     $order->amount = $totalamount;
     $order->checkout_id = $orderid;
     $order->status = ucwords($status);
     $order->save();
 }
Exemple #2
0
 public function sidebarAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $tags = $em->getRepository('BloggerBlogBundle:Blog')->getTags();
     $tagWeights = $em->getRepository('BloggerBlogBundle:Blog')->getTagWeights($tags);
     $commentLimit = $this->container->getParameter('blogger_blog.comments.latest_comment_limit');
     $latestComments = $em->getRepository('BloggerBlogBundle:Comment')->getLatestComments($commentLimit);
     // call paypal values.
     $paypal = new PayPal();
     $credentials = array('API_UserName' => $this->container->getParameter('API_UserName'), 'API_Password' => $this->container->getParameter('API_Password'), 'API_Signature' => $this->container->getParameter('API_Signature'), 'nvpStr' => $this->container->getParameter('nvpStr'));
     $list = $paypal->PPHttpPost($credentials);
     $count = count($list);
     $valuetag = 'L_AMT';
     $currencytag = 'L_CURRENCYCODE';
     /*
     Paypal answer API GetBalance
     GetBalance Completed Successfully: Array
     (
         [L_AMT0] => 0%2e00
         [L_AMT1] => 3%2e42
         [L_CURRENCYCODE0] => EUR
         [L_CURRENCYCODE1] => USD
         [TIMESTAMP] => 2015%2d07%2d06T08%3a33%3a54Z
         [CORRELATIONID] => eb155640cfe0
         [ACK] => Success
         [VERSION] => 51%2e0
         [BUILD] => 17103657
     )
     */
     $lists = [];
     for ($i = 0; $i < ($count - 5) / 2; $i++) {
         $lists += array($list[$currencytag . $i] => urldecode($list[$valuetag . $i]));
     }
     return $this->render('BloggerBlogBundle:Page:sidebar.html.twig', array('latestComments' => $latestComments, 'tags' => $tagWeights, 'Show_PayPal' => $this->container->getParameter('Show_PayPal'), 'lists' => $lists, 'locale' => $this->container->getParameter('locale')));
 }