本文整理汇总了PHP中PayPal\Api\PaymentExecution::setPayerId方法的典型用法代码示例。如果您正苦于以下问题:PHP PaymentExecution::setPayerId方法的具体用法?PHP PaymentExecution::setPayerId怎么用?PHP PaymentExecution::setPayerId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\PaymentExecution
的用法示例。
在下文中一共展示了PaymentExecution::setPayerId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: ExecutePayment
public function ExecutePayment($paymentId = 0, $payerId = 0)
{
$apiContext = $this->getApiContext();
try {
$payment = Payment::get($paymentId, $apiContext);
} catch (Exception $ex) {
$this->error = $ex->getMessage();
return false;
}
$dataP = json_decode($payment->toJSON());
if ($dataP->payer->payer_info->payer_id != $payerId) {
$this->error = 'Los datos son inválidos';
return false;
}
if ($dataP->state == 'approved') {
$this->error = 'El pedido ya fue pagado';
return false;
}
if (!$dataP->state == 'created') {
$this->error = 'El pedido no ya fue aprobado';
return false;
}
try {
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayerId($payerId);
$payment = $payment->execute($paymentExecution, $apiContext);
} catch (Exception $ex) {
$this->error = $ex->getMessage();
return false;
}
return $payment->toJSON();
}
示例3: executePayment
/**
* Completes the payment once buyer approval has been
* obtained. Used only when the payment method is 'paypal'
*
* */
public function executePayment($paymentId, $payerId)
{
$payment = $this->getPaymentDetails($paymentId);
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayerId($payerId);
$payment = $payment->execute($paymentExecution, $this->apiContext);
return $payment;
}
示例4: executePayPalPayment
public static function executePayPalPayment($paymentId, $payerId)
{
$apiContext = self::getApiContext();
$payment = Payment::get($paymentId, $apiContext);
// ### Payment Execute
// PaymentExecution object includes information necessary
// to execute a PayPal account payment.
// The payer_id is added to the request query parameters
// when the user is redirected from paypal back to your site
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
return $payment->execute($execution, $apiContext);
}
示例5: 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);
}
}
示例6: 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);
}
示例7: paymentStatus
public function paymentStatus()
{
$payment_id = Session::get('paypal_payment_id');
Session::forget('paypal_payment_id');
if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
return "Operation failed";
}
$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId(Input::get('PayerID'));
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {
return 'Payment was successfull , we Thank you for that';
} else {
return "Operation failed";
}
}
示例8: execute
/**
* {@inheritDoc}
*/
public function execute($request)
{
/** @var $request Capture */
RequestNotSupportedException::assertSupports($this, $request);
$details = ArrayObject::ensureArrayObject($request->getModel());
$payment = new Payment();
$payer = new Payer();
$payer->payment_method = "paypal";
$amount = new Amount();
$amount->currency = $details['PAYMENTREQUEST_CURRENCYCODE'];
$amount->total = $details['PAYMENTREQUEST_AMT'];
$transaction = new Transaction();
$transaction->amount = $amount;
$transaction->description = $details['PAYMENTREQUEST_DESCRIPTION'];
$redirectUrls = new RedirectUrls();
$redirectUrls->return_url = $details['RETURN_URL'];
$redirectUrls->cancel_url = $details['CANCEL_URL'];
$payment->intent = "sale";
$payment->payer = $payer;
$payment->redirect_urls = $redirectUrls;
$payment->transactions = [$transaction];
if (false == isset($details['response']) && false == isset($details['response']['state']) && isset($payment->payer->payment_method) && 'paypal' == $payment->payer->payment_method) {
$paymentResponse = $payment->create($this->api);
$details['response'] = $paymentResponse->toArray();
foreach ($paymentResponse->links as $link) {
if ($link->rel == 'approval_url') {
throw new HttpRedirect($link->href);
}
}
}
if (false == isset($details['response']) && false == isset($details['response']['state']) && isset($payment->payer->payment_method) && 'credit_card' == $payment->payer->payment_method) {
$paymentResponse = $payment->create($this->api);
$details['response'] = $paymentResponse->toArray();
}
$this->gateway->execute(new Sync($details));
if (true == isset($details['response']) && true == isset($details['response']['state']) && true == isset($details['response']['id']) && isset($payment->payer->payment_method) && 'paypal' == $payment->payer->payment_method && true == isset($details['PayerID'])) {
$payment->setId($details['response']['id']);
$execution = new PaymentExecution();
$execution->setPayerId($details['PayerID']);
//Execute the payment
$paymentResponse = $payment->execute($execution, $this->api);
$details['response'] = $paymentResponse->toArray();
}
}
示例9: callExecute
public function callExecute($clientId, $clientSecret, $paymentId, $payerId, $amount, $currency)
{
$oauthCredential = new OAuthTokenCredential($clientId, $clientSecret);
$apiContext = new ApiContext($oauthCredential);
$apiContext->setConfig(['mode' => $this->mode]);
$payment = Payment::get($paymentId, $apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
$result = $payment->execute($execution, $apiContext);
try {
$payment = Payment::get($paymentId, $apiContext);
} catch (\Exception $e) {
throw new PaymentException('unable to find payment: ' . $e->getMessage());
}
if ($payment->state == 'approved') {
return true;
}
return false;
}
示例10: successPay
public function successPay(Request $request)
{
// send emails.
if (Auth::check()) {
// Get the payment ID before session clear
$paypal_data = Session::get("paypal_data");
Session::forget("paypal_data");
$payment_id = $paypal_data['paypal_payment_id'];
$order_data = ["msg" => "Error: Payment Failed", "result" => "error"];
if (empty($request->get("PayerID")) || empty($request->get("token"))) {
return redirect('/fabrics')->with('order_data', $order_data);
}
$payment = Payment::get($payment_id, $paypal_data["paypal_context"]);
$execution = new PaymentExecution();
$execution->setPayerId($request->get("PayerID"));
//Execute the payment
$result = $payment->execute($execution, $paypal_data["paypal_context"]);
if ($result->getState() == 'approved') {
// payment made
$user = Auth::user();
$dataMail = $paypal_data["data_mail"];
Mail::send("email.email-sample", ["data" => $dataMail], function ($mail) use($user) {
//$mail->to("jj@dnim-inc.com","JJ")->cc("jsanchez@dnim-inc.com" , "Javier")->cc("oreyes@dnim-inc.com" ,"Oswaldo")->subject("New Sample Request");
$mail->to("dnimincemail@gmail.com", "DNIM")->subject("New Order");
});
Mail::send("email.email-sample", ["data" => $dataMail], function ($mail) use($user) {
$mail->to($user->email, $user->name)->subject("New Order Created");
//$mail->to("dnimincemail@gmail.com","DNIM")->subject("New Order");
});
$paypal_data["fabric"]->save();
$paypal_data["order"]->save();
$order_data = ["msg" => "Success: Order created successfully", "result" => "success"];
return redirect("/fabrics")->with("order_data", $order_data);
} else {
$order_data = ["msg" => "Error: Payment not approved", "result" => "error"];
return redirect("/fabrics")->with("order_data", $order_data);
}
} else {
return redirect("/");
}
}
示例11: completePayment
/**
* Complete the PayPal payment
* @param Request $request
* @param $temporaryToken
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function completePayment(Request $request, $temporaryToken)
{
$token = PaypalTemporaryToken::where('token', '=', $temporaryToken)->where('account_id', '=', get_user()->account_id)->first();
if ($token === null) {
$error = trans("errors.paypalTokenInvalid");
return view("pages.paypal.error", compact('error'));
}
$token->delete();
if ($request->input('paymentId') === null || $request->input('PayerID') === null) {
$error = trans("errors.missingPaypalInformation");
return view("pages.paypal.error", compact('error'));
}
$payment = Payment::get($request->input('paymentId'), $this->apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($request->input('PayerID'));
try {
$payment->execute($execution, $this->apiContext);
$payment = Payment::get($request->input('paymentId'), $this->apiContext);
} catch (Exception $e) {
$error = trans("errors.paypalGenericError");
return view("pages.paypal.error", compact('error'));
}
if (strtolower($payment->getState() != 'approved')) {
$error = trans("errors.paymentNotApproved");
return view("pages.paypal.error", compact('error'));
}
//POST the payment back into Sonar for storage
try {
$accountBillingController = new AccountBillingController();
$transaction = $payment->getTransactions()[0];
$accountBillingController->storePayPalPayment(get_user()->account_id, $transaction->related_resources[0]->sale->amount->total, $transaction->related_resources[0]->sale->id);
} catch (Exception $e) {
$error = trans("errors.failedToApplyPaypalPayment");
return view("pages.paypal.error", compact('error'));
}
$billingController = new BillingController();
$billingController->clearBillingCache();
return view("pages.paypal.success");
}
示例12: getPaymentStatus
public function getPaymentStatus()
{
// Get the payment ID before session clear
$payment_id = \Session::get('paypal_payment_id');
// clear the session payment ID
\Session::forget('paypal_payment_id');
$payerId = \Input::get('PayerID');
$token = \Input::get('token');
if (empty($payerId) || empty($token)) {
return \Redirect::route('home')->with('message', 'Hubo un problema al intentar pagar con Paypal');
}
$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId(\Input::get('PayerID'));
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {
$this->saveOrder();
\Session::forget('cart');
return \Redirect::route('home')->with('message', 'Compra realizada de forma correcta');
}
return \Redirect::route('home')->with('message', 'La compra fue cancelada');
}
示例13: execute_payment_test
function execute_payment_test()
{
$apiContext = $GLOBALS['PAYPAL']['api_context'];
// ### Approval Status
// Determine if the user approved the payment or not
if (isset($_GET['success']) && $_GET['success'] == 'true') {
// Get the payment Object by passing paymentId
// payment id was previously stored in session in
// CreatePaymentUsingPayPal.php
$paymentId = $_GET['paymentId'];
$payment = Payment::get($paymentId, $apiContext);
// ### Payment Execute
// PaymentExecution object includes information necessary
// to execute a PayPal account payment.
// The payer_id is added to the request query parameters
// when the user is redirected from paypal back to your site
$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();
// $details->setShipping(2.2)
// ->setTax(1.3)
// ->setSubtotal(17.50);
// $amount->setCurrency('USD');
// $amount->setTotal(21);
// $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
ResultPrinter::printError("Executed Payment", "Payment", null, null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment);
return $payment;
} else {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("User Cancelled the Approval", null);
exit;
}
}
示例14: getPaymentStatus
public function getPaymentStatus()
{
// Get the payment ID before session clear
$payment_id = Session::get('paypal_payment_id');
//echo '<pre>';print_r($payment_id);echo '</pre>';exit;
// clear the session payment ID
Session::forget('paypal_payment_id');
//echo '<pre>';print_r(1);echo '</pre>';exit;
if (!Input::get('PayerID') || !Input::get('token')) {
return Redirect::to('padrinos/list_registrar_pagos')->with('error', 'El pago no se realizó correctamente');
}
//echo '<pre>';print_r($this->_api_context);echo '</pre>';exit;
$payment = Payment::get($payment_id, $this->_api_context);
// PaymentExecution object includes information necessary
// to execute a PayPal account payment.
// The payer_id is added to the request query parameters
// when the user is redirected from paypal back to your site
$execution = new PaymentExecution();
$execution->setPayerId(Input::get('PayerID'));
//Execute the payment
$result = $payment->execute($execution, $this->_api_context);
//echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later
if ($result->getState() == 'approved') {
// payment made
$idpago = Session::get('idcalendario_pago');
//echo '<pre>';print_r($idpago);echo '</pre>';exit;
$pago = CalendarioPago::find($idpago);
$pago->fecha_pago = date("Y-m-d");
$pago->banco = "PayPal";
$pago->aprobacion = 1;
$pago->save();
return Redirect::to('padrinos/list_registrar_pagos')->with('message', 'El pago se realizó correctamente');
}
return Redirect::to('padrinos/list_registrar_pagos')->with('error', 'El pago no se realizó correctamente');
}
示例15: PaymentExecution
<?php
require 'app/start.php';
use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
if (!isset($_GET['success'], $_GET['paymentId'], $_GET['PayerID'])) {
die;
}
if ((bool) $_GET['success'] === 'false') {
echo 'Transaction cancelled';
die;
}
$paymentID = $_GET['paymentId'];
$payerId = $_GET['PayerID'];
$payment = Payment::get($paymentID, $paypal);
$execute = new PaymentExecution();
$execute->setPayerId($payerId);
try {
$result = $payment->execute($execute, $paypal);
} catch (Exception $e) {
die($e);
}
echo 'Pay success!';