Exemplo n.º 1
0
 /**
  * Maps the PayPal status to the appropriate payment status and sets it in the order object.
  *
  * @param MShop_Order_Item_Interface $invoice Order invoice object
  * @param array $response Associative list of key/value pairs containing the PayPal response
  */
 protected function _setPaymentStatus(MShop_Order_Item_Interface $invoice, array $response)
 {
     if (!isset($response['PAYMENTSTATUS'])) {
         return;
     }
     switch ($response['PAYMENTSTATUS']) {
         case 'Pending':
             if (isset($response['PENDINGREASON'])) {
                 if ($response['PENDINGREASON'] === 'authorization') {
                     $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_AUTHORIZED);
                     break;
                 }
                 $str = 'PayPal Express: order ID = ' . $invoice->getId() . ', PENDINGREASON = ' . $response['PENDINGREASON'];
                 $this->_getContext()->getLogger()->log($str, MW_Logger_Abstract::INFO);
             }
             $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_PENDING);
             break;
         case 'In-Progress':
             $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_PENDING);
             break;
         case 'Completed':
         case 'Processed':
             $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_RECEIVED);
             break;
         case 'Failed':
         case 'Denied':
         case 'Expired':
             $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_REFUSED);
             break;
         case 'Refunded':
         case 'Partially-Refunded':
         case 'Reversed':
             $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_REFUND);
             break;
         case 'Canceled-Reversal':
         case 'Voided':
             $invoice->setPaymentStatus(MShop_Order_Item_Abstract::PAY_CANCELED);
             break;
         default:
             $str = 'PayPal Express: order ID = ' . $invoice->getId() . ', response = ' . print_r($response, true);
             $this->_getContext()->getLogger()->log($str, MW_Logger_Abstract::INFO);
     }
 }
Exemplo n.º 2
0
 /**
  * Adds the new payment and delivery values to the order status log.
  *
  * @param MShop_Order_Item_Interface $item Order item object
  */
 protected function _addStatus(MShop_Order_Item_Interface $item)
 {
     $statusManager = MShop_Factory::createManager($this->_getContext(), 'order/status');
     $statusItem = $statusManager->createItem();
     $statusItem->setParentId($item->getId());
     if ($item->getPaymentStatus() != $item->oldPaymentStatus) {
         $statusItem->setId(null);
         $statusItem->setType(MShop_Order_Item_Status_Abstract::STATUS_PAYMENT);
         $statusItem->setValue($item->getPaymentStatus());
         $statusManager->saveItem($statusItem, false);
     }
     if ($item->getDeliveryStatus() != $item->oldDeliveryStatus) {
         $statusItem->setId(null);
         $statusItem->setType(MShop_Order_Item_Status_Abstract::STATUS_DELIVERY);
         $statusItem->setValue($item->getDeliveryStatus());
         $statusManager->saveItem($statusItem, false);
     }
 }
Exemplo n.º 3
0
 /**
  * Adds the header elements to the XML object
  *
  * @param MShop_Order_Item_Interface $invoice Order of the customer
  * @param MShop_Order_Item_Base_Interface $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(MShop_Order_Item_Interface $invoice, MShop_Order_Item_Base_Interface $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 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 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 MShop_Order_Item_Interface $order Order instance
  */
 public function process(MShop_Order_Item_Interface $order)
 {
     $order->setDeliveryStatus(MShop_Order_Item_Abstract::STAT_PROGRESS);
 }
Exemplo n.º 5
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 MShop_Order_Item_Interface $order Order invoice object
  * @param array $params Request parameter if available
  * @return MShop_Common_Item_Helper_Form_Default 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(MShop_Order_Item_Interface $order, array $params = array())
 {
     $order->setPaymentStatus(MShop_Order_Item_Abstract::PAY_AUTHORIZED);
     $this->_saveOrder($order);
     return parent::process($order, $params);
 }
Exemplo n.º 6
0
 /**
  * Adds the services from the given order item to the basket.
  *
  * @param MShop_Order_Item_Base_Interface $order Basket object
  * @param MShop_Order_Item_Interface $item Existing order to fetch the services from
  */
 protected function _setServices(MShop_Order_Item_Base_Interface $order, MShop_Order_Item_Interface $item)
 {
     $services = $order->getServices();
     if (empty($services) && $this->_getConfigValue('autofill.orderservice', true) == true) {
         $manager = 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.º 7
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 MShop_Order_Item_Interface $order Order invoice object
  * @return MShop_Common_Item_Helper_Form_Default 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(MShop_Order_Item_Interface $order)
 {
     $order->setPaymentStatus(MShop_Order_Item_Abstract::PAY_PENDING);
     return parent::process($order);
 }
Exemplo n.º 8
0
 /**
  * Increases or decreases the stock level or the coupon code count for referenced items of the given order.
  *
  * @param MShop_Order_Item_Interface $orderItem Order item object
  * @param string $type Constant from MShop_Order_Item_Status_Abstract, e.g. STOCK_UPDATE or COUPON_UPDATE
  * @param string $status New status value stored along with the order item
  * @param integer $value Number to increse or decrease the stock level or coupon code count
  */
 protected function _updateStatus(MShop_Order_Item_Interface $orderItem, $type, $status, $value)
 {
     $statusItem = $this->_getLastStatusItem($orderItem->getId(), $type);
     if ($statusItem !== false && $statusItem->getValue() == $status) {
         return;
     }
     if ($type == MShop_Order_Item_Status_Abstract::STOCK_UPDATE) {
         $this->_updateStock($orderItem, $value);
     } elseif ($type == MShop_Order_Item_Status_Abstract::COUPON_UPDATE) {
         $this->_updateCoupons($orderItem, $value);
     }
     $this->_addStatusItem($orderItem->getId(), $type, $status);
 }
Exemplo n.º 9
0
 protected function _updateStock(MShop_Order_Item_Interface $orderItem, $how = +1)
 {
     $context = $this->_getContext();
     $manager = MShop_Factory::createManager($context, 'order/base/product');
     $stockManager = MShop_Factory::createManager($context, 'product/stock');
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'order.base.product.baseid', $orderItem->getBaseId()));
     $start = 0;
     $stockManager->begin();
     do {
         $items = $manager->searchItems($search);
         foreach ($items as $item) {
             $stockManager->increase($item->getProductCode(), $item->getWarehouseCode(), $how * $item->getQuantity());
         }
         $count = count($items);
         $start += $count;
         $search->setSlice($start);
     } while ($count >= $search->getSliceSize());
     $stockManager->commit();
 }