Exemplo n.º 1
0
 /**
  * Returns the payment form for entering payment details at the shop site.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $order Order object
  * @param array $params Request parameter if available
  * @return \Aimeos\MShop\Common\Item\Helper\Form\Iface Form helper object
  */
 protected function getPaymentForm(\Aimeos\MShop\Order\Item\Iface $order, array $params)
 {
     $list = array();
     $feConfig = $this->feConfig;
     $baseItem = $this->getOrderBase($order->getBaseId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS);
     try {
         $address = $baseItem->getAddress();
         if (!isset($params[$feConfig['payment.firstname']['internalcode']]) || $params[$feConfig['payment.firstname']['internalcode']] == '') {
             $feConfig['payment.firstname']['default'] = $address->getFirstname();
         }
         if (!isset($params[$feConfig['payment.lastname']['internalcode']]) || $params[$feConfig['payment.lastname']['internalcode']] == '') {
             $feConfig['payment.lastname']['default'] = $address->getLastname();
         }
         if ($this->getValue('address')) {
             $feConfig['payment.address1']['default'] = $address->getAddress1() . ' ' . $address->getAddress2();
             $feConfig['payment.city']['default'] = $address->getCity();
             $feConfig['payment.postal']['default'] = $address->getPostal();
             $feConfig['payment.countryid']['default'] = $address->getCountryId();
             $feConfig['payment.telephone']['default'] = $address->getTelephone();
             $feConfig['payment.company']['default'] = $address->getCompany();
             $feConfig['payment.email']['default'] = $address->getEmail();
         }
     } 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);
     }
     $url = $this->getConfigValue(array('payment.url-self'));
     return new \Aimeos\MShop\Common\Item\Helper\Form\Standard($url, 'POST', $list, false);
 }
Exemplo n.º 2
0
 /**
  * Tries to get an authorization or captures the money immediately for the given order if capturing the money
  * separately isn't supported or not configured by the shop owner.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
  * @param array $params Request parameter if available
  * @return \Aimeos\MShop\Common\Item\Helper\Form\Standard Form object with URL, action and parameters to redirect to
  * 	(e.g. to an external server of the payment provider or to a local success page)
  */
 public function process(\Aimeos\MShop\Order\Item\Iface $order, array $params = array())
 {
     $order->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED);
     $this->saveOrder($order);
     return parent::process($order, $params);
 }
Exemplo n.º 3
0
 /**
  * Adds the header elements to the XML object
  *
  * @param \Aimeos\MShop\Order\Item\Iface $invoice Order of the customer
  * @param \Aimeos\MShop\Order\Item\Base\Iface $base Order base item of the customer
  * @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 buildXMLHeader(\Aimeos\MShop\Order\Item\Iface $invoice, \Aimeos\MShop\Order\Item\Base\Iface $base, \DOMDocument $dom, \DOMElement $orderitem)
 {
     $regex = '/^(\\d+)\\-(\\d+)\\-(\\d+) (\\d+)\\:(\\d+)\\:(\\d+)$/i';
     $date = $invoice->getDatePayment();
     if (($pdate = preg_replace($regex, '$1-$2-$3T$4:$5:$6Z', $date)) === null) {
         throw new \Aimeos\MShop\Service\Exception(sprintf('Invalid characters in purchase date "%1$s"', $date));
     }
     $config = $this->getServiceItem()->getConfig();
     if (!isset($config['default.project'])) {
         $msg = 'Parameter "%1$s" for configuration not available';
         throw new \Aimeos\MShop\Service\Exception(sprintf($msg, "project"), parent::ERR_TEMP);
     }
     $this->appendChildCDATA('id', $invoice->getId(), $dom, $orderitem);
     $this->appendChildCDATA('type', $invoice->getType(), $dom, $orderitem);
     $this->appendChildCDATA('datetime', $pdate, $dom, $orderitem);
     if ($invoice->getRelatedId() !== null) {
         $this->appendChildCDATA('relatedid', $invoice->getRelatedId(), $dom, $orderitem);
     }
     $this->appendChildCDATA('customerid', $base->getCustomerId(), $dom, $orderitem);
     $this->appendChildCDATA('projectcode', $config['default.project'], $dom, $orderitem);
     $this->appendChildCDATA('languagecode', strtoupper($base->getLocale()->getLanguageId()), $dom, $orderitem);
     $this->appendChildCDATA('currencycode', $base->getPrice()->getCurrencyId(), $dom, $orderitem);
 }
Exemplo n.º 4
0
 /**
  * Updates the delivery status.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $order Order instance
  */
 public function process(\Aimeos\MShop\Order\Item\Iface $order)
 {
     $order->setDeliveryStatus(\Aimeos\MShop\Order\Item\Base::STAT_PROGRESS);
 }
