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;
}