本文整理汇总了PHP中PayPal\Api\PaymentExecution::addTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP PaymentExecution::addTransaction方法的具体用法?PHP PaymentExecution::addTransaction怎么用?PHP PaymentExecution::addTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\PaymentExecution
的用法示例。
在下文中一共展示了PaymentExecution::addTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* 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);
}
}
示例2: confirmPayment
/**
* @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);
}
示例3: PaymentExecution
$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
示例4: 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);
}
}