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.'); }
function CreateTransaction($transactionType, $itemArray, $details) { $payer = new Payer(); $payer->setPaymentMethod($GLOBALS['PAYPAL']['payment_method']); $itemList = new ItemList(); $itemList->setItems($itemArray); $amount = new Amount(); $amount->setCurrency($GLOBALS['PAYPAL']['currency'])->setTotal(GetDetailsTotal($details))->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription($GLOBALS['TRANSACTION_TYPE']['DONATION']['payment_desc'])->setInvoiceNumber(uniqid()); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($GLOBALS['TRANSACTION_TYPE']['DONATION']['return_url'])->setCancelUrl($GLOBALS['TRANSACTION_TYPE']['DONATION']['cancel_url']); $payment = new Payment(); $payment->setIntent($GLOBALS['TRANSACTION_TYPE']['DONATION']['intent'])->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); $request = clone $payment; try { $payment->create($GLOBALS['PAYPAL']['api_context']); } catch (Exception $ex) { ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); return false; } $approvalUrl = $payment->getApprovalLink(); echo $approvalUrl; return array('request' => $request, 'payment' => $payment, 'approvalUrl' => $approvalUrl); }
/** * @return Payment * @throws CheckoutException */ public function startPayment() { $total_amount = ($this->request->amount + $this->request->tax_amount - $this->request->discount_amount) * 100; $apiContext->setConfig(array('service.EndPoint' => "https://test-api.sandbox.paypal.com")); $payer = new Payer(); $payer->setPaymentMethod('paypal'); $item1 = new Item(); $item1->setName('Product1')->setCurrency('EUR')->setPrice(10.0)->setQuantity(2)->setTax(3.0); $itemList = new ItemList(); $itemList->setItems(array($item1)); $details = new Details(); $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5); $amount = new Amount(); $amount->setCurrency('EUR')->setTotal(20)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment')->setInvoiceNumber('transactionid'); $baseUrl = getBaseUrl(); $redir = new RedirectUrls(); $redir->setReturnUrl($baseUrl . '/'); $redir->setCancelUrl($baseUrl . '/'); $payment = new Payment(); $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redir)->setTransactions(array($transaction)); $request = clone $payment; try { $payment->create($apiContext); } catch (\Exception $e) { throw new CheckoutException('Paypal error', 500, $e); } $approvalUrl = $payment->getApprovalLink(); ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment); return $payment; }
/** * @param PaymentInterface $payment */ public function init(PaymentInterface $payment) { $credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']); $apiContext = new ApiContext($credentials); $apiContext->setConfig(['mode' => $this->options['mode']]); $payer = new Payer(); $payer->setPaymentMethod('paypal'); $amount = new Amount(); $amount->setCurrency($this->options['currency']); $amount->setTotal($payment->getPaymentSum()); $item = new Item(); $item->setName($payment->getDescription()); $item->setCurrency($amount->getCurrency()); $item->setQuantity(1); $item->setPrice($amount->getTotal()); $itemList = new ItemList(); $itemList->addItem($item); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription($payment->getDescription()); $transaction->setItemList($itemList); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($payment->getExtraData('return_url')); $redirectUrls->setCancelUrl($payment->getExtraData('cancel_url')); $paypalPayment = new Payment(); $paypalPayment->setIntent('sale'); $paypalPayment->setPayer($payer); $paypalPayment->setTransactions([$transaction]); $paypalPayment->setRedirectUrls($redirectUrls); $paypalPayment->create($apiContext); $payment->setExtraData('paypal_payment_id', $paypalPayment->getId()); $payment->setExtraData('approval_link', $paypalPayment->getApprovalLink()); }
public function testSerializeDeserialize() { $t1 = $this->transaction; $t2 = new Transaction(); $t2->fromJson($t1->toJson()); $this->assertEquals($t1, $t2); }
public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl) { $payer = new Payer(); $payer->setPaymentMethod('paypal'); // specify the payment ammount $amount = new Amount(); $amount->setCurrency($currency); $amount->setTotal($total); // ###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); $transaction->setDescription($paymentDesc); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($returnUrl . '&success=true'); $redirectUrls->setCancelUrl($returnUrl . '&success=false'); $payment = new Payment(); $payment->setRedirectUrls($redirectUrls); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); try { $payment->create($this->apiContext); } catch (Exception $e) { throw new Exception($e); } return $payment; }
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'); }
/** * Create the Payment request and process * @return null|string The approval url to which the user has to be redirected */ public function createPayment() { $payer = new Payer(); $payer->setPaymentMethod("paypal"); $this->validateData(); if (!is_null($this->details)) { $this->getAmount()->setDetails($this->details); } $transaction = new Transaction(); $transaction->setAmount($this->getAmount())->setDescription($this->getDescription())->setInvoiceNumber($this->getInvoiceNumber()); if (count($this->itemList->getItems())) { $transaction->setItemList($this->itemList); } $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($this->getSuccessUrl(self::paymentMethod))->setCancelUrl($this->getCancelUrl(self::paymentMethod)); $payment = new Payment(); $payment->setIntent(self::ACTION)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); try { $payment->create($this->getApiContext($this->clientId, $this->clientSecret)); } catch (\Exception $ex) { $this->container->get('logger')->error($ex); return null; } $approvalUrl = $payment->getApprovalLink(); return $approvalUrl; }
/** * Creates a PayPal transaction object for given order * * @param OrderInterface $order * * @return Transaction */ protected function createTransaction(OrderInterface $order) : Transaction { $transaction = new Transaction(); $transaction->setAmount($this->createAmount($order)); $transaction->setItemList($this->createItemList($order)); $transaction->setDescription($order->getId()); return $transaction; }
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'); }
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.'); }
public function createTransaction($price, $currency, $invoiceNumber = '') { $amount = new Amount(); $amount->setCurrency($currency)->setTotal($price); if (empty($invoiceNumber)) { $invoiceNumber = uniqid(); } $transaction = new Transaction(); $transaction->setAmount($amount)->setInvoiceNumber($invoiceNumber); return $transaction; }
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'); */ }
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 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 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 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'); }
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.'); }
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'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('ATGFkB2ea6f0pM92jwBqkZ17kxsiftDvUhLHyXson-10AUs7n5TocpEc0sis7Cl_fMIxS8uQO04kPP8Q', 'ENP_JPkc3e4Yl6VeHZ_0vgvEh0SYdtzkMvw_VGBrr2nJ67sg9RuKB_YF7y_k4bj-4t2U-_23MaAGV3vD')); $status = ''; if (isset($_GET['success']) && $_GET['success'] == 'true') { $transaction = new Transaction(); $amount = new Amount(); $paymentId = $_GET['paymentId']; $payment = Payment::get($paymentId, $apiContext); $amount->setCurrency($payment->transactions[0]->amount->getCurrency()); $amount->setTotal($payment->transactions[0]->amount->getTotal()); $amount->setDetails($payment->transactions[0]->amount->getDetails()); $transaction->setAmount($amount); $execution = new PaymentExecution(); $execution->setPayerId($_GET['PayerID']); $execution->addTransaction($transaction); $rifas = $payment->transactions[0]->description; $rifas = explode(',', $rifas); $aux = 0; try { foreach ($rifas as $rifa) { $aux = Rifa::find($rifa); if ($aux->user_id == NULL) { $aux->user_id = Auth::user()->id; $aux->save(); } else { $status = 'Numeros de rifas ja foram escolhidos por outra pessoa, por favor escolha novamente.'; return view('confirmacao')->with('status', $status); } } $result = $payment->execute($execution, $apiContext); try { $payment = Payment::get($paymentId, $apiContext); } catch (Exception $ex) { $status = 'Pagamento ainda sem confirmacao'; } } catch (Exception $ex) { $status = 'Compra nao foi executada'; } if ($result->state == "approved") { $status = 'Compra feita com sucesso!'; $aux = 1; } return view('confirmacao')->with('status', $status)->with('aux', $aux); } else { $status = 'Compra cancelada pelo usuario'; return view('confirmacao')->with('status', $status); } }
function paypal($data) { try { foreach ($data as $k => $v) { ${$k} = $v; } include_once 'config.paypal.php'; $apiContext = new ApiContext(new OAuthTokenCredential(CLIENT_ID, CLIENT_SECRET)); list($m, $y) = explode("/", $card_expiry); $card = new CreditCard(); $card->setNumber($card_number); $card->setType(strtolower($card_type)); $card->setExpireMonth($m); $card->setExpireYear($y); $card->setCvv2($card_cvv); $card->setFirstName($first_name); $card->setLastName($last_name); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod('credit_card'); $payer->setFundingInstruments(array($fi)); $amount = new Amount(); $amount->setCurrency($currency); $amount->setTotal($price); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription('Enter your card details and proceed'); $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $res = json_decode($payment->create($apiContext)); $this->save($data, __FUNCTION__, $res, 1); return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $res->state)]); } catch (Exception $e) { if ($e instanceof PPConfigurationException) { } elseif ($e instanceof PPConnectionException) { } elseif ($e instanceof PayPal\Exception\PayPalConnectionException) { $res = json_decode($e->getData(), 1); $this->save($data, __FUNCTION__, $res, 0); $msg = array_shift(isset($res["details"]) ? $res["details"] : []); return json_encode(["status" => false, "msg" => $res["name"] == "UNKNOWN_ERROR" || empty($msg["issue"]) ? "An unknown error has occurred" : sprintf("%s %s", ["cvv2" => "CVV2", "expire_year" => "Card expiration", "credit_card" => "", "type" => "Invalid credit card number or", "number" => "Credit card number", "expire_month" => "Expiration month"][end(explode(".", $msg["field"]))], strtolower($msg["issue"]))]); } else { throw $e; } } }
public static function createPayPal($invoiceNumber, \PropelPDO $con) { $i18n = Localizer::get('payment'); // ### Payer // A resource representing a Payer that funds a payment // For direct credit card payments, set payment method // to 'credit_card' and add an array of funding instruments. $payer = new Payer(); $payer->setPaymentMethod("paypal"); // ### Itemized information // (Optional) Lets you specify item wise // information $item1 = new Item(); $item1->setName($i18n['item_name'])->setDescription($i18n['item_description'])->setCurrency(TransactionEntity::$BASE_CURRENCY)->setQuantity(1)->setTax(0)->setPrice(TransactionEntity::$MEMBER_FEE); $itemList = new ItemList(); $itemList->setItems(array($item1)); // ### Amount // Lets you specify a payment amount. // You can also specify additional details // such as shipping, tax. $amount = new Amount(); $amount->setCurrency(TransactionEntity::$BASE_CURRENCY)->setTotal(TransactionEntity::$MEMBER_FEE); // ### Transaction // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription($i18n['transaction_description'])->setInvoiceNumber($invoiceNumber); // ### Redirect urls // Set the urls that the buyer must be redirected to after // payment approval/ cancellation. $success = Router::toModule('account', 'index'); $failure = Router::toModule('guide', 'index', ['purchase_failed' => true]); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($success)->setCancelUrl($failure); // ### Payment // A Payment Resource; create one using // the above types and intent set to sale 'sale' $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setExperienceProfileId(self::getPaymentExperienceProfileId())->setTransactions(array($transaction)); // ### Create Payment // Create a payment by calling the payment->create() method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // The return object contains the state. $apiContext = self::getApiContext(); $payment->create($apiContext); return $payment; }
public function success() { $paymentId = request('paymentId'); $payment = Payment::get($paymentId, $this->paypal); $execution = new PaymentExecution(); $execution->setPayerId(request('PayerID')); $transaction = new Transaction(); $amount = new Amount(); $details = new Details(); $productsSum = 0.0; foreach ($this->order->getProducts() as $product) { $productsSum += $product->getTotal(); } $details->setSubtotal($productsSum); $total = $productsSum; if ($delivery = $this->order->getDelivery()) { $details->setShipping($delivery); $total += $delivery; } if ($vat = $this->order->getVat()) { $details->setTax($vat); $total += $vat; } $amount->setCurrency($this->order->getCurrency())->setTotal($total)->setDetails($details); $transaction->setAmount($amount); $execution->addTransaction($transaction); try { $payment->execute($execution, $this->paypal); } catch (\Exception $e) { $this->log($e); throw $e; } finally { Payment::get($paymentId, $this->paypal); } }
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'); }
/** * 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(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'); }
public function createPayment($amount, $description, $redirectUrl) { $apiContext = $this->getPayPal(); $payer = new Payer(); $payer->setPaymentMethod("paypal"); $amountObject = new Amount(); $amountObject->setCurrency("USD")->setTotal($amount); $transaction = new Transaction(); $transaction->setAmount($amountObject)->setDescription($description); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($redirectUrl . "?success=true")->setCancelUrl($redirectUrl . "?success=false"); $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); $data = array("amount" => $amount, "description" => $description, "redirectUrl" => $redirectUrl, "method" => $this->paymentMethod, "metadata" => $this->metadata, "webhookUrl" => $this->webhook, "locale" => $this->locale); $payment->create($apiContext); $approvalUrl = $payment->getApprovalLink(); return (object) array('id' => $payment->getId(), 'url' => $approvalUrl, 'provider' => 'paypal'); }
public function credit_card() { return "Hello?"; $card = new CreditCard(); $card->setType("visa")->setNumber("4148529247832259")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper"); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi)); $item1 = new Item(); $item1->setName('Ground Coffee 40 oz')->setDescription('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setTax(0.3)->setPrice(7.5); $item2 = new Item(); $item2->setName('Granola bars')->setDescription('Granola Bars with Peanuts')->setCurrency('USD')->setQuantity(5)->setTax(0.2)->setPrice(2); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2)); $details = new Details(); $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5); $amount = new Amount(); $amount->setCurrency("USD")->setTotal(20)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid()); $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction)); $request = clone $payment; try { $payment->create($apiContext); } catch (Exception $ex) { ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using <a href="https://ppmts.custhelp.com/app/answers/detail/a_id/750">Step 4, on this link</a>, and using it.', 'Payment', null, $request, $ex); exit(1); } ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment); return $payment; }