/** * @return Transaction */ private function buildTransaction() { $clientInfo = ClientHelper::getClientInfo(); $priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax; $paypalItems = []; $subTotal = 0; foreach ($this->order->getItems() as $item) { /* @var $item OrderItem */ // don't add shipping row if ($item->isShipping()) { continue; } $subTotal += $item->getPrice(); $newItem = new Item(); $newItem->setName($item->getProductName())->setCurrency($clientInfo->currency->currency_iso)->setQuantity($item->getQuantity())->setSku($item->getProductSku())->setPrice($item->getPrice() / 100); $paypalItems[] = $newItem; } $shippingBeforeTax = $this->order->getShipping() / 100; $tax = $this->order->getTax() / 100; $subTotal = $subTotal / 100; $total = $this->order->getTotalPrice() / 100; $orderShippingAddress = $this->order->getShippingAddress()->getArray(); $shippingAddress = new ShippingAddress(); $shippingAddress->setCity($orderShippingAddress['city']); $shippingAddress->setCountryCode(CountryHelper::getCountryCode($orderShippingAddress['countryId'])); $shippingAddress->setPostalCode($orderShippingAddress['postcode']); $shippingAddress->setLine1($orderShippingAddress['address1']); $shippingAddress->setState($orderShippingAddress['state']); $shippingAddress->setRecipientName($this->order->getCustomer()->fullName()); $itemList = new ItemList(); if (!$priceIncludesTax) { $itemList->setItems($paypalItems); } $itemList->setShippingAddress($shippingAddress); $details = new Details(); $details->setShipping($shippingBeforeTax)->setTax($tax)->setSubtotal($subTotal); $amount = new Amount(); $amount->setCurrency($clientInfo->currency->currency_iso)->setTotal($total)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Order from " . $clientInfo->name)->setInvoiceNumber($this->order->getId()); return $transaction; }