/** * Checks if the country code is allowed for the service provider. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object * @return boolean True if payment provider can be used, false if not */ public function isAvailable(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $code = strtoupper($basket->getPrice()->getCurrencyId()); if ($this->checkCurrencyCode($code, 'currency.include') === false || $this->checkCurrencyCode($code, 'currency.exclude') === true) { return false; } return $this->getProvider()->isAvailable($basket); }
/** * Returns the price when using the provider. * Usually, this is the lowest price that is available in the service item but can also be a calculated based on * the basket content, e.g. 2% of the value as transaction cost. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object * @return \Aimeos\MShop\Price\Item\Iface Price item containing the price, shipping, rebate */ public function calcPrice(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $config = $this->getServiceItem()->getConfig(); if (!isset($config['costs.percent'])) { throw new \Aimeos\MShop\Service\Provider\Exception(sprintf('Missing configuration "%1$s"', 'costs.percent')); } $value = $basket->getPrice()->getValue() * $config['costs.percent'] / 100; $price = $this->getProvider()->calcPrice($basket); $price->setCosts($price->getCosts() + $value); return $price; }
/** * Checks for the min/max order value. * * @param \Aimeos\MShop\Order\Item\Base\Iface $base Basic order of the customer * @return boolean True if the basket matches the constraints, false if not */ public function isAvailable(\Aimeos\MShop\Order\Item\Base\Iface $base) { $price = $base->getPrice(); $currency = $price->getCurrencyId(); $value = $price->getValue() + $price->getRebate(); $minvalue = $this->getConfigValue('basketvalues.total-value-min', array()); if (isset($minvalue[$currency]) && $minvalue[$currency] > $value) { return false; } $maxvalue = $this->getConfigValue('basketvalues.total-value-max', array()); if (isset($maxvalue[$currency]) && $maxvalue[$currency] < $value) { return false; } return parent::isAvailable($base); }
/** * Adds the price item to the XML object * * @param \Aimeos\MShop\Order\Item\Base\Iface $base Order base object * @param \DOMDocument $dom DOM document object with contains the XML structure * @param \DOMElement $orderitem DOM element which will be the parent of the new child * @throws DOMException If an error occures */ protected function buildXMLPrice(\Aimeos\MShop\Order\Item\Base\Iface $base, \DOMDocument $dom, \DOMElement $orderitem) { $price = $base->getPrice(); $total = $price->getValue() + $price->getCosts(); $priceitem = $dom->createElement('priceitem'); $this->appendChildCDATA('price', number_format($price->getValue(), 2, '.', ''), $dom, $priceitem); $this->appendChildCDATA('shipping', number_format($price->getCosts(), 2, '.', ''), $dom, $priceitem); $this->appendChildCDATA('discount', number_format(0.0, 2, '.', ''), $dom, $priceitem); $this->appendChildCDATA('total', number_format($total, 2, '.', ''), $dom, $priceitem); $orderitem->appendChild($priceitem); }
/** * 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; }