From ed62736269538353a27836e99916821337a870cb Mon Sep 17 00:00:00 2001 From: Aaron Whittington Date: Wed, 12 Sep 2018 15:44:55 +0200 Subject: [PATCH 01/21] [SHPWR-339] remove calls to callRequest (no click-through) --- .../Events/OrderOperationsSubscriber.php | 2 +- Component/Mapper/ModelFactory.php | 42 +++---------------- .../Service/OrderStatusChangeHandler.php | 6 +-- Component/Service/RatepayConfigWriter.php | 2 +- Controller/backend/RpayRatepayOrderDetail.php | 8 ++-- 5 files changed, 14 insertions(+), 46 deletions(-) diff --git a/Bootstrapping/Events/OrderOperationsSubscriber.php b/Bootstrapping/Events/OrderOperationsSubscriber.php index 1b0bdc11..dc46ecab 100644 --- a/Bootstrapping/Events/OrderOperationsSubscriber.php +++ b/Bootstrapping/Events/OrderOperationsSubscriber.php @@ -197,7 +197,7 @@ public function beforeDeleteOrder(\Enlight_Hook_HookArgs $arguments) $operationData['orderId'] = $order->getId(); $operationData['items'] = $items; $operationData['subtype'] = 'cancellation'; - $result = $modelFactory->callRequest('PaymentChange', $operationData); + $result = $modelFactory->callPaymentChange($operationData); if ($result !== true) { Logger::singleton()->warning('Bestellung könnte nicht gelöscht werden, da die Stornierung bei RatePAY fehlgeschlagen ist.'); diff --git a/Component/Mapper/ModelFactory.php b/Component/Mapper/ModelFactory.php index 44f3f2a1..90469577 100755 --- a/Component/Mapper/ModelFactory.php +++ b/Component/Mapper/ModelFactory.php @@ -106,38 +106,6 @@ public function setTransactionId($transactionId) $this->_transactionId = $transactionId; } - /** - * call operation - * - * @param string $operationType - * @param array $operationData - * @deprecated - * @return bool|array|object - */ - public function callRequest($operationType, array $operationData = []) - { - switch ($operationType) { - case 'ProfileRequest': - return $this->callProfileRequest($operationData); - break; - case 'PaymentRequest': - return $this->callPaymentRequest(); - break; - case 'ConfirmationDeliver': - return $this->callConfirmationDeliver($operationData); - break; - case 'PaymentChange': - return $this->callPaymentChange($operationData); - break; - case 'PaymentConfirm': - return $this->callPaymentConfirm(); - break; - case 'CalculationRequest': - return $this->callCalculationRequest($operationData); - break; - } - } - public function callCalculationRequest($operationData) { $mbHead = $this->getHead(); @@ -453,7 +421,7 @@ private function getPaymentDetails() * @return bool|array * @throws \RatePAY\Exception\ModelException */ - private function callProfileRequest($operationData) + public function callProfileRequest($operationData) { $systemId = $this->getSystemId(); $sandbox = true; @@ -561,7 +529,7 @@ private function createBasketArray($items, $type = false, $orderId = null) * @param $operationData * @return bool */ - private function callConfirmationDeliver($operationData) + public function callConfirmationDeliver($operationData) { $order = Shopware()->Models()->find('Shopware\Models\Order\Order', $operationData['orderId']); $countryCode = $order->getBilling()->getCountry()->getIso(); @@ -612,7 +580,7 @@ private function callConfirmationDeliver($operationData) return true; } elseif ($this->_retry == false && (int)$confirmationDeliver->getReasonCode() == 2300) { $this->_retry = true; - return $this->callRequest('ConfirmationDeliver', $operationData); + return $this->callConfirmationDeliver($operationData); } return false; @@ -624,7 +592,7 @@ private function callConfirmationDeliver($operationData) * @param $operationData * @return bool */ - private function callPaymentChange($operationData) + public function callPaymentChange($operationData) { $order = Shopware()->Models()->find('Shopware\Models\Order\Order', $operationData['orderId']); $countryCode = $order->getBilling()->getCountry()->getIso(); @@ -671,7 +639,7 @@ private function callPaymentChange($operationData) return true; } elseif ($this->_retry == false && (int)$paymentChange->getReasonCode() == 2300) { $this->_retry = true; - return $this->callRequest('PaymentChange', $operationData); + return $this->callPaymentChange($operationData); } return false; } diff --git a/Component/Service/OrderStatusChangeHandler.php b/Component/Service/OrderStatusChangeHandler.php index 75c1e414..b44e48f6 100644 --- a/Component/Service/OrderStatusChangeHandler.php +++ b/Component/Service/OrderStatusChangeHandler.php @@ -123,7 +123,7 @@ public function informRatepayOfOrderStatusChange(Shopware\Models\Order\Order $or $operationData['orderId'] = $order->getId(); $operationData['items'] = $items; $modelFactory->setOrderId($order->getNumber()); - $result = $modelFactory->callRequest('ConfirmationDeliver', $operationData); + $result = $modelFactory->callConfirmationDeliver($operationData); if ($result === true) { foreach ($items as $item) { @@ -146,7 +146,7 @@ public function informRatepayOfOrderStatusChange(Shopware\Models\Order\Order $or $operationData['items'] = $items; $operationData['subtype'] = 'cancellation'; $modelFactory->setOrderId($order->getNumber()); - $result = $modelFactory->callRequest('PaymentChange', $operationData); + $result = $modelFactory->callPaymentChange($operationData); if ($result === true) { foreach ($items as $item) { @@ -168,7 +168,7 @@ public function informRatepayOfOrderStatusChange(Shopware\Models\Order\Order $or $operationData['items'] = $items; $operationData['subtype'] = 'return'; $modelFactory->setOrderId($order->getNumber()); - $result = $modelFactory->callRequest('PaymentChange', $operationData); + $result = $modelFactory->callPaymentChange($operationData); if ($result === true) { foreach ($items as $item) { diff --git a/Component/Service/RatepayConfigWriter.php b/Component/Service/RatepayConfigWriter.php index 57274beb..1755e4f7 100644 --- a/Component/Service/RatepayConfigWriter.php +++ b/Component/Service/RatepayConfigWriter.php @@ -50,7 +50,7 @@ public function writeRatepayConfig($profileId, $securityCode, $shopId, $country, 'securityCode' => $securityCode ]; - $response = $factory->callRequest('ProfileRequest', $data); + $response = $factory->callProfileRequest($data); $payments = ['invoice', 'elv', 'installment']; diff --git a/Controller/backend/RpayRatepayOrderDetail.php b/Controller/backend/RpayRatepayOrderDetail.php index c1366057..36e596bb 100755 --- a/Controller/backend/RpayRatepayOrderDetail.php +++ b/Controller/backend/RpayRatepayOrderDetail.php @@ -191,7 +191,7 @@ public function deliverItemsAction() $result = false; if ($sendItem == true) { - $result = $this->_modelFactory->callRequest('ConfirmationDeliver', $operationData); + $result = $this->_modelFactory->callConfirmationDeliver($operationData); } if ($result === true || $sendItem == false) { @@ -257,7 +257,7 @@ public function cancelItemsAction() $operationData['items'] = $items; $operationData['subtype'] = 'cancellation'; $this->_modelFactory->setOrderId($order->getNumber()); - $result = $this->_modelFactory->callRequest('PaymentChange', $operationData); + $result = $this->_modelFactory->callPaymentChange($operationData); if ($result === true) { foreach ($items as $item) { @@ -318,7 +318,7 @@ public function returnItemsAction() $operationData['items'] = $items; $operationData['subtype'] = 'return'; $this->_modelFactory->setOrderId($order->getNumber()); - $result = $this->_modelFactory->callRequest('PaymentChange', $operationData); + $result = $this->_modelFactory->callPaymentChange($operationData); if ($result === true) { foreach ($items as $item) { @@ -404,7 +404,7 @@ public function addAction() ) { $result = false; } else { - $result = $this->_modelFactory->callRequest('PaymentChange', $operationData); + $result = $this->_modelFactory->callPaymentChange($operationData); } if ($result === true) { From 841e90c805cd5f9658bbfb52d8dda434b0067428 Mon Sep 17 00:00:00 2001 From: Annegret Seufert Date: Thu, 13 Sep 2018 16:11:29 +0200 Subject: [PATCH 02/21] [SHWPR-360] add payment method prepayment --- Bootstrap.php | 1 + Bootstrapping/Database/CreateConfigTable.php | 7 +++++++ Bootstrapping/Events/PaymentFilterSubscriber.php | 7 ++++++- Bootstrapping/payment_methods_install.json | 9 +++++++++ Bootstrapping/payment_methods_update.json | 9 +++++++++ Component/Mapper/ModelFactory.php | 3 ++- Component/Service/ConfigLoader.php | 3 ++- Component/Service/RatepayConfigWriter.php | 8 +++++--- Component/Service/ShopwareUtil.php | 3 +++ Component/Validation.php | 2 +- Controller/frontend/RpayRatepay.php | 4 ++-- .../backend/order/view/detail/ratepaydetailorder.js | 2 +- .../frontend/payment_rpay_part/checkout/confirm.tpl | 7 +++++++ 13 files changed, 55 insertions(+), 10 deletions(-) diff --git a/Bootstrap.php b/Bootstrap.php index a4c3c3c1..fa9571f1 100755 --- a/Bootstrap.php +++ b/Bootstrap.php @@ -31,6 +31,7 @@ public static function getPaymentMethods() 'rpayratepayrate', 'rpayratepaydebit', 'rpayratepayrate0', + 'rpayratepayprepayment', ]; } diff --git a/Bootstrapping/Database/CreateConfigTable.php b/Bootstrapping/Database/CreateConfigTable.php index 8c662a79..73f74491 100644 --- a/Bootstrapping/Database/CreateConfigTable.php +++ b/Bootstrapping/Database/CreateConfigTable.php @@ -19,6 +19,7 @@ protected function getQuery() '`installment` int(2) NOT NULL, ' . '`installment0` int(2) NOT NULL, ' . '`installmentDebit` int(2) NOT NULL, ' . + '`prepayment` int(2) NOT NULL, ' . '`device-fingerprint-status` varchar(3) NOT NULL, ' . '`device-fingerprint-snippet-id` varchar(55) NULL, ' . '`country-code-billing` varchar(30) NULL, ' . @@ -47,6 +48,12 @@ public function __invoke($database) $database->query($sql); } + $hasColumnPrepayment = ShopwareUtil::tableHasColumn('rpay_ratepay_config', 'prepayment'); + if (!$hasColumnPrepayment) { + $sql = 'ALTER TABLE rpay_ratepay_config ADD COLUMN prepayment int(2) NOT NULL'; + $database->query($sql); + } + $sql = 'ALTER TABLE rpay_ratepay_config DROP PRIMARY KEY, ADD PRIMARY KEY (shopId, country, backend);'; $database->query($sql); } diff --git a/Bootstrapping/Events/PaymentFilterSubscriber.php b/Bootstrapping/Events/PaymentFilterSubscriber.php index 7bddf3c3..79cc8db6 100644 --- a/Bootstrapping/Events/PaymentFilterSubscriber.php +++ b/Bootstrapping/Events/PaymentFilterSubscriber.php @@ -150,6 +150,11 @@ public function filterPayments(\Enlight_Event_EventArgs $arguments) $setToDefaultPayment = $paymentModel->getName() === 'rpayratepayrate0' ?: $setToDefaultPayment; continue; } + if ($payment['name'] === 'rpayratepayprepayment' && !$show['prepayment']) { + Logger::singleton()->info('RatePAY: Filter RatePAY-Prepayment'); + $setToDefaultPayment = $paymentModel->getName() === 'rpayratepayprepayment' ?: $setToDefaultPayment; + continue; + } $payments[] = $payment; } @@ -180,7 +185,7 @@ private function getRatePayPluginConfigByCountry($shopId, $country, $backend = f { $configLoader = new ConfigLoader(Shopware()->Db()); - $payments = ['installment', 'invoice', 'debit', 'installment0']; + $payments = ['installment', 'invoice', 'debit', 'installment0', 'prepayment']; $paymentConfig = []; foreach ($payments as $payment) { diff --git a/Bootstrapping/payment_methods_install.json b/Bootstrapping/payment_methods_install.json index e137ef96..244bbaa6 100644 --- a/Bootstrapping/payment_methods_install.json +++ b/Bootstrapping/payment_methods_install.json @@ -34,5 +34,14 @@ "position": 4, "additionaldescription": "Kauf per 0% Finanzierung", "template": "RatePAYRate.tpl" + }, + { + "name": "rpayratepayprepayment", + "description": "Vorkasse", + "action": "rpay_ratepay", + "active": 1, + "position": 5, + "additionaldescription": "Kauf per Vorkasse", + "template": "RatePAYPrepayment.tpl" } ] \ No newline at end of file diff --git a/Bootstrapping/payment_methods_update.json b/Bootstrapping/payment_methods_update.json index 9af8d84b..98187ece 100644 --- a/Bootstrapping/payment_methods_update.json +++ b/Bootstrapping/payment_methods_update.json @@ -7,5 +7,14 @@ "position": 4, "additionaldescription": "Kauf per 0% Finanzierung", "template": "RatePAYRate.tpl" + }, + { + "name": "rpayratepaprepayment", + "description": "Vorkasse", + "action": "rpay_ratepay", + "active": 1, + "position": 5, + "additionaldescription": "Kauf per Vorkasse", + "template": "RatePAYPrepayment.tpl" } ] \ No newline at end of file diff --git a/Component/Mapper/ModelFactory.php b/Component/Mapper/ModelFactory.php index 44f3f2a1..32286190 100755 --- a/Component/Mapper/ModelFactory.php +++ b/Component/Mapper/ModelFactory.php @@ -121,6 +121,7 @@ public function callRequest($operationType, array $operationData = []) return $this->callProfileRequest($operationData); break; case 'PaymentRequest': + Logger::singleton()->error('call'); return $this->callPaymentRequest(); break; case 'ConfirmationDeliver': @@ -266,7 +267,6 @@ public function callPaymentRequest($paymentRequestData = null, $bankData = null) } $method = $paymentRequestData->getMethod(); - if ($method == 'INSTALLMENT0') { $this->setZPercent(); //side effect $method = 'INSTALLMENT'; //state @@ -375,6 +375,7 @@ public function callPaymentRequest($paymentRequestData = null, $bankData = null) ] ]; + if (!empty($company)) { $contentArr['Customer']['CompanyName'] = $checkoutAddressBilling->getCompany(); $contentArr['Customer']['VatId'] = $checkoutAddressBilling->getVatId(); diff --git a/Component/Service/ConfigLoader.php b/Component/Service/ConfigLoader.php index 57fe3d88..e61d26ed 100644 --- a/Component/Service/ConfigLoader.php +++ b/Component/Service/ConfigLoader.php @@ -26,7 +26,8 @@ private function getPaymentMeansMap() 'rpayratepayrate' => 'installment', 'rpayratepayinvoice' => 'invoice', 'rpayratepaydebit' => 'debit', - 'rpayratepayrate0' => 'installment0' + 'rpayratepayrate0' => 'installment0', + 'rpayratepayprepayment' => 'prepayment' ]; } diff --git a/Component/Service/RatepayConfigWriter.php b/Component/Service/RatepayConfigWriter.php index 57274beb..57f12aea 100644 --- a/Component/Service/RatepayConfigWriter.php +++ b/Component/Service/RatepayConfigWriter.php @@ -52,7 +52,7 @@ public function writeRatepayConfig($profileId, $securityCode, $shopId, $country, $response = $factory->callRequest('ProfileRequest', $data); - $payments = ['invoice', 'elv', 'installment']; + $payments = ['invoice', 'elv', 'installment', 'prepayment']; if (is_array($response) && $response !== false) { foreach ($payments as $payment) { @@ -124,6 +124,7 @@ public function writeRatepayConfig($profileId, $securityCode, $shopId, $country, strtoupper($country), $response['sandbox'], $backend, + $type['prepayment'], //shopId always needs be the last line $shopId ]; @@ -132,6 +133,7 @@ public function writeRatepayConfig($profileId, $securityCode, $shopId, $country, $activePayments[] = '"rpayratepaydebit"'; $activePayments[] = '"rpayratepayrate"'; $activePayments[] = '"rpayratepayrate0"'; + $activePayments[] = '"rpayratepayprepayment"'; if (count($activePayments) > 0) { $updateSqlActivePaymentMethods = 'UPDATE `s_core_paymentmeans` SET `active` = 1 WHERE `name` in(' . implode(',', $activePayments) . ') AND `active` <> 0'; @@ -141,8 +143,8 @@ public function writeRatepayConfig($profileId, $securityCode, $shopId, $country, . '`device-fingerprint-status`, `device-fingerprint-snippet-id`,' . '`country-code-billing`, `country-code-delivery`,' . '`currency`,`country`, `sandbox`,' - . '`backend`, `shopId`)' - . 'VALUES(' . substr(str_repeat('?,', 15), 0, -1) . ');'; // In case of altering cols change 14 by amount of affected cols + . '`backend`, `prepayment`, `shopId`)' + . 'VALUES(' . substr(str_repeat('?,', 16), 0, -1) . ');'; // In case of altering cols change 14 by amount of affected cols try { $this->db->query($configSql, $data); if (count($activePayments) > 0) { diff --git a/Component/Service/ShopwareUtil.php b/Component/Service/ShopwareUtil.php index c93618c9..cc0d53c2 100755 --- a/Component/Service/ShopwareUtil.php +++ b/Component/Service/ShopwareUtil.php @@ -43,6 +43,9 @@ public static function getPaymentMethod($payment) case 'rpayratepayrate0': return 'INSTALLMENT0'; break; + case 'rpayratepayprepayment': + return 'PREPAYMENT'; + break; } } diff --git a/Component/Validation.php b/Component/Validation.php index 54ef0098..c3b0539f 100755 --- a/Component/Validation.php +++ b/Component/Validation.php @@ -111,7 +111,7 @@ public function setAllowedCountriesDelivery($countriesStr) */ public function isRatePAYPayment() { - return in_array($this->_payment->getName(), ['rpayratepayinvoice', 'rpayratepayrate', 'rpayratepaydebit', 'rpayratepayrate0']); + return in_array($this->_payment->getName(), ['rpayratepayinvoice', 'rpayratepayrate', 'rpayratepaydebit', 'rpayratepayrate0', 'rpayratepayprepayment']); } /** diff --git a/Controller/frontend/RpayRatepay.php b/Controller/frontend/RpayRatepay.php index 15dfc07e..fe9798bd 100755 --- a/Controller/frontend/RpayRatepay.php +++ b/Controller/frontend/RpayRatepay.php @@ -71,7 +71,7 @@ public function init() public function indexAction() { Shopware()->Session()->RatePAY['errorRatenrechner'] = 'false'; - if (preg_match('/^rpayratepay(invoice|rate|debit|rate0)$/', $this->getPaymentShortName())) { + if (preg_match('/^rpayratepay(invoice|rate|debit|rate0|prepayment)$/', $this->getPaymentShortName())) { if ($this->getPaymentShortName() === 'rpayratepayrate' && !isset(Shopware()->Session()->RatePAY['ratenrechner']) ) { Shopware()->Session()->RatePAY['errorRatenrechner'] = 'true'; @@ -96,7 +96,6 @@ public function indexAction() ) ); } else { - Logger::singleton()->info('proceed'); $this->_proceedPayment(); } } else { @@ -202,6 +201,7 @@ public function saveUserDataAction() */ private function _proceedPayment() { + Logger::singleton()->error('proceed'); $resultRequest = $this->_modelFactory->callPaymentRequest(); if ($resultRequest->isSuccessful()) { diff --git a/Views/backend/rpay_ratepay_orderdetail/backend/order/view/detail/ratepaydetailorder.js b/Views/backend/rpay_ratepay_orderdetail/backend/order/view/detail/ratepaydetailorder.js index 398f1404..063c7d4b 100755 --- a/Views/backend/rpay_ratepay_orderdetail/backend/order/view/detail/ratepaydetailorder.js +++ b/Views/backend/rpay_ratepay_orderdetail/backend/order/view/detail/ratepaydetailorder.js @@ -36,7 +36,7 @@ Ext.define('Shopware.apps.Order.view.detail.ratepaydetailorder', { } } - if (paymentName.search(/^rpayratepay(invoice|rate|rate0|debit)$/) != -1) { + if (paymentName.search(/^rpayratepay(invoice|rate|rate0|debit|prepayment)$/) != -1) { return true; } else { return false; diff --git a/Views/responsive/frontend/payment_rpay_part/checkout/confirm.tpl b/Views/responsive/frontend/payment_rpay_part/checkout/confirm.tpl index e196bae1..09e16a1f 100644 --- a/Views/responsive/frontend/payment_rpay_part/checkout/confirm.tpl +++ b/Views/responsive/frontend/payment_rpay_part/checkout/confirm.tpl @@ -10,6 +10,8 @@ ( $sPayment.name == 'rpayratepayrate') || ( $sPayment.name == 'rpayratepayrate0') + || + ( $sPayment.name == 'rpayratepayprepayment') )}