public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Item 1')->setCurrency('USD')->setQuantity(2)->setPrice('150');
     // unit price
     $item_2 = new Item();
     $item_2->setName('Item 2')->setCurrency('USD')->setQuantity(4)->setPrice('70');
     $item_3 = new Item();
     $item_3->setName('Item 3')->setCurrency('USD')->setQuantity(1)->setPrice('20');
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1, $item_2, $item_3));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal(580);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
         //            echo'hello';
         //            print_r($test);die;
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     if (is_array($payment->getLinks()) || is_object($payment->getLinks())) {
         foreach ($payment->getLinks() as $link) {
             echo 'reached';
             if ($link->getRel() == 'approval_url') {
                 $redirect_url = $link->getHref();
                 break;
             }
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     dd(Session::all());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
 public function postPayment($producto_id)
 {
     $producto = Producto::find($producto_id);
     if (is_null($producto)) {
         App::abort(404);
     }
     $productoYaComprado = User::find(Auth::user()->id)->Productos()->whereProducto_id($producto->id)->first();
     if (!is_null($productoYaComprado)) {
         App::abort(404);
     }
     \Session::put('producto_id', $producto_id);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $currency = 'MXN';
     $item = new Item();
     $item->setName($producto->nombre)->setCurrency($currency)->setDescription($producto->nombre)->setQuantity(1)->setPrice($producto->precio);
     $items[] = $item;
     $subtotal += $producto->precio;
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal);
     //->setShipping(100);
     //$total = $subtotal + 100;
     $total = $subtotal;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             return \Redirect::route('home')->with('message', 'Algo salió mal, inténtalo de nuevo más tarde.');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('home')->with('message', 'Ups! Error desconocido. Inténtalo de nuevo más tarde.');
 }
Example #3
0
 public function postPayment()
 {
     $data = array();
     if (is_array(Input::get('room_id'))) {
         foreach (Input::get('room_id') as $key => $val) {
             $data[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
         }
     }
     $data2 = array();
     if (is_array(Input::get('add_Am'))) {
         foreach (Input::get('add_Am') as $key => $val) {
             $data2[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
         }
     }
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $name = Input::get('packname');
     $price = Input::get('amount');
     $input_dFrom = Input::get('package_datefrom');
     $input_dTo = Input::get('package_dateto');
     $input_nPax = Input::get('num_pax');
     $input_fName = Input::get('fullN');
     $postData = new Reservation();
     $postData->dataInsertPost($name, $price, $input_dFrom, $input_dTo, $input_nPax, $input_fName, json_encode($data), 'PayPal', json_encode($data2));
     $item_1 = new Item();
     $item_1->setName($name)->setCurrency('PHP')->setQuantity('1')->setPrice(intval($price));
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('PHP')->setTotal(intval($price));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     //        $redirect_urls->setReturnUrl(URL::to('/dashboard/accommodation'))
     //            ->setCancelUrl(URL::to('/dashboard/accommodation'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $e) {
         echo $e->getData();
         // This will print a JSON which has specific details about the error.
         exit;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         return json_encode(['url' => $redirect_url]);
     }
     return Redirect::route('dashboard.packages.accommodation')->with('error', 'Unknown error occurred');
 }
Example #4
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //        $item_1 = new Item();
     //        $item_1->setName('Item 1') // item name
     //            ->setCurrency('PHP')
     //            ->setQuantity('1')
     //            ->setPrice('0.01'); // unit price
     $package1 = Input::get('packname');
     $amount1 = Input::get('amount');
     $item_1 = new Item();
     $item_1->setName($package1)->setCurrency('PHP')->setQuantity('1')->setPrice($amount1);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('PHP')->setTotal($package1);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     //        try {
     //            $payment->create($this->_api_context);
     //        } catch (\PayPal\Exception\PPConnectionException $ex) {
     //
     //            if (\Config::get('app.debug')) {
     //                echo "Exception: " . $ex->getMessage() . PHP_EOL;
     //                $err_data = json_decode($ex->getData(), true);
     //                exit;
     //            } else {
     //                die('Some error occur, sorry for inconvenient');
     //            }
     //        }
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $e) {
         echo $e->getData();
         // This will print a JSON which has specific details about the error.
         exit;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = [];
     $num = 1;
     $total = 0;
     foreach (Auth::user()->cart as $item) {
         ${"item_" . $num} = new Item();
         ${"item_" . $num}->setName($item->product->name)->setCurrency('USD')->setQuantity($item->amount)->setPrice($item->product->price);
         $items[] = ${"item_" . $num};
         $num++;
         $total += $item->product->price * $item->amount;
     }
     if (Session::has('coupon')) {
         $discount = $total * Session::get('coupon.discount') / 100;
         $total = $total - $discount;
         ${"item_" . $num} = new Item();
         ${"item_" . $num}->setName('discount')->setCurrency('USD')->setQuantity(1)->setPrice(-$discount);
         $items[] = ${"item_" . $num};
     }
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($items);
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription(Auth::user()->email);
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(route('payment.status'))->setCancelUrl(route('home'));
     // ->setCancelUrl(route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect('/')->with('error', 'Unknown error occurred');
 }
Example #6
0
 public function pay()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //agregar items de base de datos
     $items = array();
     $subtotal = 0;
     $productos = DB::table('carrito')->Join('producto', 'carrito.ItemCode', '=', 'producto.ItemCode')->where('carrito.user_id', Auth::user()->id)->get();
     //dd(Auth::user()->id);
     $currency = 'MXN';
     foreach ($productos as $key => $p) {
         $pIva = $p->precio * 0.16;
         $precioIva = $p->precio + $pIva;
         $item = new Item();
         $item->setName($p->ItemName)->setCurrency($currency)->setDescription($p->tipo)->setQuantity($p->cantidad)->setPrice($precioIva);
         $items[$key] = $item;
         $subtotal += $p->cantidad * $precioIva;
     }
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(100);
     $total = $subtotal + 100;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             return Redirect::route('carrito.failed');
             exit;
         } else {
             return Redirect::route('carrito.failed');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('carrito.failed');
 }
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $cart = \Session::get('cart');
     $currency = 'MXN';
     foreach ($cart as $producto) {
         $item = new Item();
         $item->setName($producto->name)->setCurrency($currency)->setDescription($producto->extract)->setQuantity($producto->quantity)->setPrice($producto->price);
         $items[] = $item;
         $subtotal += $producto->quantity * $producto->price;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     //costo de envio de la compra
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(100);
     //total de envio sumando el subtotal mas el envio
     $total = $subtotal + 100;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba con laravel para La Central Mueblera');
     //la ruta  para direccionar si se cancela o se envia conrectamente el pedido
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! Algo salió mal');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('cart-show')->with('error', 'Ups! Error desconocido.');
 }
