当前位置: 首页>>代码示例>>PHP>>正文


PHP Details::setSubtotal方法代码示例

本文整理汇总了PHP中PayPal\Api\Details::setSubtotal方法的典型用法代码示例。如果您正苦于以下问题:PHP Details::setSubtotal方法的具体用法?PHP Details::setSubtotal怎么用?PHP Details::setSubtotal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PayPal\Api\Details的用法示例。


在下文中一共展示了Details::setSubtotal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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.');
 }
开发者ID:hectorgarcia83,项目名称:plataforma_eliana,代码行数:60,代码来源:PaypalController.php

示例2: success

 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);
     }
 }
开发者ID:schtr4jh,项目名称:payment,代码行数:35,代码来源:PaypalRest.php

示例3: createDetails

 /**
  * @param float $shippingPrice
  * @param float $taxPrice
  * @param float $subtotal
  *
  * @return Details
  */
 public static function createDetails($shippingPrice, $taxPrice, $subtotal)
 {
     $details = new Details();
     $details->setShipping($shippingPrice);
     $details->setTax($taxPrice);
     $details->setSubtotal($subtotal);
     return $details;
 }
开发者ID:metisfw,项目名称:paypal,代码行数:15,代码来源:TransactionHelper.php

示例4: createAmountDetails

 public static function createAmountDetails()
 {
     $amountDetails = new Details();
     $amountDetails->setSubtotal(self::$subtotal);
     $amountDetails->setTax(self::$tax);
     $amountDetails->setShipping(self::$shipping);
     $amountDetails->setFee(self::$fee);
     return $amountDetails;
 }
开发者ID:johnmicahmiguel,项目名称:yodaphp,代码行数:9,代码来源:DetailsTest.php

示例5: 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');
 }
开发者ID:AlbertMed,项目名称:ceseh,代码行数:56,代码来源:PaypalController.php

示例6: 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.');
 }
开发者ID:Rotron,项目名称:carrito_laravel_51,代码行数:55,代码来源:PaypalController.php

示例7: postPayment

 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.');
 }
开发者ID:joseferrer1090,项目名称:hdsport,代码行数:50,代码来源:PaypalController.php

