/** * @inheritdoc */ public function content() { /** @var Order $order */ $order = $this->order; $order->calculate(); $payer = (new Payer())->setPaymentMethod('paypal'); $priceSubTotal = 0; /** @var ItemList $itemList */ $itemList = array_reduce($order->items, function ($result, $item) use(&$priceSubTotal) { /** @var OrderItem $item */ /** @var Product $product */ $product = $item->product; $price = CurrencyHelper::convertFromMainCurrency($item->price_per_pcs, $this->currency); $priceSubTotal = $priceSubTotal + $price * $item->quantity; /** @var ItemList $result */ return $result->addItem((new Item())->setName($product->name)->setCurrency($this->currency->iso_code)->setPrice($price)->setQuantity($item->quantity)->setUrl(Url::toRoute(['@product', 'model' => $product, 'category_group_id' => $product->category->category_group_id], true))); }, new ItemList()); $priceTotal = CurrencyHelper::convertFromMainCurrency($order->total_price, $this->currency); $details = (new Details())->setShipping($priceTotal - $priceSubTotal)->setSubtotal($priceSubTotal)->setTax(0); $amount = (new Amount())->setCurrency($this->currency->iso_code)->setTotal($priceTotal)->setDetails($details); $transaction = (new Transaction())->setAmount($amount)->setItemList($itemList)->setDescription($this->transactionDescription)->setInvoiceNumber($this->transaction->id); $urls = (new RedirectUrls())->setReturnUrl($this->createResultUrl(['id' => $this->order->payment_type_id]))->setCancelUrl($this->createFailUrl()); $payment = (new Payment())->setIntent('sale')->setPayer($payer)->setTransactions([$transaction])->setRedirectUrls($urls); $link = null; try { $link = $payment->create($this->apiContext)->getApprovalLink(); } catch (\Exception $e) { $link = null; } return $this->render('paypal', ['order' => $order, 'transaction' => $this->transaction, 'approvalLink' => $link]); }
/** * @param OrderTransaction $transaction * @param Currency $currency * @return float|int */ protected function getTotalSumOrderTransaction(OrderTransaction $transaction, Currency $currency) { return CurrencyHelper::convertFromMainCurrency($transaction->total_sum, $currency); }