Example #8
0
 public function postPayment()
 {
     $name = 'Transaction';
     /*$mmnumber      = Input::get('number');
       $amounttosend     = Input::get('amount');
       $currency   = Input::get('currency');*/
     $mmnumber = Input::get('number');
     $amounttosend = Input::get('amount');
     $currency = Input::get('currency');
     $charges = new PlatformCharges($amounttosend, $currency);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Transaction')->setCurrency('USD')->setQuantity(1)->setPrice((int) $charges->getDueAmountForPayPalToMobileMoney());
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal((int) $charges->getDueAmountForPayPalToMobileMoney());
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Send money To a Mobile Money User');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment-status'))->setCancelUrl(URL::route('payment-status'));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occurred, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return "Error!!!!";
     /*Redirect::route('original.route')
       ->with('error', 'Unknown error occurred'); */
 }
Example #9
0
 public function postBuy(Request $request)
 {
     $data = $request->all();
     $customer = $this->customer->getByToken();
     $shopping_cart = $this->cart->getByToken();
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $paypal_items = [];
     $total = 0;
     foreach ($shopping_cart->shopping_cart_products as $shopping_cart_product) {
         $item = new Item();
         $item->setName($shopping_cart_product->product_collection_name . " // " . $shopping_cart_product->product_variant_name . " // " . $shopping_cart_product->product_color_name)->setCurrency(config('shop.default_currency'))->setQuantity($shopping_cart_product->quantity)->setPrice($shopping_cart_product->price_brut / 100);
         array_push($paypal_items, $item);
         $total += $shopping_cart_product->price_brut / 100 * $shopping_cart_product->quantity;
     }
     $subtotal = $total;
     $total += config('shop.default_shipping_cost') / 100;
     $item_list = new ItemList();
     $item_list->setItems($paypal_items);
     $details = new Details();
     $details->setShipping(config('shop.default_shipping_cost') / 100)->setSubtotal($subtotal);
     $amount = new Amount();
     $amount->setCurrency(config('shop.default_currency'))->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Einkauf bei ZWEI :: Taschen');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(url(config('app.locale') . '/paypal/thankyou'))->setCancelUrl(url(config('app.locale') . '/paypal/cancellation'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (config('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die(trans('shop.some_error_occurred'));
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     $this->cart->update(['id' => $shopping_cart->id, 'paypal_payment_id' => $payment->getId(), 'remarks' => $data['remarks'], 'customer_id' => $customer->id]);
     if (isset($redirect_url)) {
         return redirect($redirect_url);
     }
     return redirect()->route(config('app.locale') . '/feedback/paypal-error')->with('error', trans('shop.some_error_occurred'));
 }
 public function pay()
 {
     #dd(Input::all());
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $counter = 0;
     $items = [];
     foreach (Input::all() as $input) {
         if (Input::has('item_name' . $counter)) {
             $item = new Item();
             $item->setName(Input::get('item_name' . $counter))->setCurrency('EUR')->setQuantity(Input::get('item_qtt' . $counter))->setPrice(Input::get('item_price' . $counter));
             $items[] = $item;
         }
         $counter++;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $amount = new Amount();
     $amount->setCurrency('EUR')->setTotal(Input::get('total'));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('This is just a demo transaction');
     $redirect_url = new RedirectUrls();
     $redirect_url->setReturnUrl(URL::route('paymentStatus'))->setCancelUrl(URL::route('paymentStatus'));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirect_url)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Example #11
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $cart = \Session::get('cart');
     $currency = 'USD';
     foreach ($cart as $producto) {
         $item = new Item();
         $item->setName($producto->tipograno)->setCurrency($currency)->setDescription($producto->descripcion)->setQuantity($producto->cantidad)->setPrice($producto->precio);
         $items[] = $item;
         $subtotal += $producto->cantidad * $producto->precio;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $total = $subtotal;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba en Agricola Grain App');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! Algo salió mal');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('cart-show')->with('error', 'Ups! Error desconocido.');
 }
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $cart = \Session::get('product');
     $currency = 'USD';
     $item = new Item();
     $item->setName($cart->name)->setCurrency($currency)->setDescription($cart->description)->setQuantity(1)->setPrice($cart->price);
     $items[] = $item;
     $subtotal += $cart->price;
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(0);
     $total = $subtotal + 0;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Order plan in hdsports.in');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! something went wrong');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::to('/')->with('message', 'Ups! Unknown mistake.');
 }
