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