示例8: createDetails

 /**
  * Creates PayPal payment details from given order
  *
  * @param OrderInterface $order
  *
  * @return Details
  */
 protected function createDetails(OrderInterface $order) : Details
 {
     $details = new Details();
     $details->setShipping($order->getShippingTotal()->getNetAmount());
     $details->setTax($order->getOrderTotal()->getTaxAmount());
     $details->setSubtotal($order->getProductTotal()->getNetAmount());
     return $details;
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:15,代码来源:AbstractPayPalProcessor.php

示例9: submit

 public function submit($ordernumber)
 {
     $order = Order::where('ordernumber', "=", $ordernumber)->first();
     if ($order->payment_method == self::PAYMENT_BANK) {
         Mail::send('emails.moneyorder', ['order' => $order], function ($message) use($order) {
             $message->from(self::$shopmail, 'LEAF Music');
             $message->subject('LEAF Music Order ' . $order->ordernumber . ' - waiting for payment');
             $message->to($order->email)->bcc(self::$shopmail)->replyTo(self::$shopmail);
         });
         Mail::send('emails.kaatmail', ['order' => $order], function ($message) use($order) {
             $message->from(self::$shopmail, 'LEAF Music');
             $message->subject('LEAF Music Order ' . $order->ordernumber . ' - waiting for payment');
             $message->to(self::$shopmail);
         });
         $order->status = Order::STATUS_WAITING;
         $order->save();
         return Redirect::action('WelcomeController@result', [$order->ordernumber]);
     } else {
         // setup PayPal api context
         $paypal_conf = \Config::get('paypal');
         $api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
         $api_context->setConfig($paypal_conf['settings']);
         $payer = new Payer();
         $payer->setPaymentMethod("paypal");
         $itemarray = [];
         $details = new Details();
         $subtotal = 0;
         foreach ($order->orderitems as $orderitem) {
             //http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html
             //http://learninglaravel.net/integrate-paypal-sdk-into-laravel-4-laravel-5/link
             if ($orderitem->item_id != Item::SHIPPING) {
                 $item = new \PayPal\Api\Item();
                 $item->setName($orderitem->item->title)->setCurrency('EUR')->setQuantity($orderitem->amount)->setSku($orderitem->item_id)->setPrice($orderitem->itemprice);
                 $itemarray[] = $item;
                 $subtotal += $orderitem->amount * $orderitem->itemprice;
             } else {
                 $details->setShipping($orderitem->itemprice)->setTax(0);
             }
         }
         $details->setSubtotal($subtotal);
         $itemlist = new ItemList();
         $itemlist->setItems($itemarray);
         $transaction = new Transaction();
         $amount = new Amount();
         $amount->setCurrency("EUR")->setTotal($order->totalamount)->setDetails($details);
         $transaction->setAmount($amount)->setItemList($itemlist)->setDescription("Payment description")->setInvoiceNumber($order->order_number);
         $redirectUrls = new RedirectUrls();
         $redirectUrls->setReturnUrl(action('WelcomeController@paypalReturn', [self::PAYPAL_OK, $order->ordernumber]))->setCancelUrl(action('WelcomeController@paypalReturn', [self::PAYPAL_PROBLEM, $order->ordernumber]));
         $payment = new Payment();
         $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
         try {
             $payment->create($api_context);
         } catch (\PayPal\Exception\PayPalConnectionException $pce) {
             // Don't spit out errors or use "exit" like this in production code
             return view('problem', ["order" => $order]);
         }
         $approvalUrl = $payment->getApprovalLink();
         return Redirect::to($approvalUrl);
     }
 }
开发者ID:b0tting,项目名称:leafshop,代码行数:60,代码来源:WelcomeController.php

示例10: actionPay

 public function actionPay($id)
 {
     $return = [];
     $total = 0;
     if (isset(Yii::$app->user->id)) {
         $user = User::findOne(Yii::$app->user->id);
         $race = Race::findOne($id);
         if ($user && $race) {
             /* paypal */
             $clientId = 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS';
             $clientSecret = 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL';
             $apiContext = $this->getApiContext($clientId, $clientSecret);
             $payer = new Payer();
             $payer->setPaymentMethod("paypal");
             $total = $race->cost;
             $item1 = new Item();
             $item1->setName('Inscripción ' . $race->name)->setCurrency('USD')->setQuantity(1)->setPrice($total);
             /*$item1 = new Item();
               $item1->setName('Ground Coffee 40 oz')
                   ->setCurrency('USD')
                   ->setQuantity(1)
                   ->setPrice(7.5);
               $item2 = new Item();
               $item2->setName('Granola bars')
                   ->setCurrency('USD')
                   ->setQuantity(5)
                   ->setPrice(2);*/
             $itemList = new ItemList();
             $itemList->setItems(array($item1));
             $details = new Details();
             /*$details->setShipping(5)
               // ->setTax(1.3)
               ->setSubtotal($total);*/
             $details->setSubtotal($total);
             $amount = new Amount();
             $amount->setCurrency("USD")->setTotal($total)->setDetails($details);
             $transaction = new Transaction();
             $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Inscripción en Aurasur")->setInvoiceNumber('1234567890');
             $baseUrl = Url::base(true);
             $redirectUrls = new RedirectUrls();
             $redirectUrls->setReturnUrl($baseUrl . "/user/view?id=" . $user->id . "&r=ins")->setCancelUrl($baseUrl . "/race/pay?success=false&id=" . $id);
             $payment = new Payment();
             $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
             try {
                 $payment->create($apiContext);
             } catch (Exception $ex) {
                 print_r($ex);
                 exit(1);
             }
             $approvalUrl = $payment->getApprovalLink();
             /* --- */
         }
     } else {
         return $this->redirect(Yii::getAlias('@web') . '/site/login?ins=' . $id);
     }
     return $this->render('pay', ['race' => $race, 'aurl' => $approvalUrl]);
 }
开发者ID:frankpaul142,项目名称:aurasur,代码行数:57,代码来源:RaceController.php

示例11: createDetails

 private function createDetails(OrderInterface $order) : Details
 {
     $shippingCosts = $order->getModifier('shipping_cost');
     $details = new Details();
     $details->setShipping($shippingCosts->getNetAmount());
     $details->setTax($order->getSummary()->getTaxAmount());
     $details->setSubtotal($order->getProductTotal()->getNetPrice());
     return $details;
 }
开发者ID:WellCommerce,项目名称:PaymentBundle,代码行数:9,代码来源:PayPalGateway.php

示例12: get_link

 /**
  * Gets link for account payment
  *
  * @access public
  * @param array $settings
  * @return null
  */
 public static function get_link(array $settings)
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $data = self::get_data($settings['payment_type'], $settings['object_id']);
     $item = new Item();
     $item->setName($data['title'])->setDescription($data['description'])->setCurrency($data['currency_code'])->setQuantity(1)->setPrice($data['price']);
     $item_list = new ItemList();
     $item_list->setItems(array($item));
     $details = new Details();
     $details->setSubtotal($data['price']);
     $amount = new Amount();
     $amount->setCurrency($data['currency_code'])->setTotal($data['price'])->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription($data['description'])->setInvoiceNumber(uniqid());
     $redirectUrls = new RedirectUrls();
     $url = self::get_paypal_process_url(get_current_user_id(), $settings['payment_type'], $settings['object_id']);
     $redirectUrls->setReturnUrl($url)->setCancelUrl(plugins_url() . '/realestate/includes/paypal-payment.php?success=false&payment_type=' . $settings['payment_type'] . '&object_id=' . $settings['object_id'] . '&user_id=' . get_current_user_id());
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $api_context = self::get_paypal_context();
         $payment->create($api_context);
     } catch (Exception $ex) {
         var_dump($ex);
         die;
         return null;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             wp_redirect($link->getHref());
             exit;
         }
     }
     return null;
 }