Example #13
0
 public function postPayment()
 {
     // echo '123123';exit;
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $total = Input::get('total');
     $qty = Input::get('qty');
     $price = Input::get('price');
     $bill_id = Input::get('bill_id');
     $item_1 = new Item();
     $item_1->setName(Input::get('service_name'))->setCurrency('USD')->setQuantity($qty)->setPrice($price);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     Session::put('bill_id', $bill_id);
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Example #14
0
 /**
  * Cria o pagamento Paypal: passos 2/3
  *
  * @access	public
  * @param	
  * @return	error string
  */
 public function create_payment($items_array, $details_array)
 {
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // define os items
     $i = 0;
     foreach ($items_array as $item) {
         $items[$i] = new Item();
         $items[$i]->setName($item['name'])->setCurrency(PAYPAL_CURRENCY)->setQuantity($item['quantity'])->setPrice($item['price']);
         $i++;
     }
     $itemList = new ItemList();
     $itemList->setItems($items);
     // Define os totais
     $details = new Details();
     $details->setShipping($details_array['shipping'])->setTax($details_array['tax'])->setSubtotal($details_array['subtotal']);
     // Define a quantidade
     $amount = new Amount();
     $amount->setCurrency(PAYPAL_CURRENCY)->setTotal($details_array['total'])->setDetails($details);
     // cria a transação
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("");
     // cria o URL
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl(SITE_PATH . "success.php")->setCancelUrl(SITE_PATH . "cart.php");
     // cria o pagamento
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($this->api_context);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         return $ex->getMessage();
     }
     // busca o URL de redirecionamento
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirectUrl = $link->getHref();
             break;
         }
     }
     // redireciona
     $_SESSION['payment_id'] = $payment->getId();
     if (isset($redirectUrl)) {
         header("Location: {$redirectUrl}");
         exit;
     }
 }
 public function postPayment()
 {
     $input_amount = \Input::get('amount');
     $input_user_id = \Input::get('user_id');
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Υπηρεσίες freelancing')->setCurrency('EUR')->setQuantity(1)->setPrice($input_amount);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('EUR')->setTotal($input_amount);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Ειμαι η περιγραφή');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setId("2014031400023")->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     \Session::put('user_id', $input_user_id);
     \Session::put('amount', $input_amount);
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
 /**
  * @depends testSerializationDeserialization
  * @param Payment $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getId(), "TestSample");
     $this->assertEquals($obj->getIntent(), "TestSample");
     $this->assertEquals($obj->getPayer(), PayerTest::getObject());
     $this->assertEquals($obj->getPayee(), PayeeTest::getObject());
     $this->assertEquals($obj->getCart(), "TestSample");
     $this->assertEquals($obj->getTransactions(), TransactionTest::getObject());
     $this->assertEquals($obj->getFailedTransactions(), ErrorTest::getObject());
     $this->assertEquals($obj->getPaymentInstruction(), PaymentInstructionTest::getObject());
     $this->assertEquals($obj->getState(), "TestSample");
     $this->assertEquals($obj->getExperienceProfileId(), "TestSample");
     $this->assertEquals($obj->getRedirectUrls(), RedirectUrlsTest::getObject());
     $this->assertEquals($obj->getCreateTime(), "TestSample");
     $this->assertEquals($obj->getUpdateTime(), "TestSample");
     $this->assertEquals($obj->getLinks(), LinksTest::getObject());
 }
Example #17
0
 public function postPayment(Request $request)
 {
     foreach ($request->get('passengername') as $key => $name) {
         $passenger = Passenger::create(['reservation_id' => $request->reservation_id, 'cruise_id' => $request->cruise_id, 'name' => $name, 'identification' => $request->get('passengeridentification')[$key], 'nationality' => $request->get('passengernationality')[$key], 'contact_no' => $request->get('passengercontact')[$key], 'gender' => $request->get('passengergender')[$key]]);
     }
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName($request->cruise_name)->setCurrency('MYR')->setQuantity(1)->setPrice($request->total);
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('MYR')->setTotal($request->total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription($request->description);
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     Session::put('reservation_id', $request->reservation_id);
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Example #18
0
 /**
  * @depends testSerializationDeserialization
  * @param Payment $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getId(), "TestSample");
     $this->assertEquals($obj->getIntent(), "TestSample");
     $this->assertEquals($obj->getPayer(), PayerTest::getObject());
     $this->assertEquals($obj->getPotentialPayerInfo(), PotentialPayerInfoTest::getObject());
     $this->assertEquals($obj->getPayee(), PayeeTest::getObject());
     $this->assertEquals($obj->getCart(), "TestSample");
     $this->assertEquals($obj->getTransactions(), array(TransactionTest::getObject()));
     $this->assertEquals($obj->getFailedTransactions(), ErrorTest::getObject());
     $this->assertEquals($obj->getBillingAgreementTokens(), array("TestSample"));
     $this->assertEquals($obj->getCreditFinancingOffered(), CreditFinancingOfferedTest::getObject());
     $this->assertEquals($obj->getPaymentInstruction(), PaymentInstructionTest::getObject());
     $this->assertEquals($obj->getState(), "TestSample");
     $this->assertEquals($obj->getExperienceProfileId(), "TestSample");
     $this->assertEquals($obj->getNoteToPayer(), "TestSample");
     $this->assertEquals($obj->getRedirectUrls(), RedirectUrlsTest::getObject());
     $this->assertEquals($obj->getFailureReason(), "TestSample");
     $this->assertEquals($obj->getCreateTime(), "TestSample");
     $this->assertEquals($obj->getUpdateTime(), "TestSample");
     $this->assertEquals($obj->getLinks(), LinksTest::getObject());
 }
 public function checkout()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = [];
     $session = Session::get('cart.songs');
     $bundles = Session::get('cart.bundles');
     $total = 0;
     if (count($session) == 0 && count($bundles) == 0) {
         die('No Items in you cart');
     }
     $songs_string = "";
     $bundles_string = "";
     if (count($session) != 0) {
         foreach ($session as $s) {
             $song = Song::find($s['id']);
             $item = new Item();
             $item->setName($song->title)->setCurrency('AUD')->setQuantity(1)->setPrice($song->price);
             $items[] = $item;
             $total += $song->price;
             $songs_string .= "," . $song->id;
         }
     }
     if (count($bundles) != 0) {
         foreach ($bundles as $s) {
             $bundles = Bundle::find($s['id']);
             $item = new Item();
             $item->setName($bundles->name)->setCurrency('AUD')->setQuantity(1)->setPrice($bundles->price);
             $items[] = $item;
             $total += $bundles->price;
             $bundles_string .= "," . $bundles->id;
         }
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $amount = new Amount();
     $amount->setCurrency('AUD')->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Music Equity Song Purchase');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     $t = new MyTransaction();
     $t->amount = $total;
     if (Auth::check()) {
         $t->customer = Auth::user()->id;
     } else {
         $t->customer = '0';
     }
     $t->songs = $songs_string;
     $t->bundles = $bundles_string;
     $t->status = 'OPEN';
     $t->paypal_id = $payment->getId();
     $t->save();
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
 }
Example #20
0
 public function postPayment($type)
 {
     \Session::forget('pagos_id');
     $pagos_id = \Session::get('pagos_id');
     //\Session::put('pagos_id', $pagos_id);
     \Session::forget('pagos_data');
     $pagos_data = \Session::get('pagos_data');
     //\Session::put('pagos_data', $pagos_data);
     $user_id = $this->auth->user()->id;
     $month = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
     $cta = $this->auth->user()->type;
     $cuota = Cuotas::find($cta);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $currency = 'MXN';
     $price = $cuota->amount;
     $descuento = false;
     $discount = -$price;
     $qty = 1;
     $shipp = 0;
     $items_arr = array();
     $pago_hasta = 0;
     $lmt = 0;
     $m = 1;
     //mes de inicio 1-12
     $y = 2016;
     //año de inicio
     $d = date('d');
     $ultimo_p = DB::table('pagos')->where('id_user', $this->auth->user()->id)->where('status', 1)->orderBy('date', 'dsc')->get();
     foreach ($ultimo_p as $pay) {
         $pago_hasta = explode("-", $pay->date);
         $m = intval($pago_hasta[1]);
         $y = intval($pago_hasta[0]);
         $m++;
         if ($m == 13) {
             $m = 1;
             $y++;
         }
         break;
     }
     $prueba = '';
     // 1-mensual
     // 2-semestral
     // 3-anual
     // 4-saldo vencido
     if ($type == 1) {
         $lmt = 1;
     } else {
         if ($type == 2) {
             $lmt = 6;
         } else {
             if ($type == 3) {
                 $lmt = 12;
                 $descuento = true;
             } else {
                 if ($type == 4) {
                     $vencidos = DB::table('pagos')->where('id_user', $this->auth->user()->id)->where('status', 0)->orderBy('date', 'asc')->get();
                     $vence_date = explode("-", $vencidos[0]->date);
                     $m = intval($vence_date[1]);
                     $y = intval($vence_date[0]);
                     //[0]2014 [1]mes [2]dia
                     foreach ($vencidos as $vence) {
                         $pagos_id[] = $vence->id;
                         \Session::put('pagos_id', $pagos_id);
                         $lmt++;
                     }
                 }
             }
         }
     }
     //populate items array
     for ($i = 0; $i < $lmt; $i++) {
         $items_arr[$i] = $month[$m - 1] . " " . $y;
         //se llena con fechas -> yyyy-mm-dd
         if ($m < 10) {
             $pagos_data[$i] = $y . '-0' . $m . '-' . $d;
             \Session::put('pagos_data', $pagos_data);
         } else {
             $pagos_data[$i] = $y . '-' . $m . '-' . $d;
             \Session::put('pagos_data', $pagos_data);
         }
         $m++;
         if ($m == 13) {
             $m = 1;
             $y++;
         }
     }
     //crear los items
     foreach ($items_arr as $pago) {
         $item = new Item();
         $item->setName($pago)->setCurrency($currency)->setDescription('item description')->setQuantity($qty)->setPrice($price);
         $items[] = $item;
         $subtotal += $price * $qty;
     }
     //descuento
     if ($descuento) {
         $item = new Item();
         $item->setName('Descuento Pago Anual(1 mes)')->setCurrency($currency)->setDescription('item description')->setQuantity($qty)->setPrice($discount);
         $items[] = $item;
         $subtotal += $discount * $qty;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping($shipp);
     $total = $subtotal + $shipp;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba en mi Laravel App');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     /*		
     		try {
     			$payment->create($this->_api_context);
     		} catch (PayPal\Exception\PayPalConnectionException $ex) {
     		    //echo $ex->getCode(); // Prints the Error Code
     		    //echo $ex->getData(); // Prints the detailed error message 
     		    die($ex);
     		} catch (Exception $ex) {
     		    die($ex);
     		}
     */
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! Algo salió mal');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return redirect()->to('micuenta')->with('error', 'Ha ocurrido un error. Volver a intentar.');
 }
