/** * Add the given Items to the given order */ public function addAction() { $orderId = $this->Request()->getParam("orderId"); $insertedIds = json_decode($this->Request()->getParam("insertedIds")); $subOperation = $this->Request()->getParam("suboperation"); $order = Shopware()->Db()->fetchRow("SELECT * FROM `s_order` WHERE `id`=?", array($orderId)); $orderItems = Shopware()->Db()->fetchAll("SELECT *, (`quantity` - `delivered` - `cancelled`) AS `quantityDeliver` FROM `s_order_details` " . "INNER JOIN `rpay_ratepay_order_positions` ON `s_order_details`.`id` = `rpay_ratepay_order_positions`.`s_order_details_id` " . "WHERE `orderID`=?", array($orderId)); $basketItems = array(); foreach ($orderItems as $row) { if ($row['quantityDeliver'] == 0) { continue; } $basketItem = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item(); $basketItem->setArticleName($row['name']); $basketItem->setArticleNumber($row['articleordernumber']); $basketItem->setQuantity($row['quantityDeliver']); $basketItem->setTaxRate($row['tax_rate']); $basketItem->setUnitPriceGross($row['price']); $basketItems[] = $basketItem; } $shippingRow = $this->getShippingFromDBAsItem($orderId); if (!is_null($shippingRow) && $shippingRow['quantityDeliver'] != 0) { $basketItem = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item(); $basketItem->setArticleName($shippingRow['name']); $basketItem->setArticleNumber($shippingRow['articleordernumber']); $basketItem->setQuantity($shippingRow['quantityDeliver']); $basketItem->setTaxRate($shippingRow['tax_rate']); $basketItem->setUnitPriceGross($shippingRow['price']); $basketItems[] = $basketItem; } $basket = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_ShoppingBasket(); $basket->setAmount($this->getRecalculatedAmount($basketItems)); $basket->setCurrency($order['currency']); $basket->setItems($basketItems); $this->_modelFactory->setTransactionId($order['transactionID']); $paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange(), $orderId); $head = $paymentChange->getHead(); $head->setOperationSubstring($subOperation); $paymentChange->setHead($head); $paymentChange->setShoppingBasket($basket); $response = $this->_service->xmlRequest($paymentChange->toArray()); $result = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_CHANGE', $response); if ($result) { $event = $subOperation === 'credit' ? 'Nachlass wurde hinzugefügt' : 'Artikel wurde hinzugefügt'; foreach ($insertedIds as $id) { $newItems = Shopware()->Db()->fetchRow("SELECT * FROM `s_order_details` WHERE `id`=?", array($id)); if ($newItems['quantity'] <= 0) { continue; } $this->_history->logHistory($orderId, $event, $newItems['name'], $newItems['articleordernumber'], $newItems['quantity']); } } $this->setNewOrderState($orderId); $this->View()->assign(array("result" => $result, "success" => true)); }
/** * Procceds the whole Paymentprocess */ private function _proceedPayment() { $paymentInitModel = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentInit()); $result = $this->_service->xmlRequest($paymentInitModel->toArray()); if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_INIT', $result)) { Shopware()->Session()->RatePAY['transactionId'] = $result->getElementsByTagName('transaction-id')->item(0)->nodeValue; $this->_modelFactory->setTransactionId(Shopware()->Session()->RatePAY['transactionId']); $paymentRequestModel = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest()); $result = $this->_service->xmlRequest($paymentRequestModel->toArray()); if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_REQUEST', $result)) { $uniqueId = $this->createPaymentUniqueId(); $orderNumber = $this->saveOrder(Shopware()->Session()->RatePAY['transactionId'], $uniqueId, 17); $paymentConfirmModel = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentConfirm()); $matches = array(); preg_match("/<descriptor.*>(.*)<\\/descriptor>/", $this->_service->getLastResponse(), $matches); $dgNumber = $matches[1]; $result = $this->_service->xmlRequest($paymentConfirmModel->toArray()); if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_CONFIRM', $result)) { if (Shopware()->Session()->sOrderVariables['sBasket']['sShippingcosts'] > 0) { $this->initShipping($orderNumber); } try { $orderId = Shopware()->Db()->fetchOne('SELECT `id` FROM `s_order` WHERE `ordernumber`=?', array($orderNumber)); Shopware()->Db()->update('s_order_attributes', array('attribute5' => $dgNumber, 'attribute6' => Shopware()->Session()->RatePAY['transactionId']), 'orderID=' . $orderId); } catch (Exception $exception) { Shopware()->Pluginlogger()->error($exception->getMessage()); } //set cleared date $dateTime = new DateTime(); $order = Shopware()->Models()->find('Shopware\\Models\\Order\\Order', $orderId); $order->setClearedDate($dateTime); Shopware()->Models()->flush($order); //set payments status to payed $this->savePaymentStatus(Shopware()->Session()->RatePAY['transactionId'], $uniqueId, 12); /** * unset DFI token */ if (Shopware()->Session()->RatePAY['dfpToken']) { unset(Shopware()->Session()->RatePAY['dfpToken']); } /* * redirect to success page */ $this->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => $uniqueId, 'forceSecure' => true)); } else { $this->_error(); } } else { $this->_customerMessage = $result->getElementsByTagName('customer-message')->item(0)->textContent; $this->_error(); } } else { $this->_error(); } }
/** * Sends a Profile_request and saves the data into the Database * * @param string $profileId * @param string $securityCode * * @return boolean */ private function getRatepayConfig($profileId, $securityCode, $shopId, $sandbox) { $factory = new Shopware_Plugins_Frontend_RpayRatePay_Component_Mapper_ModelFactory(); $profileRequestModel = $factory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_ProfileRequest()); $head = $profileRequestModel->getHead(); $head->setProfileId($profileId); $head->setSecurityCode($securityCode); $profileRequestModel->setHead($head); $requestService = new Shopware_Plugins_Frontend_RpayRatePay_Component_Service_RequestService($sandbox); $response = $requestService->xmlRequest($profileRequestModel->toArray()); if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PROFILE_REQUEST', $response)) { $data = array($response->getElementsByTagName('profile-id')->item(0)->nodeValue, $response->getElementsByTagName('activation-status-invoice')->item(0)->nodeValue, $response->getElementsByTagName('activation-status-elv')->item(0)->nodeValue, $response->getElementsByTagName('activation-status-installment')->item(0)->nodeValue, $response->getElementsByTagName('b2b-invoice')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('b2b-elv')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('b2b-installment')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('delivery-address-invoice')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('delivery-address-elv')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('delivery-address-installment')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('tx-limit-invoice-min')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-elv-min')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-installment-min')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-invoice-max')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-elv-max')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-installment-max')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-invoice-max-b2b')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-elv-max-b2b')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-installment-max-b2b')->item(0)->nodeValue, $response->getElementsByTagName('month-allowed')->item(0)->nodeValue, $response->getElementsByTagName('rate-min-normal')->item(0)->nodeValue, $response->getElementsByTagName('interestrate-default')->item(0)->nodeValue, $response->getElementsByTagName('eligibility-device-fingerprint')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('device-fingerprint-snippet-id')->item(0)->nodeValue, strtoupper($response->getElementsByTagName('country-code-billing')->item(0)->nodeValue), strtoupper($response->getElementsByTagName('country-code-delivery')->item(0)->nodeValue), strtoupper($response->getElementsByTagName('currency')->item(0)->nodeValue), $shopId); $activePayments = []; if ($response->getElementsByTagName('activation-status-invoice')->item(0)->nodeValue == 2) { $activePayments[] = '"rpayratepayinvoice"'; } else { $inactivePayments[] = '"rpayratepayinvoice"'; } if ($response->getElementsByTagName('activation-status-elv')->item(0)->nodeValue == 2) { $activePayments[] = '"rpayratepaydebit"'; } else { $inactivePayments[] = '"rpayratepaydebit"'; } if ($response->getElementsByTagName('activation-status-installment')->item(0)->nodeValue == 2) { $activePayments[] = '"rpayratepayrate"'; } else { $inactivePayments[] = '"rpayratepayrate"'; } if (count($activePayments) > 0) { $updateSqlActivePaymentMethods = 'UPDATE `s_core_paymentmeans` SET `active` = 1 WHERE `name` in(' . implode(",", $activePayments) . ') AND `active` <> 0'; } if (count($inactivePayments) > 0) { $updateSqlInactivePaymentMethods = 'UPDATE `s_core_paymentmeans` SET `active` = 0 WHERE `name` in(' . implode(",", $inactivePayments) . ')'; } $configSql = 'REPLACE INTO `rpay_ratepay_config`' . '(`profileId`, `invoiceStatus`,`debitStatus`,`rateStatus`,' . '`b2b-invoice`, `b2b-debit`, `b2b-rate`,' . '`address-invoice`, `address-debit`, `address-rate`,' . '`limit-invoice-min`, `limit-debit-min`, `limit-rate-min`,' . '`limit-invoice-max`, `limit-debit-max`, `limit-rate-max`,' . '`limit-invoice-max-b2b`, `limit-debit-max-b2b`, `limit-rate-max-b2b`,' . '`month-allowed`, `rate-min-normal`, `interestrate-default`,' . '`device-fingerprint-status`, `device-fingerprint-snippet-id`,' . '`country-code-billing`, `country-code-delivery`,' . '`currency`,' . ' `shopId`)' . 'VALUES(' . substr(str_repeat('?,', 28), 0, -1) . ');'; // In case of altering cols change 28 by amount of affected cols try { Shopware()->Db()->query($configSql, $data); if (count($activePayments) > 0) { Shopware()->Db()->query($updateSqlActivePaymentMethods); } if (count($inactivePayments) > 0) { Shopware()->Db()->query($updateSqlInactivePaymentMethods); } return true; } catch (Exception $exception) { Shopware()->Pluginlogger()->info($exception->getMessage()); return false; } } else { Shopware()->Pluginlogger()->error('RatePAY: Profile_Request failed!'); return false; } }