/** * Returns the configuration attribute definitions of the provider to generate a list of available fields and * rules for the value of each field in the frontend. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object * @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface */ public function getConfigFE(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $list = array(); $feconfig = $this->feConfig; try { $attrs = $basket->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT)->getAttributes(); foreach ($attrs as $item) { if (isset($feconfig[$item->getCode()])) { $feconfig[$item->getCode()]['default'] = $item->getValue(); } } } catch (\Aimeos\MShop\Order\Exception $e) { } // If payment isn't available yet try { $address = $basket->getAddress(); if ($feconfig['novalnetsepa.holder']['default'] == '' && ($fn = $address->getFirstname()) !== '' && ($ln = $address->getLastname()) !== '') { $feconfig['novalnetsepa.holder']['default'] = $fn . ' ' . $ln; } } catch (\Aimeos\MShop\Order\Exception $e) { } // If address isn't available foreach ($feconfig as $key => $config) { $list[$key] = new \Aimeos\MW\Criteria\Attribute\Standard($config); } return $list; }
/** * Returns a list of tax rates and values for the given basket. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket containing the products, services, etc. * @return array Associative list of tax rates as key and corresponding amounts as value */ protected function getTaxRates(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $taxrates = array(); foreach ($basket->getProducts() as $product) { $price = $product->getSumPrice(); $taxrate = $price->getTaxrate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate]->addItem($price); } else { $taxrates[$taxrate] = $price->setQuantity(1); // sum is already calculated } } try { $price = clone $basket->getService('delivery')->getPrice(); $taxrate = $price->getTaxrate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate]->addItem($price, $price->getQuantity()); } else { $taxrates[$taxrate] = $price->setQuantity(1); // only single price } } catch (\Exception $e) { } // if delivery service isn't available try { $price = clone $basket->getService('payment')->getPrice(); $taxrate = $price->getTaxrate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate]->addItem($price, $price->getQuantity()); } else { $taxrates[$taxrate] = $price->setQuantity(1); // only single price } } catch (\Exception $e) { } // if payment service isn't available return $taxrates; }
/** * Returns a list of tax rates and values for the given basket. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket containing the products, services, etc. * @return array Associative list of tax rates as key and corresponding amounts as value */ protected function getTaxRates(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $taxrates = array(); foreach ($basket->getProducts() as $product) { $price = $product->getPrice(); $taxrate = $price->getTaxrate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate] += ($price->getValue() + $price->getCosts()) * $product->getQuantity(); } else { $taxrates[$taxrate] = ($price->getValue() + $price->getCosts()) * $product->getQuantity(); } } try { $price = $basket->getService('delivery')->getPrice(); $taxrate = $price->getTaxrate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate] += $price->getValue() + $price->getCosts(); } else { $taxrates[$taxrate] = $price->getValue() + $price->getCosts(); } } catch (\Exception $e) { } // if delivery service isn't available try { $price = $basket->getService('payment')->getPrice(); $taxrate = $price->getTaxrate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate] += $price->getValue() + $price->getCosts(); } else { $taxrates[$taxrate] = $price->getValue() + $price->getCosts(); } } catch (\Exception $e) { } // if payment service isn't available return $taxrates; }
/** * Returns a list of tax rates and their price items for the given basket. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket containing the products, services, etc. * @return array Associative list of tax rates as key and corresponding price items as value */ protected function getPriceByTaxRate(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $taxrates = array(); $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'price'); foreach ($basket->getProducts() as $product) { $price = $product->getPrice(); $taxrate = $price->getTaxRate(); if (!isset($taxrates[$taxrate])) { $taxrates[$taxrate] = $manager->createItem(); } $taxrates[$taxrate]->addItem($price, $product->getQuantity()); } try { $price = $basket->getService('delivery')->getPrice(); $taxrate = $price->getTaxRate(); if (!isset($taxrates[$taxrate])) { $taxrates[$taxrate] = $manager->createItem(); } $taxrates[$taxrate]->addItem($price); } catch (\Exception $e) { } // if delivery service isn't available try { $price = $basket->getService('payment')->getPrice(); $taxrate = $price->getTaxRate(); if (!isset($taxrates[$taxrate])) { $taxrates[$taxrate] = $manager->createItem(); } $taxrates[$taxrate]->addItem($price); } catch (\Exception $e) { } // if payment service isn't available return $taxrates; }
/** * Addes the transation reference to the order service attributes. * * @param \Aimeos\MShop\Order\Item\Base\Iface $baseItem Order base object with service items attached * @param string $ref Transaction reference from the payment gateway */ protected function saveTransationRef(\Aimeos\MShop\Order\Item\Base\Iface $baseItem, $ref) { $serviceItem = $baseItem->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT); $attr = array('TRANSACTIONID' => $ref); $this->setAttributes($serviceItem, $attr, 'payment/omnipay'); $this->saveOrderBase($baseItem); }
/** * Returns an list of order data required by PayPal. * * @param \Aimeos\MShop\Order\Item\Base\Iface $orderBase Order base item * @return array Associative list of key/value pairs with order data required by PayPal */ protected function getOrderDetails(\Aimeos\MShop\Order\Item\Base\Iface $orderBase) { $deliveryCosts = $paymentCosts = '0.00'; $values = $this->getAuthParameter(); try { $orderAddressDelivery = $orderBase->getAddress(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY); /* setting up the shipping address details (ReviewOrder) */ $values['ADDROVERRIDE'] = 1; $values['PAYMENTREQUEST_0_SHIPTONAME'] = $orderAddressDelivery->getFirstName() . ' ' . $orderAddressDelivery->getLastName(); $values['PAYMENTREQUEST_0_SHIPTOSTREET'] = $orderAddressDelivery->getAddress1() . ' ' . $orderAddressDelivery->getAddress2() . ' ' . $orderAddressDelivery->getAddress3(); $values['PAYMENTREQUEST_0_SHIPTOCITY'] = $orderAddressDelivery->getCity(); $values['PAYMENTREQUEST_0_SHIPTOSTATE'] = $orderAddressDelivery->getState(); $values['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $orderAddressDelivery->getCountryId(); $values['PAYMENTREQUEST_0_SHIPTOZIP'] = $orderAddressDelivery->getPostal(); } catch (\Exception $e) { } // If no address is available $lastPos = 0; foreach ($orderBase->getProducts() as $product) { $price = $product->getPrice(); $lastPos = $product->getPosition() - 1; $values['L_PAYMENTREQUEST_0_NUMBER' . $lastPos] = $product->getId(); $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $product->getName(); $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = $product->getQuantity(); $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $this->getAmount($price); } $price = $orderBase->getService('payment')->getPrice(); if (($paymentCosts = $this->getAmount($price)) > '0.00') { $lastPos++; $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $this->getContext()->getI18n()->dt('mshop', 'Payment costs'); $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = '1'; $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $paymentCosts; } try { $orderServiceDeliveryItem = $orderBase->getService('delivery'); $deliveryCosts = $this->getAmount($orderServiceDeliveryItem->getPrice()); $values['L_SHIPPINGOPTIONAMOUNT0'] = (string) $deliveryCosts; $values['L_SHIPPINGOPTIONLABEL0'] = $orderServiceDeliveryItem->getName(); $values['L_SHIPPINGOPTIONNAME0'] = $orderServiceDeliveryItem->getCode(); $values['L_SHIPPINGOPTIONISDEFAULT0'] = 'true'; } catch (\Exception $e) { } // If no delivery service is available $price = $orderBase->getPrice(); $amount = $this->getAmount($price); $values['MAXAMT'] = $amount + 0.01; // @todo rounding error? $values['PAYMENTREQUEST_0_AMT'] = $amount; $values['PAYMENTREQUEST_0_ITEMAMT'] = number_format($price->getValue() + $paymentCosts, 2, '.', ''); $values['PAYMENTREQUEST_0_SHIPPINGAMT'] = number_format($price->getCosts() - $paymentCosts, 2, '.', ''); $values['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00'; $values['PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED'] = 'false'; $values['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00'; $values['PAYMENTREQUEST_0_TAXAMT'] = $price->getTaxValue(); $values['PAYMENTREQUEST_0_CURRENCYCODE'] = $orderBase->getPrice()->getCurrencyId(); $values['PAYMENTREQUEST_0_PAYMENTACTION'] = $this->getConfigValue(array('paypalexpress.PaymentAction'), 'sale'); return $values; }