Example #21
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $_contentCart = Cart::instance('shopping')->content();
     $_itemsCount = Cart::instance('shopping')->count();
     $_arryItems = array();
     $_i = 0;
     foreach ($_contentCart as $row) {
         if ($_i < $_itemsCount) {
             $item = new Item();
             $item->setName($row->name)->setDescription($row->name)->setCurrency('AUD')->setQuantity((double) $row->qty)->setTax((double) ($row->price * 10) / 100)->setPrice((double) $row->price);
             //$435.00
             $_arryItems[$_i] = $item;
             $_i++;
         }
     }
     $item_list = new ItemList();
     $item_list->setItems(array($_arryItems));
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($_arryItems);
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $details = new Details();
     $details->setShipping("0")->setTax((string) (Cart::instance('shopping')->total() * 10) / 100)->setSubtotal((string) Cart::instance('shopping')->total());
     $amount = new Amount();
     $amount->setCurrency("AUD")->setTotal((string) Cart::instance('shopping')->total() + Cart::instance('shopping')->total() * 10 / 100)->setDetails($details);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('QLM Shopping Cart');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::to('/payment/status'))->setCancelUrl(URL::to('/payments/cancel'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         //$this->createInvoice();
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PayPalConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return View::make('pages.shoppingcart')->with('error', 'Unknown error occurred');
 }
Example #22
0
 public function postPayment()
 {
     $name = 'Transaction';
     $mmnumber = Input::get('number');
     $amounttosend = Input::get('amount');
     $currency = Input::get('currency');
     $type = Input::get('target');
     //destination/receipient's payment Provider
     $cno = Input::get('cardnumber');
     $charges = new PlatformCharges($amounttosend, $currency, $type);
     $desc = $charges->getReceiverType($type);
     Session::set('destProvider', $type);
     Session::set('destination', $mmnumber);
     if ($type == 'pp') {
         return Redirect::route('dashboard')->with('alertError', 'You need to select different payment provider for sender and receiver');
     }
     $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('Paypal to ' . $desc);
     //used to pass the transaction type in the request
     $payer->setPayerInfo($payerInfo);
     $item_1 = new Item();
     $item_1->setName('Money Transfer')->setDescription("Send money to a {$desc} User")->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('Send money To a Mobile Money User');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment-status'))->setCancelUrl(URL::route('payment-status'));
     $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;
             }
         }
         // add payment ID to session
         Session::put('paypal_payment_id', $payment->getId());
         if (isset($redirect_url)) {
             // redirect to paypal
             return Redirect::away($redirect_url);
         }
         return "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('dashboard')->with('alertError', 'Connection error. $err_data');
             exit;
         } else {
             return Redirect::route('dashboard')->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('dashboard')->with('alertError', 'Error! ' . $ex->getMessage());
     }
 }
