本文整理匯總了PHP中PayPal\Api\Payment::getApprovalLink方法的典型用法代碼示例。如果您正苦於以下問題:PHP Payment::getApprovalLink方法的具體用法?PHP Payment::getApprovalLink怎麽用?PHP Payment::getApprovalLink使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PayPal\Api\Payment
的用法示例。
在下文中一共展示了Payment::getApprovalLink方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateApprovalLink
/**
* Generate the approval link for a PayPal payment
* @param $amountToPay
* @return mixed
*/
public function generateApprovalLink($amountToPay)
{
$amountToPay = number_format($amountToPay, 2, ".", "");
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amount = new Amount();
$amount->setCurrency($this->currency)->setTotal($amountToPay);
$transaction = new Transaction();
$transaction->setAmount($amount)->setDescription(trans("billing.paymentToCompany", ['company_name' => Config::get("customer_portal.company_name")]))->setInvoiceNumber(uniqid(true));
//This is not a payment on a specific invoice, so we'll just generate a unique string, which is what PayPal requires
$tempToken = new PaypalTemporaryToken(['account_id' => get_user()->account_id, 'token' => uniqid(true)]);
$tempToken->save();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(action("PayPalController@completePayment", ['temporary_token' => $tempToken->token]))->setCancelUrl(action("PayPalController@cancelPayment", ['temporary_token' => $tempToken->token]));
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
$payment->create($this->apiContext);
return $payment->getApprovalLink();
}
示例2: CreateTransaction
function CreateTransaction($transactionType, $itemArray, $details)
{
$payer = new Payer();
$payer->setPaymentMethod($GLOBALS['PAYPAL']['payment_method']);
$itemList = new ItemList();
$itemList->setItems($itemArray);
$amount = new Amount();
$amount->setCurrency($GLOBALS['PAYPAL']['currency'])->setTotal(GetDetailsTotal($details))->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription($GLOBALS['TRANSACTION_TYPE']['DONATION']['payment_desc'])->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($GLOBALS['TRANSACTION_TYPE']['DONATION']['return_url'])->setCancelUrl($GLOBALS['TRANSACTION_TYPE']['DONATION']['cancel_url']);
$payment = new Payment();
$payment->setIntent($GLOBALS['TRANSACTION_TYPE']['DONATION']['intent'])->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($GLOBALS['PAYPAL']['api_context']);
} catch (Exception $ex) {
ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
return false;
}
$approvalUrl = $payment->getApprovalLink();
echo $approvalUrl;
return array('request' => $request, 'payment' => $payment, 'approvalUrl' => $approvalUrl);
}
示例3: startPayment
/**
* @return Payment
* @throws CheckoutException
*/
public function startPayment()
{
$total_amount = ($this->request->amount + $this->request->tax_amount - $this->request->discount_amount) * 100;
$apiContext->setConfig(array('service.EndPoint' => "https://test-api.sandbox.paypal.com"));
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item1 = new Item();
$item1->setName('Product1')->setCurrency('EUR')->setPrice(10.0)->setQuantity(2)->setTax(3.0);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
$amount = new Amount();
$amount->setCurrency('EUR')->setTotal(20)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment')->setInvoiceNumber('transactionid');
$baseUrl = getBaseUrl();
$redir = new RedirectUrls();
$redir->setReturnUrl($baseUrl . '/');
$redir->setCancelUrl($baseUrl . '/');
$payment = new Payment();
$payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redir)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (\Exception $e) {
throw new CheckoutException('Paypal error', 500, $e);
}
$approvalUrl = $payment->getApprovalLink();
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment);
return $payment;
}
示例4: init
/**
* @param PaymentInterface $payment
*/
public function init(PaymentInterface $payment)
{
$credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']);
$apiContext = new ApiContext($credentials);
$apiContext->setConfig(['mode' => $this->options['mode']]);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$amount = new Amount();
$amount->setCurrency($this->options['currency']);
$amount->setTotal($payment->getPaymentSum());
$item = new Item();
$item->setName($payment->getDescription());
$item->setCurrency($amount->getCurrency());
$item->setQuantity(1);
$item->setPrice($amount->getTotal());
$itemList = new ItemList();
$itemList->addItem($item);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($payment->getDescription());
$transaction->setItemList($itemList);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($payment->getExtraData('return_url'));
$redirectUrls->setCancelUrl($payment->getExtraData('cancel_url'));
$paypalPayment = new Payment();
$paypalPayment->setIntent('sale');
$paypalPayment->setPayer($payer);
$paypalPayment->setTransactions([$transaction]);
$paypalPayment->setRedirectUrls($redirectUrls);
$paypalPayment->create($apiContext);
$payment->setExtraData('paypal_payment_id', $paypalPayment->getId());
$payment->setExtraData('approval_link', $paypalPayment->getApprovalLink());
}
示例5: test
function test()
{
global $apiContext;
// IncludeConfig('paypal/bootstrap.php');
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$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));
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
$amount = new Amount();
$amount->setCurrency("USD")->setTotal(20)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("{$baseUrl}/donate.php/execute_payment_test?success=true")->setCancelUrl("{$baseUrl}/donate.php/execute_payment_test?success=false");
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
exit(1);
}
$approvalUrl = $payment->getApprovalLink();
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment);
return $payment;
}
示例6: getPayTaskUrl
public function getPayTaskUrl($task)
{
$apiContext = $this->apiContext;
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item1 = new Item();
$item1->setName($task->title)->setCurrency($this->currency)->setQuantity(1)->setSku($task->id)->setPrice($task->total);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$amount = new Amount();
$amount->setCurrency($this->currency)->setTotal($task->total);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment for " . $task->title)->setInvoiceNumber($task->id . '_' . date('YmdHis'));
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->redirectSuccess . '/' . $task->id)->setCancelUrl($this->redirectFail . '/' . $task->id);
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$payment->create($apiContext);
$this->storePaymentSession($payment->getId(), $task->id);
return $payment->getApprovalLink();
}
示例7: processPayment
/**
* {@inheritdoc}
*/
public function processPayment(PaymentInterface $payment) : PaymentInterface
{
$order = $payment->getOrder();
$payer = $this->createPayer('paypal');
$redirectUrls = $this->createRedirectUrls($payment);
$transaction = $this->createTransaction($order);
$payPalPayment = new Payment();
$payPalPayment->setIntent("sale");
$payPalPayment->setPayer($payer);
$payPalPayment->setRedirectUrls($redirectUrls);
$payPalPayment->setTransactions([$transaction]);
try {
$payPalPayment->create($apiContext);
} catch (\Exception $e) {
echo $e->getMessage();
}
$payment->setApprovalUrl($payPalPayment->getApprovalLink());
$payment->setState($payPalPayment->getState());
$payment->setToken($payPalPayment->getId());
$this->paymentManager->updateResource($payment);
return $payment;
}
示例8: onCharge
/**
* Called by shop to charge order's amount.
*
* @param Cart $cart Cart.
*
* @return bool
*/
public function onCharge($order)
{
$this->statusCode = 'pending';
// Begin paypal
try {
if ($order->total <= 0) {
$this->statusCode = 'completed';
$this->detail = 'Order total is 0; no PayPal transaction required.';
$this->transactionId = uniqid();
return true;
}
$this->setContext();
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$list = new ItemList();
$list->setItems($this->toPayPalItems($order));
$details = new Details();
$details->setShipping($order->totalShipping)->setTax($order->totalTax)->setSubtotal($order->totalPrice);
$amount = new Amount();
$amount->setCurrency(Config::get('shop.currency'))->setTotal($order->total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($list)->setDescription(sprintf('%s payment, Order #%d', Config::get('shop.name'), $order->id))->setInvoiceNumber($order->id);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->callbackSuccess)->setCancelUrl($this->callbackFail);
$payment = new Payment();
$payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
//$request = clone $payment;
$payment->create($this->apiContext);
$this->approvalUrl = $payment->getApprovalLink();
$this->detail = sprintf('Pending approval: %s', $this->approvalUrl);
return true;
} catch (PayPalConnectionException $e) {
$response = json_decode($e->getData());
throw new GatewayException(sprintf('%s: %s', $response->name, isset($response->message) ? $response->message : 'Paypal payment Failed.'), 1001, $e);
} catch (\Exception $e) {
throw new GatewayException($e->getMessage(), 1000, $e);
}
return false;
}
示例9: getRefillUrl
public function getRefillUrl($amount, User $user)
{
$paymentTitle = Config::get('services.paypal.payment_title');
$amount = floatval($amount);
$apiContext = $this->apiContext;
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item1 = new Item();
$item1->setName($paymentTitle)->setCurrency($this->currency)->setQuantity(1)->setSku('1')->setPrice($amount);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$amountObj = new Amount();
$amountObj->setCurrency($this->currency)->setTotal($amount);
$transaction = new Transaction();
$transaction->setAmount($amountObj)->setItemList($itemList)->setDescription($paymentTitle)->setInvoiceNumber($user->id . '_' . date('YmdHis'));
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->redirectSuccess . '/' . $user->id)->setCancelUrl($this->redirectFail . '/' . $user->id);
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$payment->create($apiContext);
$this->storePaymentSession($payment->getId(), $user->id, $amount, $this->currency, $itemList);
return $payment->getApprovalLink();
}
示例10: takePayment
/**
* @return mixed
*/
public function takePayment()
{
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$transaction = $this->buildTransaction();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->returnUrl)->setCancelUrl($this->cancelUrl);
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
try {
$payment->create($this->apiContext);
return $payment->getApprovalLink();
} catch (PayPalConnectionException $e) {
$response = json_decode($e->getData());
switch ($response->name) {
case 'VALIDATION_ERROR':
throw new Exception('Oops! ' . trans('vendirun::checkout.invalidPostcode'));
break;
default:
throw new Exception(trans('vendirun::checkout.paypalUnavailable'));
}
}
}
示例11: callCreate
public function callCreate($clientId, $clientSecret, $orderId, $amount, $currency, $description, $returnUrl, $cancelUrl)
{
$oauthCredential = new OAuthTokenCredential($clientId, $clientSecret);
$apiContext = new ApiContext($oauthCredential);
$apiContext->setConfig(['mode' => $this->mode]);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($description);
$item->setCurrency($currency);
$item->setPrice($amount);
$item->setQuantity(1);
$itemList = new ItemList();
$itemList->setItems(array($item));
$amountObject = new Amount();
$amountObject->setCurrency($currency);
$amountObject->setTotal($amount);
$transaction = new Transaction();
$transaction->setItemList($itemList);
$transaction->setAmount($amountObject);
$transaction->setDescription($description);
$transaction->setInvoiceNumber($orderId);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try {
$payment->create($apiContext);
} catch (\Exception $e) {
throw new PaymentException('PayPal Exception: ' . $e->getMessage());
}
$approvalUrl = $payment->getApprovalLink();
return $approvalUrl;
}
示例12: sendRequest
public function sendRequest()
{
$details = new Details();
$details->setShipping(0)->setTax(0)->setSubtotal($this->totalAmount);
$amount = new Amount();
$amount->setCurrency($this->currencyCode)->setTotal($this->totalAmount)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($this->itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
$baseUrl = 'http://localhost/';
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("{$baseUrl}/ExecutePayment.php?success=true")->setCancelUrl("{$baseUrl}/ExecutePayment.php?success=false");
$payment = new Payment();
$payment->setIntent("sale")->setPayer($this->payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
try {
$payment->create($this->apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
var_dump($ex);
exit(1);
}
$approvalUrl = $payment->getApprovalLink();
header('Location: ' . $approvalUrl);
quit();
}
示例13: createPayment
public function createPayment($amount, $description, $redirectUrl)
{
$apiContext = $this->getPayPal();
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amountObject = new Amount();
$amountObject->setCurrency("USD")->setTotal($amount);
$transaction = new Transaction();
$transaction->setAmount($amountObject)->setDescription($description);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($redirectUrl . "?success=true")->setCancelUrl($redirectUrl . "?success=false");
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$data = array("amount" => $amount, "description" => $description, "redirectUrl" => $redirectUrl, "method" => $this->paymentMethod, "metadata" => $this->metadata, "webhookUrl" => $this->webhook, "locale" => $this->locale);
$payment->create($apiContext);
$approvalUrl = $payment->getApprovalLink();
return (object) array('id' => $payment->getId(), 'url' => $approvalUrl, 'provider' => 'paypal');
}
示例14: actionPay
public function actionPay()
{
$return = [];
$total = 0;
if (isset(Yii::$app->user->id)) {
$cart = Cart::findOne(['user_id' => Yii::$app->user->id, 'status' => 'CREATED']);
if ($cart) {
$items = [];
foreach ($cart->productscarts as $k => $productCart) {
$aux = [];
$aux['name'] = $productCart->product->name;
$aux['quantity'] = $productCart->quantity;
$aux['stock'] = $productCart->product->stock;
$aux['price'] = $productCart->product->price;
$aux['image'] = $productCart->product->image1;
$aux['total'] = $productCart->product->price * $productCart->quantity;
$aux['won'] = $productCart->won;
$return[$productCart->product->id] = $aux;
$total += $productCart->product->price * $productCart->quantity;
$item = new Item();
$item->setName($aux['name'])->setCurrency('USD')->setQuantity($aux['quantity'])->setPrice($aux['price']);
$items[] = $item;
}
/* paypal */
$clientId = 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS';
$clientSecret = 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL';
$apiContext = $this->getApiContext($clientId, $clientSecret);
$payer = new Payer();
$payer->setPaymentMethod("paypal");
/*$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($items);
$details = new Details();
$details->setShipping(5)->setSubtotal($total);
$amount = new Amount();
$amount->setCurrency("USD")->setTotal($total + 5)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Compra en Mosaico")->setInvoiceNumber('1234567890');
$baseUrl = Url::base(true);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("{$baseUrl}/site/pay?success=true")->setCancelUrl("{$baseUrl}/site/pay?success=false");
$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->render('pay', ['total' => $total, 'cart' => $return, 'aurl' => $approvalUrl]);
}
示例15: pay
public function pay(array $items = null, $invoiceNo = null)
{
if (!isset($invoiceNo)) {
$invoiceNo = uniqid();
}
if (isset($items) && !empty($items)) {
$baseUrl = SYMPHONY_URL . '/extension/paypal/payment';
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$itemList = new ItemList();
$subTotal = 0;
$taxTotal = 0;
$shipping = 0;
foreach ($items as $key => $itemDetails) {
$subTotal += $itemDetails['price'];
if (isset($itemDetails['tax'])) {
$taxTotal += $itemDetails['tax'];
}
$itemList->addItem($this->paypalItemFromArray($itemDetails));
}
$details = new Details();
$details->setShipping($shipping)->setTax($taxTotal)->setSubtotal($subTotal);
$amount = new Amount();
$amount->setCurrency($this->currency)->setTotal($subTotal + $taxTotal)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("JCI Malta Membership")->setInvoiceNumber($invoiceNo);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("{$baseUrl}?success=true")->setCancelUrl("{$baseUrl}?success=false");
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($this->apiContext);
} catch (Exception $ex) {
var_dump($request);
var_dump($ex);
die;
return "error";
//log the error
// echo("Error Creating Payment Using PayPal.", "Payment", null, $request, $ex);
// exit(1);
}
$return = array('id' => $payment->getId(), 'link' => $payment->getApprovalLink());
return $return;
}
}