Exemplo n.º 5
0
 /**
  * Adds the services from the given order item to the basket.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $order Basket object
  * @param \Aimeos\MShop\Order\Item\Iface $item Existing order to fetch the services from
  */
 protected function setServices(\Aimeos\MShop\Order\Item\Base\Iface $order, \Aimeos\MShop\Order\Item\Iface $item)
 {
     $services = $order->getServices();
     if (empty($services) && $this->getConfigValue('autofill.orderservice', true) == true) {
         $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/service');
         $search = $manager->createSearch();
         $search->setConditions($search->compare('==', 'order.base.service.baseid', $item->getBaseId()));
         $services = $manager->searchItems($search);
         foreach ($services as $service) {
             $type = $service->getType();
             if (($item = $this->getServiceItem($order, $type, $service->getCode())) !== null) {
                 $order->setService($item, $type);
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Tries to get an authorization or captures the money immediately for the given order if capturing the money
  * separately isn't supported or not configured by the shop owner.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
  * @param array $params Request parameter if available
  * @return \Aimeos\MShop\Common\Item\Helper\Form\Standard Form object with URL, action and parameters to redirect to
  * 	(e.g. to an external server of the payment provider or to a local success page)
  */
 protected function processOrder(\Aimeos\MShop\Order\Item\Iface $order, array $params = array())
 {
     $urls = $this->getPaymentUrls();
     $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE | \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS;
     $base = $this->getOrderBase($order->getBaseId(), $parts);
     $desc = $this->getContext()->getI18n()->dt('mshop', 'Order %1$s');
     $card = $this->getCardDetails($base, $params);
     $orderid = $order->getId();
     $data = array('token' => '', 'card' => $card, 'transactionId' => $orderid, 'description' => sprintf($desc, $orderid), 'amount' => $this->getAmount($base->getPrice()), 'currency' => $base->getLocale()->getCurrencyId(), 'language' => $base->getAddress(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT)->getLanguageId(), 'clientIp' => $this->getValue('client.ipaddress')) + $urls;
     try {
         $provider = $this->getProvider();
         if ($this->getValue('authorize', false) && $provider->supportsAuthorize()) {
             $response = $provider->authorize($data)->send();
             $status = \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED;
         } else {
             $response = $provider->purchase($data)->send();
             $status = \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED;
         }
         if ($response->isSuccessful()) {
             $this->saveTransationRef($base, $response->getTransactionReference());
             $order->setPaymentStatus($status);
             $this->saveOrder($order);
         } elseif ($response->isRedirect()) {
             if (($ref = $response->getTransactionReference()) != null) {
                 $this->saveTransationRef($base, $ref);
             }
             return $this->getRedirectForm($response);
         } else {
             $order->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_REFUSED);
             $this->saveOrder($order);
             throw new \Aimeos\MShop\Service\Exception($response->getMessage());
         }
     } catch (\Exception $e) {
         throw new \Aimeos\MShop\Service\Exception($e->getMessage());
     }
     return new \Aimeos\MShop\Common\Item\Helper\Form\Standard($urls['returnUrl'], 'POST', array());
 }
Exemplo n.º 7
0
 /**
  * Adds the new payment and delivery values to the order status log.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $item Order item object
  */
 protected function addStatus(\Aimeos\MShop\Order\Item\Iface $item)
 {
     $statusManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/status');
     $statusItem = $statusManager->createItem();
     $statusItem->setParentId($item->getId());
     if ($item->getPaymentStatus() != $item->oldPaymentStatus) {
         $statusItem->setId(null);
         $statusItem->setType(\Aimeos\MShop\Order\Item\Status\Base::STATUS_PAYMENT);
         $statusItem->setValue($item->getPaymentStatus());
         $statusManager->saveItem($statusItem, false);
     }
     if ($item->getDeliveryStatus() != $item->oldDeliveryStatus) {
         $statusItem->setId(null);
         $statusItem->setType(\Aimeos\MShop\Order\Item\Status\Base::STATUS_DELIVERY);
         $statusItem->setValue($item->getDeliveryStatus());
         $statusManager->saveItem($statusItem, false);
     }
 }
Exemplo n.º 8
0
 /**
  * Maps the PayPal status to the appropriate payment status and sets it in the order object.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $invoice Order invoice object
  * @param array $response Associative list of key/value pairs containing the PayPal response
  */
 protected function setPaymentStatus(\Aimeos\MShop\Order\Item\Iface $invoice, array $response)
 {
     if (!isset($response['PAYMENTSTATUS'])) {
         return;
     }
     switch ($response['PAYMENTSTATUS']) {
         case 'Pending':
             if (isset($response['PENDINGREASON'])) {
                 if ($response['PENDINGREASON'] === 'authorization') {
                     $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED);
                     break;
                 }
                 $str = 'PayPal Express: order ID = ' . $invoice->getId() . ', PENDINGREASON = ' . $response['PENDINGREASON'];
                 $this->getContext()->getLogger()->log($str, \Aimeos\MW\Logger\Base::INFO);
             }
             $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_PENDING);
             break;
         case 'In-Progress':
             $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_PENDING);
             break;
         case 'Completed':
         case 'Processed':
             $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_RECEIVED);
             break;
         case 'Failed':
         case 'Denied':
         case 'Expired':
             $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_REFUSED);
             break;
         case 'Refunded':
         case 'Partially-Refunded':
         case 'Reversed':
             $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_REFUND);
             break;
         case 'Canceled-Reversal':
         case 'Voided':
             $invoice->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_CANCELED);
             break;
         default:
             $str = 'PayPal Express: order ID = ' . $invoice->getId() . ', response = ' . print_r($response, true);
             $this->getContext()->getLogger()->log($str, \Aimeos\MW\Logger\Base::INFO);
     }
 }
