/** * @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 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'); }
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 = 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 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'); }
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()); }
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 getPayTaskUrl($task) { $apiContext = $this->apiContext; $payer = new Payer(); $payer->setPaymentMethod("paypal"); $item1 = new Item(); $item1->setName($task->title)->setCurrency($this->currency)->setQuantity(1)->setSku($task->id)->setPrice($task->total); $itemList = new ItemList(); $itemList->setItems(array($item1)); $amount = new Amount(); $amount->setCurrency($this->currency)->setTotal($task->total); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment for " . $task->title)->setInvoiceNumber($task->id . '_' . date('YmdHis')); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($this->redirectSuccess . '/' . $task->id)->setCancelUrl($this->redirectFail . '/' . $task->id); $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); $payment->create($apiContext); $this->storePaymentSession($payment->getId(), $task->id); return $payment->getApprovalLink(); }
/** * {@inheritdoc} */ public function processPayment(PaymentInterface $payment) : PaymentInterface { $order = $payment->getOrder(); $payer = $this->createPayer('paypal'); $redirectUrls = $this->createRedirectUrls($payment); $transaction = $this->createTransaction($order); $payPalPayment = new Payment(); $payPalPayment->setIntent("sale"); $payPalPayment->setPayer($payer); $payPalPayment->setRedirectUrls($redirectUrls); $payPalPayment->setTransactions([$transaction]); try { $payPalPayment->create($apiContext); } catch (\Exception $e) { echo $e->getMessage(); } $payment->setApprovalUrl($payPalPayment->getApprovalLink()); $payment->setState($payPalPayment->getState()); $payment->setToken($payPalPayment->getId()); $this->paymentManager->updateResource($payment); return $payment; }
/** * @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 getRefillUrl($amount, User $user) { $paymentTitle = Config::get('services.paypal.payment_title'); $amount = floatval($amount); $apiContext = $this->apiContext; $payer = new Payer(); $payer->setPaymentMethod("paypal"); $item1 = new Item(); $item1->setName($paymentTitle)->setCurrency($this->currency)->setQuantity(1)->setSku('1')->setPrice($amount); $itemList = new ItemList(); $itemList->setItems(array($item1)); $amountObj = new Amount(); $amountObj->setCurrency($this->currency)->setTotal($amount); $transaction = new Transaction(); $transaction->setAmount($amountObj)->setItemList($itemList)->setDescription($paymentTitle)->setInvoiceNumber($user->id . '_' . date('YmdHis')); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($this->redirectSuccess . '/' . $user->id)->setCancelUrl($this->redirectFail . '/' . $user->id); $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); $payment->create($apiContext); $this->storePaymentSession($payment->getId(), $user->id, $amount, $this->currency, $itemList); return $payment->getApprovalLink(); }
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)]); }
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()); } }
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'); }
$card = new CreditCard(); $card->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper")->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi)); $amount = new Amount(); $amount->setCurrency("USD")->setTotal(1); $transaction = new Transaction(); $transaction->setAmount($amount)->setDescription("Payment description."); $payment = new Payment(); // Setting intent to authorize creates a payment // authorization. Setting it to sale creates actual payment $payment->setIntent("authorize")->setPayer($payer)->setTransactions(array($transaction)); // For Sample Purposes Only. $request = clone $payment; // ### 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. try { $payment->create($apiContext); } catch (Exception $ex) { ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex); exit(1); } ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment); $transactions = $payment->getTransactions(); $relatedResources = $transactions[0]->getRelatedResources(); $authorization = $relatedResources[0]->getAuthorization(); return $authorization;
/** * @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 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); } }
$payer = new Payer(); $details = new Details(); $amount = new Amount(); $transaction = new Transaction(); $payment = new Payment(); $redirectUrls = new RedirectUrls(); $payer->setPaymentMethod('paypal'); $details->setShipping('2.00')->setTax('0.00')->setSubtotal('20.00'); $amount->setCurrency('GBP')->setTotal('22.00')->setDetails($details); $transaction->setAmount($amount)->setDescription('Membership'); $payment->setIntent('sale')->setPayer($payer)->setTransactions([$transaction]); $redirectUrls->setReturnUrl('http://localhost/paypal/paypal/pay.php?approved=true')->setCancelUrl('http://localhost/paypal/paypal/pay.php?approved=false'); $payment->setRedirectUrls($redirectUrls); try { $payment->create($api); $hash = md5($payment->getId()); // var_dump($hash); die(); $_SESSION['paypal_hash'] = $hash; $store = $db->prepare("INSERT INTO transaction_paypal VALUES('',?,?,?,?)"); $store->bindValue(1, $_SESSION['user_id'], PDO::PARAM_INT); $store->bindValue(2, $payment->getId(), PDO::PARAM_INT); $store->bindValue(3, $hash, PDO::PARAM_INT); $store->bindValue(4, 0, PDO::PARAM_INT); $store->execute(); } catch (PPConnectionException $e) { header("location: ../paypal/error.php"); die; } foreach ($payment->getLinks() as $link) { if ($link->getRel() == 'approval_url') { $redirectUrl = $link->getHref();
/** * @param $data array form post data * @return string HTML to display */ function _prePayment($data) { $this->_autoload(); $order = $this->_getOrder($data['order_number']); //initialise application $app = JFactory::getApplication(); //get card input $data['cardtype'] = $app->input->getString("cardtype"); $data['cardnum'] = $app->input->getString("cardnum"); $month = $app->input->getString("month"); $year = $app->input->getString("year"); $card_exp = $month . '' . $year; $data['cardexp'] = $card_exp; $data['cardcvv'] = $app->input->getString("cardcvv"); $data['cardnum_last4'] = substr($app->input->getString("cardnum"), -4); //initialise payment $apiContext = new ApiContext(new OAuthTokenCredential($this->api_clientId, $this->api_clientSecret)); $apiContext->setConfig(array('mode' => $this->api_mode)); // echo'<pre>';print_r($apiContext);die; $card = new CreditCard(); $card->setType($data['cardtype']); $card->setNumber($data['cardnum']); $card->setExpireMonth($month); $card->setExpireYear($year); $card->setFirstName($data['firstname']); $card->setLastName($data['lastname']); $card->setCvv2($data['cardcvv']); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi)); if (!empty($data['email'])) { $payerInfo = new PayerInfo(); $payerInfo->setFirstName($data['firstname']); $payerInfo->setLastName($data['lastname']); $payerInfo->setEmail($data['email']); $payer->setPayerInfo($payerInfo); } $amount = new Amount(); $amount->setCurrency($this->currency); $amount->setTotal($data['total']); $item1 = new Item(); $item1->setName($data['order_number'])->setDescription($data['order_number'])->setCurrency($this->currency)->setQuantity(1)->setTax(0)->setPrice($data['total']); $itemList = new ItemList(); $itemList->setItems(array($item1)); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setItemList($itemList); $transaction->setDescription($data['order_number']); $payment = new Payment(); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $request = clone $payment; try { $payment->create($apiContext); } catch (PayPal\Exception\PayPalConnectionException $ex) { $error = json_decode($ex->getData()); $error_html = '<h2>' . $error->name . '</h2><br>'; foreach ($error->details as $r) { $error_html .= '- ' . $r->field . ' - ' . $r->issue . '<br>'; } $app->enqueueMessage($error_html, 'error'); $app->redirect('index.php?option=com_bookpro&view=formpayment&order_id=' . $order->id . '&' . JSession::getFormToken() . '=1'); return; } catch (Exception $ex) { die($ex); } $ack = $payment->getState(); if ($ack == 'approved' || $ack == 'completed') { $order->pay_status = "SUCCESS"; $order->order_status = "CONFIRMED"; $order->tx_id = $payment->getId(); $order->store(); } else { JLog::addLogger(array('text_file' => 'paypal.txt', 'text_file_path' => 'logs', 'text_file_no_php' => 1, 'text_entry_format' => '{DATE} {TIME} {MESSAGE}'), JLog::ALERT); JLog::add('Transaction: ' . json_encode($payment) . '\\nOrder: ' . $order->order_number . ' Status: ' . $ack, JLog::ALERT, 'com_bookpro'); $order->pay_status = "PENDING"; $order->tx_id = $transaction_id; $order->store(); } $app = JFactory::getApplication(); $app->redirect('index.php?option=com_bookpro&controller=payment&task=postpayment&method=' . $this->_element . '&order_number=' . $order->order_number); return; }
function payment_redirect($cart = false, $approval = false, $order_exists = false) { global $order, $xtPrice; // auth $apiContext = $this->apiContext(); // set payment $payer = new Payer(); $payer->setPaymentMethod('paypal'); if ($this->code == 'paypalinstallment') { $payer->setExternalSelectedFundingInstrumentType('CREDIT'); } // set payer_info $payer_info = new PayerInfo(); // set items $item = array(); // set details $this->details = new Details(); // set amount $this->amount = new Amount(); // set ItemList $itemList = new ItemList(); // set redirect $redirectUrls = new RedirectUrls(); // set address $shipping_address = new ShippingAddress(); if ($cart === true) { $products = $_SESSION['cart']->get_products(); for ($i = 0, $n = sizeof($products); $i < $n; $i++) { $item[$i] = new Item(); $item[$i]->setName($this->encode_utf8($products[$i]['name']))->setCurrency($_SESSION['currency'])->setQuantity($products[$i]['quantity'])->setPrice($products[$i]['price'])->setSku($products[$i]['model'] != '' ? $products[$i]['model'] : $products[$i]['id']); $this->details->setSubtotal($this->details->getSubtotal() + $products[$i]['final_price']); } $total = $price = $_SESSION['cart']->show_total(); if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1 && $_SESSION['customers_status']['customers_status_ot_discount'] != '0.00') { if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) { $price = $total - $_SESSION['cart']->show_tax(false); } $this->details->setShippingDiscount($this->details->getShippingDiscount() + $xtPrice->xtcGetDC($price, $_SESSION['customers_status']['customers_status_ot_discount']) * -1); } $this->amount->setTotal($total + $this->details->getShippingDiscount()); if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1 && MODULE_SMALL_BUSINESS != 'true') { foreach ($_SESSION['cart']->tax as $tax) { $this->details->setTax($this->details->getTax() + $tax['value']); } $total = $this->calc_total(); $amount_total = $this->amount->getTotal(); if ((string) $amount_total != (string) $total) { $this->details->setTax($this->details->getTax() + ($amount_total - $total)); } } $shipping_cost = $this->get_config('MODULE_PAYMENT_' . strtoupper($this->code) . '_SHIPPING_COST'); if ((int) $shipping_cost > 0) { $i = count($item); $item[$i] = new Item(); $item[$i]->setName($this->encode_utf8(PAYPAL_EXP_VORL))->setCurrency($_SESSION['currency'])->setQuantity(1)->setPrice($shipping_cost); $this->amount->setTotal($this->amount->getTotal() + $shipping_cost); $this->details->setSubtotal($this->amount->getTotal()); } // set amount $this->amount->setCurrency($_SESSION['currency'])->setDetails($this->details); // set redirect $redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link('callback/paypal/paypalcart.php', '', 'SSL')))->setCancelUrl($this->link_encoding(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'SSL'))); } else { $shipping_address->setRecipientName($this->encode_utf8($order->delivery['firstname'] . ' ' . $order->delivery['lastname']))->setLine1($this->encode_utf8($order->delivery['street_address']))->setCity($this->encode_utf8($order->delivery['city']))->setCountryCode($this->encode_utf8($order_exists === false ? $order->delivery['country']['iso_code_2'] : $order->delivery['country_iso_2']))->setPostalCode($this->encode_utf8($order->delivery['postcode']))->setState($this->encode_utf8($order->delivery['state'] != '' ? xtc_get_zone_code($order->delivery['country_id'], $order->delivery['zone_id'], $order->delivery['state']) : '')); if ($order->delivery['suburb'] != '') { $shipping_address->setLine2($this->encode_utf8($order->delivery['suburb'])); } $subtotal = 0; for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { $item[$i] = new Item(); $item[$i]->setName($this->encode_utf8($order->products[$i]['name']))->setCurrency($order->info['currency'])->setQuantity($order->products[$i]['qty'])->setPrice($order->products[$i]['price'])->setSku($order->products[$i]['model'] != '' ? $order->products[$i]['model'] : $order->products[$i]['id']); $subtotal += $order->products[$i]['price'] * $order->products[$i]['qty']; } // set totals if ($order_exists === false) { if (!class_exists('order_total')) { require_once DIR_WS_CLASSES . 'order_total.php'; } $order_total_modules = new order_total(); $order_totals = $order_total_modules->process(); $this->get_totals($order_totals, true, $subtotal); } else { $this->get_totals($order->totals); } // set amount $this->amount->setCurrency($order->info['currency'])->setDetails($this->details); // set redirect if ($order_exists === false) { $redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')))->setCancelUrl($this->link_encoding(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL'))); } else { $redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link('callback/paypal/' . $this->code . '.php', 'oID=' . $order->info['order_id'] . '&key=' . md5($order->customer['email_address']), 'SSL')))->setCancelUrl($this->link_encoding(xtc_href_link('callback/paypal/' . $this->code . '.php', 'payment_error=' . $this->code . '&oID=' . $order->info['order_id'] . '&key=' . md5($order->customer['email_address']), 'SSL'))); } if ($this->code == 'paypalinstallment') { $redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link(FILENAME_CHECKOUT_CONFIRMATION, 'conditions=true', 'SSL'))); } } // set ItemList if ($this->get_config('PAYPAL_ADD_CART_DETAILS') == '0' || $this->check_discount() === true) { $item = array(); $item[0] = new Item(); $item[0]->setName($this->encode_utf8(MODULE_PAYMENT_PAYPAL_TEXT_ORDER))->setCurrency($_SESSION['currency'])->setQuantity(1)->setPrice($this->details->getSubtotal()); if ($cart === true) { $shipping_cost = $this->get_config('MODULE_PAYMENT_' . strtoupper($this->code) . '_SHIPPING_COST'); if ((int) $shipping_cost > 0) { $item[1] = new Item(); $item[1]->setName($this->encode_utf8(PAYPAL_EXP_VORL))->setCurrency($_SESSION['currency'])->setQuantity(1)->setPrice($shipping_cost); $this->amount->setTotal($this->amount->getTotal() + $shipping_cost); $this->details->setSubtotal($this->amount->getTotal()); } } } $itemList->setItems($item); // profile $address_override = false; $profile_id = $this->get_config('PAYPAL_' . strtoupper($this->code . '_' . $_SESSION['language_code']) . '_PROFILE'); if ($profile_id == '') { $profile_id = $this->get_config('PAYPAL_STANDARD_PROFILE'); } if ($profile_id != '') { if ($this->get_config(strtoupper($profile_id) . '_TIME') < time() - 3600 * 24) { $profile = $this->get_profile($profile_id); $sql_data_array = array(array('config_key' => strtoupper($profile_id) . '_TIME', 'config_value' => time()), array('config_key' => strtoupper($profile_id) . '_ADDRESS', 'config_value' => $profile[0]['input_fields']['address_override'])); $this->save_config($sql_data_array); $address_override = $profile[0]['input_fields']['address_override'] == '0' ? true : false; } else { $address_override = $this->get_config(strtoupper($profile_id) . '_ADDRESS') == '0' ? true : false; } } if ($cart === false && $approval === false && $address_override === false || $order_exists === true || $this->code == 'paypalinstallment') { $itemList->setShippingAddress($shipping_address); } if ($this->code == 'paypalinstallment') { // set payment address $payment_address = new Address(); $payment_address->setLine1($this->encode_utf8($order->billing['street_address']))->setCity($this->encode_utf8($order->billing['city']))->setState($this->encode_utf8($order->billing['state'] != '' ? xtc_get_zone_code($order->billing['country_id'], $order->billing['zone_id'], $order->billing['state']) : ''))->setPostalCode($this->encode_utf8($order->billing['postcode']))->setCountryCode($this->encode_utf8($order->billing['country']['iso_code_2'])); if ($order->billing['suburb'] != '') { $payment_address->setLine2($this->encode_utf8($order->billing['suburb'])); } $payer_info->setBillingAddress($payment_address)->setShippingAddress($shipping_address)->setEmail($this->encode_utf8($order->customer['email_address']))->setFirstName($this->encode_utf8($order->delivery['firstname']))->setLastName($this->encode_utf8($order->delivery['lastname'])); $payer->setPayerInfo($payer_info); } // set transaction $transaction = new Transaction(); $transaction->setAmount($this->amount)->setItemList($itemList)->setDescription($this->encode_utf8(STORE_NAME))->setInvoiceNumber(uniqid()); // set payment $payment = new Payment(); $payment->setIntent($this->transaction_type)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction))->setCreateTime(time()); if (isset($profile_id) && $profile_id != '') { $payment->setExperienceProfileId($profile_id); } try { $payment->create($apiContext); $_SESSION['paypal']['paymentId'] = $payment->getId(); $approval_link = $payment->getApprovalLink(); if ($approval === false) { xtc_redirect($approval_link); } else { return $approval_link; } } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); unset($_SESSION['paypal']); if ($cart === true) { xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'SSL')); } elseif ($this->code != 'paypalplus') { xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL')); } } }
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.'); }
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'); }
// for payment approval try { $payment->create($apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception: " . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } // ### Get redirect url // The API response provides the url that you must redirect // the buyer to. Retrieve the url from the $payment->getLinks() // method foreach ($payment->getLinks() as $link) { if ($link->getRel() == 'approval_url') { $redirectUrl = $link->getHref(); break; } } // ### Redirect buyer to PayPal website // Save the payment id so that you can 'complete' the payment // once the buyer approves the payment and is redirected // back to your website. // // It is not a great idea to store the payment id // in the session. In a real world app, you may want to // store the payment id in a database. $_SESSION['paymentId'] = $payment->getId(); if (isset($redirectUrl)) { header("Location: {$redirectUrl}"); exit; }