コード例 #1
0
 public function postCheckout()
 {
     $payer = PayPal::Payer();
     $payer->setPaymentMethod('paypal');
     $amount = PayPal::Amount();
     $amount->setCurrency('USD');
     $amount->setTotal(intval(\Cart::getTotal()) / 20);
     // This is the simple way,
     // you can alternatively describe everything in the order separately;
     // Reference the PayPal PHP REST SDK for details.
     $transaction = PayPal::Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription('Thanh Toán Mua Hàng Từ Couponia?');
     $redirectUrls = PayPal::RedirectUrls();
     $redirectUrls->setReturnUrl(\Redirect::getUrlGenerator()->route('paypal-done'));
     $redirectUrls->setCancelUrl(\Redirect::getUrlGenerator()->route('paypal'));
     $payment = PayPal::Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $response = $payment->create($this->_apiContext);
     $redirectUrl = $response->links[1]->href;
     return \Redirect::to($redirectUrl);
 }
コード例 #2
0
 /**
  * Payments
  */
 public function checkout()
 {
     $ids = session('likes', []);
     $total = 0;
     foreach ($ids as $id) {
         $movie = Movies::find($id);
         $total = $total + $movie->price;
     }
     $payer = PayPal::Payer();
     $payer->setPaymentMethod('paypal');
     $amount = PayPal::Amount();
     $amount->setCurrency('EUR');
     $amount->setTotal($total);
     $transaction = PayPal::Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription("Récapitulatif total des " . count($ids) . " films commandés");
     $redirectUrls = PayPal::RedirectUrls();
     $redirectUrls->setReturnUrl(route('cart_done'));
     $redirectUrls->setCancelUrl(route('cart_cancel'));
     $payment = PayPal::Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     //response de Paypal
     $response = $payment->create($this->_apiContext);
     $redirectUrl = $response->links[1]->href;
     //redirect to Plateform Paypal
     return Redirect::to($redirectUrl);
 }
コード例 #3
0
ファイル: paypalController.php プロジェクト: aaffio/guide
 public function getCheckout()
 {
     $payer = PayPal::Payer();
     $payer->setPaymentMethod('paypal');
     $amount = PayPal::Amount();
     $amount->setCurrency('EUR');
     $amount->setTotal(42);
     // This is the simple way,
     // you can alternatively describe everything in the order separately;
     // Reference the PayPal PHP REST SDK for details.
     $transaction = PayPal::Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription('What are you selling?');
     $redirectUrls = PayPal::RedirectUrls();
     $redirectUrls->setReturnUrl(action('PayPalController@getDone'));
     $redirectUrls->setCancelUrl(action('PayPalController@getCancel'));
     $payment = PayPal::Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $response = $payment->create($this->_apiContext);
     $redirectUrl = $response->links[1]->href;
     return Redirect::to($redirectUrl);
 }
コード例 #4
0
 public function postProcessPayment()
 {
     $index = \Input::get('value');
     $user = \Input::get('user');
     if ($user !== 'company' && $user !== 'agency') {
         return \Response::json(['type' => 'danger', 'message' => 'User not recognized']);
     }
     if (!array_key_exists($index, $this->paymentType)) {
         return \Response::json(['type' => 'danger', 'message' => 'Payment not recognized']);
     }
     $paymentData = $this->paymentType[$index];
     if ($index === '2') {
         $xAmount = \Input::get('amount');
         if ($xAmount <= 0) {
             return \Response::json(['type' => 'danger', 'message' => 'Minimum of amount of credit to be bought is 1.']);
         }
         $paymentData['name'] = $xAmount . ' company credit(s) on Programme Chameleon.';
         $paymentData['xCreditAmount'] = $xAmount;
         $paymentData['successMessage'] .= $xAmount . ' credit(s)';
     }
     session(['_temp_payment_sess' => $paymentData]);
     $total = isset($xAmount) ? $xAmount * $paymentData['amount'] : $paymentData['amount'];
     try {
         $payer = PayPal::Payer();
         $payer->setPaymentMethod('paypal');
         $amount = PayPal::Amount();
         $amount->setCurrency('GBP');
         $amount->setTotal($total + 0.2 * $total);
         $item = PayPal::Item();
         $item->setName($paymentData['name'])->setDescription($paymentData['description'])->setCurrency('GBP')->setQuantity(isset($xAmount) ? $xAmount : 1)->setTax(0)->setPrice($paymentData['amount']);
         $tax = PayPal::Item();
         $tax->setName('VAT TAX')->setDescription('20% VAT Tax')->setCurrency('GBP')->setQuantity(1)->setTax(0)->setPrice(0.2 * $total);
         $itemList = PayPal::ItemList();
         $itemList->setItems([$item, $tax]);
         $transaction = PayPal::Transaction();
         $transaction->setAmount($amount);
         $transaction->setItemList($itemList);
         $transaction->setDescription('Transaction for programmechameleon.com website.');
         $redirectUrls = PayPal::RedirectUrls();
         if ($user === 'company') {
             $redirectUrls->setReturnUrl(action('PaymentController@getCompanyPaymentDone'));
             $redirectUrls->setCancelUrl(action('PaymentController@getCompanyPaymentCancel'));
         } else {
             if ($user === 'agency') {
                 $redirectUrls->setReturnUrl(action('PaymentController@getAgencyPaymentDone'));
                 $redirectUrls->setCancelUrl(action('PaymentController@getAgencyPaymentCancel'));
             }
         }
         $payment = PayPal::Payment();
         $payment->setIntent('sale');
         $payment->setPayer($payer);
         $payment->setRedirectUrls($redirectUrls);
         $payment->setTransactions(array($transaction));
         $response = $payment->create($this->paypalApiContext);
         $redirectUrl = $response->links[1]->href;
         return \Response::json(['type' => 'success', 'message' => 'Paypal init success', 'redirect' => $redirectUrl]);
     } catch (\Exception $e) {
         return \Response::json(['type' => 'danger', 'message' => $e->getMessage()]);
     }
 }