Beispiel #1
0
 public function devzone()
 {
     $user = User::find(Auth::user()->id);
     $data['developers'] = Developer::where('dev_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->get();
     return View::make('dev.developer')->with($data)->with('user', $user)->with('title', 'Paygray - Merchant|Developer');
 }
Beispiel #2
0
 public function payWithPaypal()
 {
     //purchase parameters
     $mmnumber = Input::get('number');
     $apikey = Input::get('apikey');
     $amounttosend = Input::get('amount');
     $currency = Input::get('currency');
     $item = Input::get('item_name');
     $cancel_url = Input::get('cancel_url');
     $confirm_url = Input::get('confirm_url');
     // $cno        = Input::get('cardnumber');
     $developers = Developer::where('dev_key', '=', $apikey)->where('dev_status', '=', 1)->limit(1)->get();
     if ($developers != null) {
         foreach ($developers as $developer) {
             $mmnumber = $developer->dev_email . ' | ' . $developer->dev_number . ' | ' . $developer->dev_username;
             $type = $developer->dev_paymentprovider;
             //   echo $mmnumber;
             //  echo '<BR/>'.$type;
         }
     } else {
         Redirect::away($cancel_url);
     }
     $charges = new PlatformCharges($amounttosend, $currency, $type);
     //        $desc    = $charges->getReceiverType($type);
     Session::set('destProvider', $type);
     Session::set('destination', $mmnumber);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     // Valid Values: ["credit_card", "bank", "paypal", "pay_upon_invoice", "carrier"]
     //TODO:: try to deduce the receiver type (email or number) and set the payerinfo data correctly for consistency
     $payerInfo = new PayerInfo();
     $payerInfo->setFirstName($mmnumber);
     //used to represent the receiver name/number/email
     $payerInfo->setLastName('Item: ');
     //used to pass the transaction type in the request
     $payer->setPayerInfo($payerInfo);
     $item_1 = new Item();
     $item_1->setName('Item purchase')->setDescription("Purchase made for {$item}")->setCurrency('USD')->setQuantity(1)->setPrice($charges->getDueAmount('pp', $type));
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal($charges->getDueAmount('pp', $type));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Payment for $item');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('api/merchantapi/paypalconfirm'))->setCancelUrl(URL::route('api/merchantapi/paypalcancel'));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
         foreach ($payment->getLinks() as $link) {
             if ($link->getRel() == 'approval_url') {
                 $redirect_url = $link->getHref();
                 break;
             }
         }
         //   var_dump($payment->getLinks());
         //   var_dump($redirect_url);
         // add payment ID to session
         Session::put('paypal_payment_id', $payment->getId());
         header('Location: ' . $redirect_url);
         exit;
         //            return isset($redirect_url)?Redirect::away($redirect_url): "Error!!Paypal Checkout error";
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             return Redirect::route($cancel_url)->with('alertError', 'Connection error. $err_data');
             exit;
         } else {
             return Redirect::route($cancel_url)->with('alertError', 'Connection error occured. Please try again later. ' . $ex->getMessage());
             //            die('Some error occurred, sorry for the inconvenience. Our team has been notified to correct this error.');
         }
     } catch (Exception $ex) {
         return Redirect::route($cancel_url)->with('alertError', 'Error! ' . $ex->getMessage());
     }
 }