Exemplo n.º 9
0
 /**
  * Increases or decreses the stock levels of the products referenced in the order by the given value.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
  * @param integer $how Positive or negative integer number for increasing or decreasing the stock levels
  */
 protected function updateStock(\Aimeos\MShop\Order\Item\Iface $orderItem, $how = +1)
 {
     $context = $this->getContext();
     $productManager = \Aimeos\MShop\Factory::createManager($context, 'product');
     $stockManager = \Aimeos\MShop\Factory::createManager($context, 'product/stock');
     $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product');
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'order.base.product.baseid', $orderItem->getBaseId()));
     $start = 0;
     $stockManager->begin();
     try {
         do {
             $items = $manager->searchItems($search);
             foreach ($items as $item) {
                 $stockManager->increase($item->getProductCode(), $item->getWarehouseCode(), $how * $item->getQuantity());
                 // recalculate stock level of product bundles
                 $search = $productManager->createSearch();
                 $expr = array($search->compare('==', 'product.type.code', 'bundle'), $search->compare('==', 'product.lists.domain', 'product'), $search->compare('==', 'product.lists.refid', $item->getProductId()), $search->compare('==', 'product.lists.type.code', 'default'));
                 $search->setConditions($search->combine('&&', $expr));
                 $search->setSlice(0, 0x7fffffff);
                 $bundleItems = $productManager->searchItems($search, array('product'));
                 $this->updateStockBundle($bundleItems, $item->getWarehouseCode());
             }
             $count = count($items);
             $start += $count;
             $search->setSlice($start);
         } while ($count >= $search->getSliceSize());
         $stockManager->commit();
     } catch (\Exception $e) {
         $stockManager->rollback();
         throw $e;
     }
 }
