本文整理汇总了PHP中PayPal\Api\RedirectUrls::setCancelUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP RedirectUrls::setCancelUrl方法的具体用法?PHP RedirectUrls::setCancelUrl怎么用?PHP RedirectUrls::setCancelUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\RedirectUrls
的用法示例。
在下文中一共展示了RedirectUrls::setCancelUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: testInvalidRedirectUrls
/**
* @dataProvider invalidRedirectUrlsProvider
*/
public function testInvalidRedirectUrls($return_url, $cancel_url)
{
$redirectUrls = new RedirectUrls();
$this->setExpectedException('\\InvalidArgumentException');
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
}
示例3: makePaymentUsingPayPal
public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl)
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
// specify the payment ammount
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($total);
// ###Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($paymentDesc);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl . '&success=true');
$redirectUrls->setCancelUrl($returnUrl . '&success=false');
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
try {
$payment->create($this->apiContext);
} catch (Exception $e) {
throw new Exception($e);
}
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: createNewPayment
public static function createNewPayment()
{
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
return $payment;
}
示例6: get_payment_url
/**
* When you have configured the payment properly this will give you a URL that you can redirect your visitor to,
* so that he can pay the desired amount.
*
* @param string $url_format
* @return string
*/
public function get_payment_url($url_format)
{
if (!is_array($this->payment_provider_auth_config[self::PROVIDER_NAME]) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid']) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['secret'])) {
throw new \Exception('Auth Config for Provider ' . self::PROVIDER_NAME . ' is not set.', 1394795187);
}
$total_price = $this->order->get_total_price();
if ($total_price == 0) {
throw new \Exception('Total price is 0. Provider ' . self::PROVIDER_NAME . ' does not support free payments.', 1394795478);
}
$api_context = new ApiContext(new OAuthTokenCredential($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid'], $this->payment_provider_auth_config[self::PROVIDER_NAME]['secret']));
$api_context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => false));
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amount = new Amount();
$amount->setCurrency("EUR");
$amount->setTotal($this->order->get_total_price());
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($this->order->get_reason());
$transaction->setItemList($this->getItemList());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->get_success_url($url_format));
$redirectUrls->setCancelUrl($this->get_abort_url($url_format));
$payment = new \PayPal\Api\Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$payment->create($api_context);
$payment_url = '';
foreach ($payment->getLinks() as $link) {
/** @var \PayPal\Api\Links $link */
if ($link->getRel() == 'approval_url') {
$payment_url = $link->getHref();
}
}
return $payment_url;
}
示例7: process
public function process($orderData, $cartProducts = [])
{
$this->setApiContext();
$this->_apiContext->setConfig(['mode' => Configuration::getConfiguration('paypal_payment_mode'), 'service.EndPoint' => Configuration::getConfiguration('paypal_payment_url'), 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => Configuration::getConfiguration('paypal_payment_log'), 'log.FileName' => storage_path('logs/paypal.log'), 'log.LogLevel' => 'FINE']);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$itemList = new ItemList();
$subTotal = 0;
$taxTotal = 0;
foreach ($cartProducts as $product) {
$item = new Item();
$model = $product['model'];
$item->setName($model->title)->setCurrency('USD')->setQuantity($product['qty'])->setSku($model->sku)->setPrice($product['price']);
$itemList->addItem($item);
$subTotal += $product['price'] * $product['qty'];
$taxTotal += $product['tax_amount'] * $product['qty'];
}
$total = $subTotal + $taxTotal;
$shippingOption = $orderData['shipping_method'];
$shipping = Shipping::get($shippingOption);
$details = new Details();
$details->setShipping($shipping->getAmount())->setTax($taxTotal)->setSubtotal($subTotal);
$amount = new Amount();
$amount->setCurrency('USD')->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment description')->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(route('paypal.store'));
$redirectUrls->setCancelUrl(route('paypal.cancel'));
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions([$transaction]);
$response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href;
return $redirectUrl;
}
示例8: testUrlValidationForCancelUrl
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage CancelUrl is not a fully qualified URL
*/
public function testUrlValidationForCancelUrl()
{
$obj = new RedirectUrls();
$obj->setCancelUrl(null);
}
示例9: createRedirectUrls
/**
* Creates a collection of PayPal url definitions
*
* @return RedirectUrls
*/
protected function createRedirectUrls(PaymentInterface $payment) : RedirectUrls
{
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->getConfirmUrl($payment));
$redirectUrls->setCancelUrl($this->getCancelUrl($payment));
return $redirectUrls;
}
示例10: store
public function store(Request $request)
{
//stores a new order for confirmation
$result = false;
$msg = "";
$info = $request->all();
//return dd($request->all());
//return var_dump( $info );
if (Auth::check()) {
if (User::profileComplete(Auth::user())) {
$paypal_conf = config('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
$fabric = Fabric::find($info["fabric"]);
$user = Auth::user();
$order = new Order();
if ($fabric->stock >= $info["totalAmount"] && $info["totalAmount"] > 0) {
//create new order with from the given data.
$order->user_id = $user->id;
$order->fabric_id = $fabric->id;
$order->fabric_name = $fabric->name;
$order->amount = $info["totalAmount"];
$weight = $info["totalAmount"] / 5 * (2.5 * 1.2);
$order->shipping = $weight;
$order->type_sample = $info["type-sample"];
$order->carrier = $info["carrier"];
$order->sub_total = $fabric->priceYard * $info["totalAmount"];
$order->total = $order->sub_total + $order->shipping;
$order->status = "not-confirmed";
$fabric->stock -= $order->amount;
$result = true;
$dataMail["subTotal"] = $order->sub_total;
$dataMail["shipping"] = $order->shipping;
$dataMail["carrier"] = $order->carrier;
$dataMail["type-sample"] = $order->type_sample;
$dataMail["total"] = $order->total;
$dataMail["fabric-name"] = $fabric->name;
$dataMail["name"] = $user->name;
$dataMail["city"] = $user->city;
$dataMail["country"] = $user->country;
$dataMail["zp"] = $user->zp_code;
$dataMail["address"] = $user->address;
$dataMail["email"] = $user->email;
$dataMail["totalAmount"] = $order->amount;
// paypal logic starts here
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($order->fabric_name . $order->created_at);
$item->setCurrency('USD');
$item->setQuantity($order->amount);
$item->setPrice($fabric->priceYard);
$itemCarrier = new Item();
$itemCarrier->setName("Shipping Price");
$itemCarrier->setCurrency('USD');
$itemCarrier->setQuantity(1);
$itemCarrier->setPrice($weight);
// add item to list
$item_list = new ItemList();
$item_list->setItems([$itemCarrier, $item]);
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal($order->sub_total + $weight);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($item_list);
$transaction->setDescription('New Fabric Order');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(url('successPay/orders'));
$redirect_urls->setCancelUrl(url("cancelPay/orders"));
$payment = new Payment();
$payment->setIntent('Sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirect_urls);
$payment->setTransactions(array($transaction));
try {
PPHttpConfig::$DEFAULT_CURL_OPTS[CURLOPT_SSLVERSION] = 4;
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
if (config('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
echo '<pre>';
print_r(json_decode($pce->getData()));
exit;
exit;
} else {
die('Some error occur, sorry for inconvenient');
}
}
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
$paypal_data = ['paypal_payment_id' => $payment->getId(), "fabric" => $fabric, "order" => $order, "data_mail" => $dataMail, "paypal_context" => $this->_api_context];
Session::put("paypal_data", $paypal_data);
$order_data = ["msg" => "Error: could not connect to paypal", "result" => false];
//.........这里部分代码省略.........
示例11: makePaymentUsingPayPal
/**
* Create a payment using the buyer's paypal
* account as the funding instrument. Your app
* will have to redirect the buyer to the paypal
* website, obtain their consent to the payment
* and subsequently execute the payment using
* the execute API call.
*
* @param string $total payment amount in DDD.DD format
* @param string $currency 3 letter ISO currency code such as 'USD'
* @param string $paymentDesc A description about the payment
* @param string $returnUrl The url to which the buyer must be redirected
* to on successful completion of payment
* @param string $cancelUrl The url to which the buyer must be redirected
* to if the payment is cancelled
* @return \PayPal\Api\Payment
*/
function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl)
{
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// Specify the payment amount.
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($total);
// ###Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$item = new Item();
$item->setQuantity(1);
$item->setName($paymentDesc);
$item->setPrice($total);
$item->setCurrency("USD");
$itemList = new ItemList();
$itemList->setItems(array($item));
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemList);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl);
$redirectUrls->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->create($this->getApiContext());
return $payment;
}
示例12: payPaypal
/**
* Runs a payment with PayPal
*
* @link https://devtools-paypal.com/guide/pay_paypal/php?interactive=ON&env=sandbox
* @return PayPal\Api\Payment
*/
public function payPaypal($urls = [], $sum = 0, $message = '')
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$amount = new Amount();
$amount->setCurrency($this->currency);
$amount->setTotal($sum);
$transaction = new Transaction();
if ($message) {
$transaction->setDescription($message);
}
$transaction->setAmount($amount);
$redirectUrls = new RedirectUrls();
$return_url = isset($urls['return_url']) ? $urls['return_url'] : 'https://devtools-paypal.com/guide/pay_paypal/php?success=true';
$cancel_url = isset($urls['cancel_url']) ? $urls['cancel_url'] : 'https://devtools-paypal.com/guide/pay_paypal/php?success=true';
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions([$transaction]);
return $payment->create($this->_apiContext);
// get approval url from this json
}
示例13: makePaymentUsingPayPal
/**
* Create a payment using the buyer's paypal
* account as the funding instrument. Your app
* will have to redirect the buyer to the paypal
* website, obtain their consent to the payment
* and subsequently execute the payment using
* the execute API call.
*
* @param string $total payment amount in DDD.DD format
* @param string $currency 3 letter ISO currency code such as 'USD'
* @param string $paymentDesc A description about the payment
* @param string $returnUrl The url to which the buyer must be redirected
* to on successful completion of payment
* @param string $cancelUrl The url to which the buyer must be redirected
* to if the payment is cancelled
* @return \PayPal\Api\Payment
*/
function makePaymentUsingPayPal($sku, $returnUrl, $cancelUrl)
{
/*
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// Specify the payment amount.
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($total);
// ###Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($paymentDesc);
*/
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName($GLOBALS['PAY_NAME'])->setCurrency(PAYPAL_CURRENCY_EUR)->setQuantity(1)->setPrice($GLOBALS['PAY_PRICE'])->setSku(llenaEspaciosPaypal($sku, 11, '0'));
$itemList = new ItemList();
$itemList->setItems(array($item1));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details = new Details();
$details->setTax($GLOBALS['PAY_TAX'])->setSubtotal($GLOBALS['PAY_TOTAL_AMOUNT']);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency(PAYPAL_CURRENCY_EUR)->setTotal($GLOBALS['PAY_PRICE'])->setDetails($details);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it.
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription($GLOBALS['PAY_DESCRIPTION']);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl);
$redirectUrls->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->create(getApiContext());
return $payment;
}
示例14: paypalAction
public function paypalAction()
{
//Zend_Loader::loadFile('paypal_bootstrap.php', APPLICATION_PATH . "/../library/My/", true);
require_once APPLICATION_PATH . "/../library/My/paypal_bootstrap.php";
$error = false;
$approvalLink = null;
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$currentUser = $auth->getIdentity();
$userMapper = new Application_Model_UserMapper();
$db_adapter = $userMapper->getDbTable()->getAdapter();
$db = Zend_Db::factory('Mysqli', $db_adapter->getConfig());
$results = $userMapper->getShoppingCart($currentUser);
$user = $userMapper->getDbTable()->find($currentUser->id)->current();
$currencyMapper = new Application_Model_CurrencyMapper();
$defaultCurrency = $currencyMapper->getDefaultCurrency();
$data = array('user_id' => $currentUser->id, 'state' => 'created', 'email' => $user->email);
$db->insert('orders', $data);
$lastOrderId = $db->lastInsertId('orders', 'id');
$items = array();
$subTotal = 0;
foreach ($results as $i => $result) {
$item = new Item();
$item->setName($result->name)->setCurrency($defaultCurrency->code)->setQuantity($result->quantity)->setSku($i + 1)->setPrice($result->price);
//->setDescription($result->c_id);
$db->insert('ordered_products', array('product_id' => $result->id, 'name' => $result->name, 'category_id' => $result->getCategoryId(), 'currency' => $defaultCurrency->code, 'price' => $result->price, 'quantity' => $result->quantity, 'order_id' => $lastOrderId));
$items[] = $item;
$subTotal += $result->quantity * (double) number_format($result->price, 2);
}
$itemList = new ItemList();
$itemList->setItems($items);
$shippingTax = 0;
//
$details = new Details();
$details->setShipping($shippingTax)->setTax(0)->setSubtotal($subTotal);
$total = $shippingTax + $subTotal;
$amount = new Amount();
$amount->setCurrency($defaultCurrency->code)->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setCustom($lastOrderId)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($baseUrl . '/users/exepaypal/?success=true');
$redirectUrls->setCancelUrl($baseUrl . '/users/exepaypal/?cancel=true');
$payment = new Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try {
$result = $payment->create($apiContext);
} catch (Exception $ex) {
$error = true;
}
$approvalLink = $payment->getApprovalLink();
} else {
$error = true;
}
$response = array('error' => $error, 'approvalLink' => $approvalLink);
//Send as JSON
header("Content-Type: application/json", true);
//Return JSON
echo json_encode($response);
//Stop Execution
exit;
}
示例15: preparePayment
public static function preparePayment($payment, $domain)
{
$items = array();
$currency = null;
$total = 0;
foreach ($payment->items as $item) {
$tmpItem = new PayPalItem();
$tmpItem->setName($item->description)->setCurrency($item->currency)->setQuantity($item->quantity)->setSku($item->sku)->setPrice($item->price);
$items[] = $tmpItem;
//
$total += (double) $item->price;
$currency = $item->currency;
}
$itemList = new ItemList();
$itemList->setItems($items);
$payer = new PayPalPayer();
switch ($payment->payer->paymentMethod) {
case Payer::PAYMENT_CREDIT_CARD:
$payer->setPaymentMethod($payment->payer->paymentMethod);
$card = new PayPalCreditCard();
$card->setType($payment->payer->creditCard->type)->setNumber($payment->payer->creditCard->number)->setExpireMonth($payment->payer->creditCard->expireMonth)->setExpireYear($payment->payer->creditCard->expireYear)->setCvv2($payment->payer->creditCard->cvv2)->setFirstName($payment->payer->creditCard->firstName)->setLastName($payment->payer->creditCard->lastName);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer->setFundingInstruments(array($fi));
break;
case Payer::PAYMENT_PAYPAL:
$payer->setPaymentMethod($payment->payer->paymentMethod);
break;
}
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($total);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription($payment->description);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($payment->returnUrl);
$redirectUrls->setCancelUrl($payment->cancelUrl);
$paypalPayment = new PayPalPayment();
$paypalPayment->setRedirectUrls($redirectUrls);
$paypalPayment->setIntent($payment->intent);
$paypalPayment->setPayer($payer);
$paypalPayment->setTransactions(array($transaction));
try {
$paypalPayment->create(static::getApiContext($domain));
return static::getPayment($paypalPayment->getId(), $domain)->then(function ($payment) use($paypalPayment) {
$payment->approvalUrl = static::getLink($paypalPayment->getLinks(), "approval_url");
return $payment;
});
} catch (PayPalConnectionException $e) {
return When::reject($e);
} catch (PayPalInvalidCredentialException $e) {
return When::reject($e);
}
}