/** * 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); }
/** * 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()); }
/** * 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); } }
/** * 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); } }
/** * Increases or decreases the stock level or the coupon code count for referenced items of the given order. * * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object * @param string $type Constant from \Aimeos\MShop\Order\Item\Status\Base, 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(\Aimeos\MShop\Order\Item\Iface $orderItem, $type, $status, $value) { $statusItem = $this->getLastStatusItem($orderItem->getId(), $type); if ($statusItem !== false && $statusItem->getValue() == $status) { return; } if ($type == \Aimeos\MShop\Order\Item\Status\Base::STOCK_UPDATE) { $this->updateStock($orderItem, $value); } elseif ($type == \Aimeos\MShop\Order\Item\Status\Base::COUPON_UPDATE) { $this->updateCoupons($orderItem, $value); } $this->addStatusItem($orderItem->getId(), $type, $status); }
/** * 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()); }