Example #23
0
 /**
  * @brief epay.getPaymentForm 에서 호출됨
  */
 function dispPaypalForm()
 {
     $oEpayController = getController('epay');
     $oNcartModel = getModel('ncart');
     $oModuleModel = getModel('module');
     $oPaypalModuleConfig = $oModuleModel->getModuleConfig('paypal');
     $oPaypalModel = getModel('paypal');
     $paypalhome = sprintf(_XE_PATH_ . "files/epay/%s", $this->module_info->module_srl);
     $logged_info = Context::get('logged_info');
     if ($logged_info) {
         $oEpayModel = getModel('epay');
         $transaction_count = $oEpayModel->getTransactionCountByMemberSrl($logged_info->member_srl);
         if ($transaction_count < $oPaypalModuleConfig->minimum_transactions) {
             Context::set('error_code', '3');
             Context::set('minimum_transactions_count', $oPaypalModuleConfig->minimum_transactions);
             $this->setTemplateFile('error');
             return;
         }
     }
     // get products info using cartnos
     $output = $oEpayController->reviewOrder();
     if (!$output->toBool()) {
         return $output;
     }
     Context::set('review_form', $output->review_form);
     //$cart_info = $output->cart_info;
     $transaction_srl = $output->transaction_srl;
     $order_srl = $output->order_srl;
     //Context::set('cart_info', $cart_info);
     Context::set('price', $output->price);
     Context::set('transaction_srl', $transaction_srl);
     Context::set('order_srl', $order_srl);
     require __DIR__ . '/bootstrap.php';
     // Paypal account - 'paypal' / Credit card - 'credit_card'
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $item = new Item();
     $item_name = $output->item_name;
     $item->setName($item_name)->setCurrency($oPaypalModuleConfig->currency_code)->setQuantity(1)->setPrice($oPaypalModel->getConvertedPrice($output->price, $oPaypalModuleConfig->conversion_rate));
     $itemList = new ItemList();
     $itemList->setItems(array($item));
     /*
     		$details = new Details();
     		$details->setShipping(number_format($cart_info->delivery_fee, 2))
     				->setTax(number_format($cart_info->vat, 2))
     				->setSubtotal(number_format($cart_info->supply_amount, 2));
     */
     $amount = new Amount();
     $amount->setCurrency($oPaypalModuleConfig->currency_code)->setTotal($oPaypalModel->getConvertedPrice($output->price, $oPaypalModuleConfig->conversion_rate));
     //			   ->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description");
     $baseUrl = getBaseUrl();
     $redirectUrls = new RedirectUrls();
     $returnURL = getNotEncodedFullUrl('', 'module', $this->module_info->module, 'act', 'procPaypalExecutePayment', 'success', 'true', 'order_srl', $order_srl, 'transaction_srl', $transaction_srl);
     $cancelURL = getNotEncodedFullUrl('', 'module', $this->module_info->module, 'act', 'procPaypalExecutePayment', 'success', 'false', 'order_srl', $order_srl, 'transaction_srl', $transaction_srl);
     $redirectUrls->setReturnUrl($returnURL)->setCancelUrl($cancelURL);
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $output = $payment->create($apiContext);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         echo "Exception: " . $ex->getMessage() . PHP_EOL;
         var_dump($ex->getData());
         exit(1);
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirectUrl = $link->getHref();
             break;
         }
     }
     $_SESSION['paymentId'] = $payment->getId();
     Context::set('redirectUrl', $redirectUrl);
     Context::set('payment_method', $payment_method);
     $this->setTemplateFile('formdata');
 }
 public function postPayment()
 {
     $payer = new Payer();
     $i = [];
     $input = Input::all();
     $membership_discount = Session::has('reservation.customerdiscount') ? number_format(Session::get('reservation.customerdiscountprice'), 2) : 0;
     $coupon_discount = 0;
     $total_discount = 0;
     $i['checkin'] = Session::get('reservation')['checkin'];
     $i['checkout'] = Session::get('reservation')['checkout'];
     $i['total_nights'] = Session::get('reservation')['nights'];
     $total_price = 0;
     $tax_price = 0;
     $item = [];
     $payer->setPaymentMethod('paypal');
     foreach (Session::get('reservation')['reservation_room'] as $roomKey => $rooms) {
         $total_price += $rooms['room_details']['price'] * $i['total_nights'] * $rooms['quantity'];
         $room_id = $rooms['room_details']['id'];
         $available_rooms = [];
         $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) {
             $query->where(function ($query2) use($i, $room_id) {
                 $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out');
             })->where('status', '!=', 5);
         }))->where('room_id', $room_id)->get();
         foreach ($room_qty as $available) {
             if ($available->roomReserved == '[]') {
                 $item[$roomKey] = new Item();
                 $item[$roomKey]->setName($rooms['room_details']['name'])->setDescription("Room \"" . $rooms['room_details']['name'] . "\". P " . $rooms['room_details']['price'] . " per night (" . $i['total_nights'] . " nights)")->setCurrency('PHP')->setQuantity($rooms['quantity'])->setPrice($rooms['room_details']['price'] * $i['total_nights']);
             }
         }
     }
     if (isset($input['discountCode'])) {
         $discount = Discount::where('code', $input['discountCode'])->first();
         if ($discount) {
             if ($discount->used == null || $discount->used == '') {
                 $coupon_discount = $discount->calculateDiscount($total_price, $discount->effect, $discount->effect_type);
                 $discount->used = date('Y-m-d H:i:s');
                 $discount->save();
             }
         }
     }
     $total_discount = -$membership_discount - $coupon_discount;
     $total_price += $total_discount;
     Session::put('total_price', $total_price);
     if ($membership_discount != 0) {
         Session::put('hasMembershipDiscount', $membership_discount);
     }
     if ($coupon_discount != 0) {
         Session::put('hasCouponDiscount', $coupon_discount);
     }
     $discount1 = new Item();
     $discount1->setName('Discount')->setDescription("Reservation Discount")->setCurrency('PHP')->setQuantity(1)->setPrice($total_discount);
     array_push($item, $discount1);
     $item_list = new ItemList();
     $item_list->setItems($item);
     $tax_price = $total_price * 0.12;
     /*set tax*/
     $details = new Details();
     $details->setSubtotal($total_price);
     /*computing the amout*/
     $amount = new Amount();
     $amount->setCurrency('PHP')->setDetails($details)->setTotal($total_price);
     /*creation of transaction starts here*/
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Filigans Hotel Reservation');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             return $err_data;
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Example #25
0
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(200);
$fakeTotal = 200 + 1.2 + 1.3;
$amount = new Amount();
$amount->setCurrency("USD")->setTotal($fakeTotal)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://localhost:9090/member/executePayment.php?success=true')->setCancelUrl('http://localhost:9090/member/executePayment.php?success=false');
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
    $payment->create($api);
    echo 'payment';
} catch (Exception $ex) {
    echo 'error';
    // ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
    exit(1);
}
$approvalUrl = $payment->getApprovalLink();
foreach ($payment->getLinks() as $link) {
    # code...
    if ($link->getRel() == 'approval_url') {
        $redirectUrl = $link->getHref();
    }
}
header('Location: ' . $redirectUrl);
// ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
 /**
  * Gets link for account payment
  *
  * @access public
  * @param array $settings
  * @return null
  */
 public static function get_link(array $settings)
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $data = self::get_data($settings['payment_type'], $settings['object_id']);
     $item = new Item();
     $item->setName($data['title'])->setDescription($data['description'])->setCurrency($data['currency_code'])->setQuantity(1)->setPrice($data['price']);
     $item_list = new ItemList();
     $item_list->setItems(array($item));
     $details = new Details();
     $details->setSubtotal($data['price']);
     $amount = new Amount();
     $amount->setCurrency($data['currency_code'])->setTotal($data['price'])->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription($data['description'])->setInvoiceNumber(uniqid());
     $redirectUrls = new RedirectUrls();
     $url = self::get_paypal_process_url(get_current_user_id(), $settings['payment_type'], $settings['object_id']);
     $redirectUrls->setReturnUrl($url)->setCancelUrl(plugins_url() . '/realestate/includes/paypal-payment.php?success=false&payment_type=' . $settings['payment_type'] . '&object_id=' . $settings['object_id'] . '&user_id=' . get_current_user_id());
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $api_context = self::get_paypal_context();
         $payment->create($api_context);
     } catch (Exception $ex) {
         var_dump($ex);
         die;
         return null;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             wp_redirect($link->getHref());
             exit;
         }
     }
     return null;
 }