Exemplo n.º 10
0
 /**
  * Tries to get an authorization or captures the money immediately for the given order if capturing the money
  * separately isn't supported or not configured by the shop owner.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
  * @param array $params Request parameter if available
  * @return \Aimeos\MShop\Common\Item\Helper\Form\Standard Form object with URL, action and parameters to redirect to
  * 	(e.g. to an external server of the payment provider or to a local success page)
  */
 protected function processOrder(\Aimeos\MShop\Order\Item\Iface $order, array $params = array())
 {
     $parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE | \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS;
     $base = $this->getOrderBase($order->getBaseId(), $parts);
     $data = $this->getData($base, $order->getId(), $params);
     $urls = $this->getPaymentUrls();
     try {
         $provider = $this->getProvider();
         if ($this->getValue('authorize', false) && $provider->supportsAuthorize()) {
             $response = $provider->authorize($data)->send();
             $status = \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED;
         } else {
             $response = $provider->purchase($data)->send();
             $status = \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED;
         }
         if ($response->isSuccessful()) {
             $this->saveTransationRef($base, $response->getTransactionReference());
             $order->setPaymentStatus($status);
             $this->saveOrder($order);
         } elseif ($response->isRedirect()) {
             if (($ref = $response->getTransactionReference()) != null) {
                 $this->saveTransationRef($base, $ref);
             }
             return $this->getRedirectForm($response);
         } else {
             $order->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_REFUSED);
             $this->saveOrder($order);
             throw new \Aimeos\MShop\Service\Exception($response->getMessage());
         }
     } catch (\Exception $e) {
         throw new \Aimeos\MShop\Service\Exception($e->getMessage());
     }
     return new \Aimeos\MShop\Common\Item\Helper\Form\Standard($urls['returnUrl'], 'POST', array());
 }
Exemplo n.º 11
0
 /**
  * Cancels the authorization for the given order if supported.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
  */
 public function cancel(\Aimeos\MShop\Order\Item\Iface $order)
 {
     $order->setPaymentStatus(\Aimeos\MShop\Order\Item\Base::PAY_CANCELED);
     $this->saveOrder($order);
 }
Exemplo n.º 12
0
 /**
  * Increases or decreses the stock levels of the products referenced in the order by the given value.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
  * @param integer $how Positive or negative integer number for increasing or decreasing the stock levels
  */
 protected function updateStock(\Aimeos\MShop\Order\Item\Iface $orderItem, $how = +1)
 {
     $context = $this->getContext();
     $stockManager = \Aimeos\MShop\Factory::createManager($context, 'product/stock');
     $manager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product');
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'order.base.product.baseid', $orderItem->getBaseId()));
     $start = 0;
     $stockManager->begin();
     try {
         do {
             $items = $manager->searchItems($search);
             foreach ($items as $item) {
                 $stockManager->increase($item->getProductCode(), $item->getWarehouseCode(), $how * $item->getQuantity());
                 switch ($item->getType()) {
                     case 'default':
                         $this->updateStockBundle($item->getProductId(), $item->getWarehouseCode());
                         break;
                     case 'select':
                         $this->updateStockSelection($item->getProductId(), $item->getWarehouseCode());
                         break;
                 }
             }
             $count = count($items);
             $start += $count;
             $search->setSlice($start);
         } while ($count >= $search->getSliceSize());
         $stockManager->commit();
     } catch (\Exception $e) {
         $stockManager->rollback();
         throw $e;
     }
 }