Exemplo n.º 1
0
 /**
  * Frees the resources listed in the order.
  *
  * If customers created orders but didn't pay for them, the blocked resources
  * like products and redeemed coupon codes must be unblocked so they can be
  * ordered again or used by other customers. This method increased the stock
  * level of products, the counts of coupon codes and others.
  *
  * It's save to call this method multiple times for one order. In this case,
  * the actions will be executed only once. All subsequent calls will do
  * nothing as long as the resources haven't been blocked in the meantime.
  *
  * You can also unblock and block resources several times. Please keep in
  * mind that unblocked resources may be reused by other orders in the
  * meantime. This can lead to an oversell of products!
  *
  * @param MShop_Order_Item_Interface $orderItem Order item object
  */
 public function unblock(MShop_Order_Item_Interface $orderItem)
 {
     $status = 0;
     $orderId = $orderItem->getId();
     $this->_updateStatus(MShop_Order_Item_Status_Abstract::STOCK_UPDATE, $orderId, $orderItem, $status, +1);
     $this->_updateStatus(MShop_Order_Item_Status_Abstract::COUPON_UPDATE, $orderId, $orderItem, $status, +1);
 }
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
 /**
  * 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.º 4
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.º 5
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);
 }