Example #27
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $_contentCart = Cart::instance('shopping')->content();
     $_itemsCount = Cart::instance('shopping')->count();
     $_arryItems = array();
     $_i = 0;
     foreach ($_contentCart as $row) {
         if ($_i < $_itemsCount) {
             $item = new Item();
             $item->setName($row->name)->setDescription($row->name)->setCurrency('USD')->setQuantity((double) $row->qty)->setTax((double) ($row->price * 10) / 100)->setPrice((double) $row->price);
             //$435.00
             $_arryItems[$_i] = $item;
             $_i++;
         }
     }
     $item_list = new ItemList();
     $item_list->setItems(array($_arryItems));
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($_arryItems);
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $details = new Details();
     $details->setShipping("0")->setTax((string) (Cart::instance('shopping')->total() * 10) / 100)->setSubtotal((string) Cart::instance('shopping')->total());
     $amount = new Amount();
     $amount->setCurrency("USD")->setTotal((string) Cart::instance('shopping')->total() + Cart::instance('shopping')->total() * 10 / 100)->setDetails($details);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         echo $ex->getCode();
         // Prints the Error Code
         echo $ex->getData();
         // Prints the detailed error message
         die($ex);
     } catch (Exception $ex) {
         die($ex);
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return View::make('pages.home');
 }
