addTransaction() public méthode

Append Transactions to the list.
public addTransaction ( Transaction $transaction )
$transaction Transaction
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('ATGFkB2ea6f0pM92jwBqkZ17kxsiftDvUhLHyXson-10AUs7n5TocpEc0sis7Cl_fMIxS8uQO04kPP8Q', 'ENP_JPkc3e4Yl6VeHZ_0vgvEh0SYdtzkMvw_VGBrr2nJ67sg9RuKB_YF7y_k4bj-4t2U-_23MaAGV3vD'));
     $status = '';
     if (isset($_GET['success']) && $_GET['success'] == 'true') {
         $transaction = new Transaction();
         $amount = new Amount();
         $paymentId = $_GET['paymentId'];
         $payment = Payment::get($paymentId, $apiContext);
         $amount->setCurrency($payment->transactions[0]->amount->getCurrency());
         $amount->setTotal($payment->transactions[0]->amount->getTotal());
         $amount->setDetails($payment->transactions[0]->amount->getDetails());
         $transaction->setAmount($amount);
         $execution = new PaymentExecution();
         $execution->setPayerId($_GET['PayerID']);
         $execution->addTransaction($transaction);
         $rifas = $payment->transactions[0]->description;
         $rifas = explode(',', $rifas);
         $aux = 0;
         try {
             foreach ($rifas as $rifa) {
                 $aux = Rifa::find($rifa);
                 if ($aux->user_id == NULL) {
                     $aux->user_id = Auth::user()->id;
                     $aux->save();
                 } else {
                     $status = 'Numeros de rifas ja foram escolhidos por outra pessoa, por favor escolha novamente.';
                     return view('confirmacao')->with('status', $status);
                 }
             }
             $result = $payment->execute($execution, $apiContext);
             try {
                 $payment = Payment::get($paymentId, $apiContext);
             } catch (Exception $ex) {
                 $status = 'Pagamento ainda sem confirmacao';
             }
         } catch (Exception $ex) {
             $status = 'Compra nao foi executada';
         }
         if ($result->state == "approved") {
             $status = 'Compra feita com sucesso!';
             $aux = 1;
         }
         return view('confirmacao')->with('status', $status)->with('aux', $aux);
     } else {
         $status = 'Compra cancelada pelo usuario';
         return view('confirmacao')->with('status', $status);
     }
 }
 /**
  * @param array $params
  * @return bool
  */
 public function confirmPayment($params = [])
 {
     $payment = Payment::get($params['paymentId'], $this->apiContext);
     $execution = new PaymentExecution();
     $execution->setPayerId($params['PayerID']);
     $transaction = $this->buildTransaction();
     try {
         $execution->addTransaction($transaction);
         $payment->execute($execution, $this->apiContext);
     } catch (PayPalConnectionException $e) {
         throw new Exception(trans('vendirun::checkout.paypalUnavailable'));
     }
     $vendirunPayment = new VendirunPayment($this->order->getTotalPrice(), date("Y-m-d"), 'paypal', json_encode($payment));
     $this->order->addPayment($vendirunPayment);
     return $this->orderRepository->save($this->order);
 }
 $execution = new PaymentExecution();
 $execution->setPayerId($_GET['PayerID']);
 // ### Optional Changes to Amount
 // If you wish to update the amount that you wish to charge the customer,
 // based on the shipping address or any other reason, you could
 // do that by passing the transaction object with just `amount` field in it.
 // Here is the example on how we changed the shipping to $1 more than before.
 $transaction = new Transaction();
 $amount = new Amount();
 $details = new Details();
 $amount->setCurrency('USD');
 $amount->setTotal($payment->getTransactions()[0]->amount->total);
 $amount->setDetails($details);
 $transaction->setAmount($amount);
 // Add the above transaction object inside our Execution object.
 $execution->addTransaction($transaction);
 try {
     // Execute the payment
     // (See bootstrap.php for more on `ApiContext`)
     $result = $payment->execute($execution, $apiContext);
     // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
     //        ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result);
     try {
         $payment = Payment::get($paymentId, $apiContext);
     } catch (Exception $ex) {
         // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
         // 	        ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
         exit(1);
     }
 } catch (Exception $ex) {
     // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
Exemple #4
0
 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);
     }
 }