本文整理汇总了PHP中PayPal\Api\RedirectUrls类的典型用法代码示例。如果您正苦于以下问题:PHP RedirectUrls类的具体用法?PHP RedirectUrls怎么用?PHP RedirectUrls使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RedirectUrls类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateApprovalLink
/**
* Generate the approval link for a PayPal payment
* @param $amountToPay
* @return mixed
*/
public function generateApprovalLink($amountToPay)
{
$amountToPay = number_format($amountToPay, 2, ".", "");
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amount = new Amount();
$amount->setCurrency($this->currency)->setTotal($amountToPay);
$transaction = new Transaction();
$transaction->setAmount($amount)->setDescription(trans("billing.paymentToCompany", ['company_name' => Config::get("customer_portal.company_name")]))->setInvoiceNumber(uniqid(true));
//This is not a payment on a specific invoice, so we'll just generate a unique string, which is what PayPal requires
$tempToken = new PaypalTemporaryToken(['account_id' => get_user()->account_id, 'token' => uniqid(true)]);
$tempToken->save();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(action("PayPalController@completePayment", ['temporary_token' => $tempToken->token]))->setCancelUrl(action("PayPalController@cancelPayment", ['temporary_token' => $tempToken->token]));
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
$payment->create($this->apiContext);
return $payment->getApprovalLink();
}
示例2: CreateTransaction
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);
}
示例3: testInvalidRedirectUrls
/**
* @dataProvider invalidRedirectUrlsProvider
*/
public function testInvalidRedirectUrls($return_url, $cancel_url)
{
$redirectUrls = new RedirectUrls();
$this->setExpectedException('\\InvalidArgumentException');
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
}
示例4: startPayment
/**
* @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;
}
示例5: init
/**
* @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());
}
示例6: makePaymentUsingPayPal
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;
}
示例7: createPayment
/**
* @param array $items
* @param $shippingDetails
* @param string $intent
* @throws Exception
* @return null|string
*/
public function createPayment(array $items, Details $shippingDetails, $intent = PaymentConst::INTENT_SALE)
{
$apiContext = $this->connectionService->getApiContext();
$dispatcher = $this->connectionService->getDispatcher();
$dispatcher->dispatch(PaymentEvent::NEW_SETUP);
$successUrl = '';
$cancelUrl = '';
switch ($intent) {
case PaymentConst::INTENT_SALE:
$successUrl = $this->router->generate('paypal_payment_sale_success', array(), true);
$cancelUrl = $this->router->generate('paypal_payment_sale_cancel', array(), true);
break;
case PaymentConst::INTENT_AUTHORIZE:
$successUrl = $this->router->generate('paypal_payment_authorize_success', array(), true);
$cancelUrl = $this->router->generate('paypal_payment_authorize_cancel', array(), true);
break;
}
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($successUrl)->setCancelUrl($cancelUrl);
$payment = PaymentService::create($items, $shippingDetails, $intent, PaymentConst::METHOD_PAYPAL);
$payment->setRedirectUrls($redirectUrls);
$paymentEvent = new PayPalPaymentEvent($payment);
$dispatcher->dispatch(PaymentEvent::NEW_START, $paymentEvent);
$result = $payment->create($apiContext);
$paymentEvent = new PayPalPaymentEvent($result);
$dispatcher->dispatch(PaymentEvent::NEW_END, $paymentEvent);
$payment->create($apiContext);
$approvalUrl = $payment->getApprovalLink();
return $approvalUrl;
}
示例8: postPayment
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');
}
示例9: postPayment
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.');
}
示例10: postPayment
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');
}
示例11: postPayment
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');
}
示例12: pay
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');
}
示例13: postPayment
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.');
}
示例14: postPayment
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'); */
}
示例15: postPayment
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');
}