Example #28
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $type = Request::get('type');
     $item_name = "";
     $item_price = 0;
     // if($type == '1') {
     //   $item_name = "30Points";
     //   $item_price = 30;
     // } else
     if ($type == '2') {
         $item_name = "40Points";
         $item_price = 50;
     } else {
         if ($type == '3') {
             $item_name = "75Points";
             $item_price = 90;
         } else {
             if ($type == '4') {
                 $item_name = "125Points";
                 $item_price = 150;
             } else {
                 if ($type == '5') {
                     $item_name = "255Points";
                     $item_price = 300;
                 } else {
                     return Redirect::route('home')->with('error', 'เกิดปัญหาในการเติมเครดิตกรุณาลองใหม่อีกครั้ง');
                 }
             }
         }
     }
     $item_1 = new Item();
     $item_1->setName($item_name)->setCurrency('THB')->setQuantity(1)->setPrice($item_price);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('THB')->setTotal($item_price);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('home')->with('error', 'เกิดปัญหาในการเติมเครดิตกรุณาลองใหม่อีกครั้ง');
 }
 public function postPayment($request)
 {
     $requestItems = $request->json('items');
     $requestTransactionDescription = $request->json('transactionDescription');
     $requestCallback = $request->json('callback');
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = [];
     $totalPrice = 0;
     foreach ($requestItems as $item) {
         $item = (object) $item;
         $savedProduct = Product::find($item->id);
         if ($savedProduct !== null) {
             $quantity = isset($item->quantity) === true ? $item->quantity : '1';
             $tempItem = new Item();
             $tempItem->setName($savedProduct->name)->setCurrency(config('payment.currency', 'BRL'))->setQuantity($quantity)->setPrice($savedProduct->price);
             array_push($items, $tempItem);
             $totalPrice += floatval($tempItem->price) * $quantity;
         }
     }
     // add items to list
     $item_list = new ItemList();
     $item_list->setItems($items);
     $amount = new Amount();
     $amount->setCurrency(config('payment.currency', 'BRL'))->setTotal(floatval($totalPrice));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list);
     if (isset($requestTransactionDescription) && $requestTransactionDescription != null) {
         $transaction->setDescription($requestTransactionDescription);
     } else {
         $transaction->setDescription(config('payment.globalTransactionDescription', ''));
     }
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::action('PaymentController@getPaymentStatus', ['paypal']))->setCancelUrl(URL::action('PaymentController@getPaymentCancel', ['paypal']));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPalConnectionException $ex) {
         $result = new StdClass();
         $result->success = false;
         $result->message = 'internal-server-error';
         return view('payment.pay')->with(["result" => json_encode($result)]);
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     // add callback to the session
     if (isset($requestCallback)) {
         Session::put('paymentCallback', $requestCallback);
     }
     if (isset($redirect_url)) {
         // redirect to paypal
         return json_encode(["url" => $redirect_url]);
     }
     $result = new StdClass();
     $result->success = false;
     $result->message = 'internal-server-error';
     return view('payment.pay')->with(["result" => json_encode($result)]);
 }
 /**
  * Create payment
  *
  * @param string $transactionDescription Description for transaction
  * @return mixed Paypal checkout URL or false
  */
 public function createPayment($transactionDescription)
 {
     $checkoutUrl = false;
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $itemList = new ItemList();
     $itemList->setItems($this->itemList);
     $amount = new Amount();
     $amount->setCurrency($this->paymentCurrency)->setTotal($this->totalAmount);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($transactionDescription);
     $redirectUrls = new RedirectUrls();
     // Check $cancelUrl. If it's null. By default, cancel URL
     // same as success URL
     if (is_null($this->cancelUrl)) {
         $this->cancelUrl = $this->returnUrl;
     }
     $redirectUrls->setReturnUrl($this->returnUrl)->setCancelUrl($this->cancelUrl);
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
     try {
         $payment->create($this->apiContext);
     } catch (\PayPal\Exception\PPConnectionException $paypalException) {
         throw new \Exception($paypalException->getMessage());
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $checkoutUrl = $link->getHref();
             session(['paypal_payment_id' => $payment->getId()]);
             break;
         }
     }
     return $checkoutUrl;
 }