开发者ID:jhonrsalcedo,项目名称:sitio,代码行数:43,代码来源:class-realia-paypal.php

示例13: setPaypalDetails

 public function setPaypalDetails($shipping, $tax, $subtotal)
 {
     $subtotal = number_format($subtotal, 2);
     $shipping = number_format($shipping, 2);
     $tax = number_format($tax, 2);
     $details = new Details();
     $details->setSubtotal($subtotal);
     $details->setShipping($shipping);
     $details->setTax($tax);
     return $details;
 }
开发者ID:cinghie,项目名称:yii2-paypal,代码行数:11,代码来源:Helper.php

示例14: teszt


//.........这里部分代码省略.........
     //     ->setExpireMonth("11")
     //     ->setExpireYear("2019")
     //     ->setCvv2("012")
     //     ->setFirstName("Joe")
     //     ->setLastName("Shopper");
     // try {
     //     $creditCard->create($apiContext);
     //     echo '<pre>';
     //     print_r($creditCard);
     // }
     // catch (\PayPal\Exception\PayPalConnectionException $ex) {
     //     echo $ex;
     // }
     //END SAMPLE 2
     //SAMPLE 3
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // ### Itemized information
     // (Optional) Lets you specify item wise
     // information
     $item1 = new Item();
     $item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setPrice(7.5);
     $item2 = new Item();
     $item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setPrice(2);
     $itemList = new ItemList();
     $itemList->setItems(array($item1, $item2));
     // ### Additional payment details
     // Use this optional field to set additional
     // payment information such as tax, shipping
     // charges etc.
     /* $details = new Details();
     $details->setShipping(1.2)
         ->setTax(1.3)
         ->setSubtotal(17.50); */
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     /* $amount = new Amount();
     $amount->setCurrency("USD")
         ->setTotal(20)
         ->setDetails($details); */
     // ### 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("Payment description");
     // ->setInvoiceNumber('134');
     //>setInvoiceNumber(uniqid());
     // ### Redirect urls
     // Set the urls that the buyer must be redirected to after
     // payment approval/ cancellation.
     //$baseUrl = getBaseUrl();
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/ordered")->setCancelUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/index");
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent set to 'sale'
     /* $payment = new Payment();
     $payment->setIntent("sale")
         ->setPayer($payer)
         ->setRedirectUrls($redirectUrls)
         ->setTransactions(array($transaction)); */
     $addr = new Address();
     $addr->setLine1('52 N Main ST');
开发者ID:nishanthpininti,项目名称:nishanth-work-nudostilo,代码行数:67,代码来源:paypal.php

示例15: postPayment


//.........这里部分代码省略.........
         } 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.');
 }
开发者ID:rebservoir,项目名称:retros,代码行数:101,代码来源:PaypalController.php


注:本文中的PayPal\Api\Details::setSubtotal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。