From 27f58d05fba3459c9efd96d92c9a78ad9484c670 Mon Sep 17 00:00:00 2001 From: Horst Fickel Date: Mon, 20 Mar 2023 11:01:56 +0100 Subject: [PATCH] compatibility update for shopware 5.7.x --- Frontend/QentaCheckoutPage/Bootstrap.php | 54 +++---- .../QentaCEE/Stdlib/Client/ClientAbstract.php | 2 +- .../Stdlib/Response/ResponseAbstract.php | 2 + .../Frontend/QentaCheckoutPage.php | 133 ++++++++++-------- Frontend/QentaCheckoutPage/Models/Config.php | 2 +- Frontend/QentaCheckoutPage/Models/Page.php | 64 ++++----- .../QentaCheckoutPage/Models/Resources.php | 8 +- .../QentaCheckoutPage/Models/Transaction.php | 2 +- README.md | 4 +- 9 files changed, 147 insertions(+), 124 deletions(-) diff --git a/Frontend/QentaCheckoutPage/Bootstrap.php b/Frontend/QentaCheckoutPage/Bootstrap.php index 1a84f03..bc973e9 100755 --- a/Frontend/QentaCheckoutPage/Bootstrap.php +++ b/Frontend/QentaCheckoutPage/Bootstrap.php @@ -71,7 +71,7 @@ public function getCapabilities() */ public function getVersion() { - return '2.0.1'; + return '2.0.2'; } /** @@ -116,7 +116,7 @@ public function install() { $this->createForm(); $this->createTranslations(); - foreach (Shopware()->QentaCheckoutPage()->getConfig()->getDbTables() as $sql) { + foreach (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->getDbTables() as $sql) { Shopware()->Db()->exec($sql); } @@ -746,7 +746,7 @@ public function addLessFiles(Enlight_Event_EventArgs $args) */ protected function createPayments() { - $oConfig = Shopware()->QentaCheckoutPage()->getConfig(); + $oConfig = Shopware()->Container()->get('QentaCheckoutPage')->getConfig(); $prefixName = $oConfig->getPrefix('name'); @@ -770,7 +770,7 @@ protected function createPayments() $aTranslations = array(); $i = 80; - foreach (Shopware()->QentaCheckoutPage()->getPaymentMethods()->getList() as $pm) { + foreach (Shopware()->Container()->get('QentaCheckoutPage')->getPaymentMethods()->getList() as $pm) { $oPayment = $this->Payments()->findOneBy(array('name' => $prefixName . $pm['name'])); if(!$oPayment) { $payment = array( @@ -825,9 +825,9 @@ public function pluginConfig() public static function init() { // Register resource QentaCheckoutPage - // The instance is available with Shopware()->QentaCheckoutPage() - if (!Shopware()->Bootstrap()->issetResource('QentaCheckoutPage')) { - Shopware()->Bootstrap()->registerResource( + // The instance is available with Shopware()->Container()->get('QentaCheckoutPage') + if (!Shopware()->Container()->initialized('QentaCheckoutPage')) { + Shopware()->Container()->set( 'QentaCheckoutPage', new Shopware_Plugins_Frontend_QentaCheckoutPage_Models_Resources() ); @@ -864,7 +864,7 @@ public static function onGetControllerPathFrontend(Enlight_Event_EventArgs $args */ public function getPayolutionLink() { - $mid = Shopware()->QentaCheckoutPage()->getConfig()->PAYOLUTION_MID; + $mid = Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->PAYOLUTION_MID; if (strlen($mid) === 0) { return false; } @@ -917,7 +917,7 @@ public function onPreDispatch(Enlight_Event_EventArgs $args) $financialInstitution = $args->getSubject()->Request()->get('financialInstitution'); if (isset($financialInstitution)) { self::init(); - Shopware()->QentaCheckoutPage()->financialInstitution = $financialInstitution; + Shopware()->Container()->get('QentaCheckoutPage')->financialInstitution = $financialInstitution; } $birthDate = $args->getSubject()->Request()->get('birthdate'); if (!empty($birthDate)) { @@ -965,7 +965,7 @@ public function onPostDispatch(Enlight_Event_EventArgs $args) $view->addTemplateDir($this->Path() . 'Views/responsive/'); // Output of common errors - if (null != Shopware()->QentaCheckoutPage()->qenta_action) { + if (null != Shopware()->Container()->get('QentaCheckoutPage')->qenta_action) { self::showErrorMessages($view); } break; @@ -975,7 +975,7 @@ public function onPostDispatch(Enlight_Event_EventArgs $args) $view->addTemplateDir($this->Path() . 'Views/responsive/'); // Output of common errors - if (null != Shopware()->QentaCheckoutPage()->qenta_action) { + if (null != Shopware()->Container()->get('QentaCheckoutPage')->qenta_action) { self::showErrorMessages($view); } @@ -984,18 +984,18 @@ public function onPostDispatch(Enlight_Event_EventArgs $args) $view->paymentDesc = Shopware()->Session()->sOrderVariables['sUserData']['additional']['payment']['description']; $view->paymentName = $paymentName; $view->paymentLogo = 'frontend/_public/images/' . $paymentName . '.png'; - $view->financialInstitutionSelectionEnabled = Shopware()->QentaCheckoutPage()->getConfig()->FINANCIAL_INSTITUTION_SELECTION_ENABLED; + $view->financialInstitutionSelectionEnabled = Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->FINANCIAL_INSTITUTION_SELECTION_ENABLED; if(Shopware()->Session()->offsetGet('qcpConsumerDeviceId') != null) { $consumerDeviceId = Shopware()->Session()->offsetGet('qcpConsumerDeviceId'); } else { $timestamp = microtime(); - $consumerDeviceId = md5(Shopware()->QentaCheckoutPage()->getConfig()->customerid . "_" . $timestamp); + $consumerDeviceId = md5(Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->customerid . "_" . $timestamp); Shopware()->Session()->offsetSet('qcpConsumerDeviceId', $consumerDeviceId); } - $paymentName = Shopware()->QentaCheckoutPage()->getPaymentShortName(); - if ((Shopware()->QentaCheckoutPage()->getConfig()->INVOICE_PROVIDER == 'ratepay' && $paymentName == 'qcp_invoice') || - (Shopware()->QentaCheckoutPage()->getConfig()->INSTALLMENT_PROVIDER == 'ratepay' && $paymentName == 'qcp_installment')) { + $paymentName = Shopware()->Container()->get('QentaCheckoutPage')->getPaymentShortName(); + if ((Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INVOICE_PROVIDER == 'ratepay' && $paymentName == 'qcp_invoice') || + (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INSTALLMENT_PROVIDER == 'ratepay' && $paymentName == 'qcp_installment')) { $ratepay = ''; $ratepay .= ''; $ratepay .= ''; @@ -1029,11 +1029,11 @@ public function onPostDispatch(Enlight_Event_EventArgs $args) $view->bMonth = $birthday[1]; $view->bDay = $birthday[2]; - if ((Shopware()->QentaCheckoutPage()->getConfig()->INVOICE_PROVIDER == 'payolution' && $paymentName == 'INVOICE') || - (Shopware()->QentaCheckoutPage()->getConfig()->INSTALLMENT_PROVIDER == 'payolution' && $paymentName == 'INSTALLMENT') + if ((Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INVOICE_PROVIDER == 'payolution' && $paymentName == 'INVOICE') || + (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INSTALLMENT_PROVIDER == 'payolution' && $paymentName == 'INSTALLMENT') ) { - $view->payolutionTerms = Shopware()->QentaCheckoutPage()->getConfig()->PAYOLUTION_TERMS; - if (Shopware()->QentaCheckoutPage()->getConfig()->PAYOLUTION_TERMS) { + $view->payolutionTerms = Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->PAYOLUTION_TERMS; + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->PAYOLUTION_TERMS) { $view->qcpPayolutionLink1 = ''; $view->qcpPayolutionLink2 = ''; } @@ -1041,7 +1041,7 @@ public function onPostDispatch(Enlight_Event_EventArgs $args) $view->epsFinancialInstitutions = QentaCEE_QPay_PaymentType::getFinancialInstitutions('EPS'); $view->idlFinancialInstitutions = QentaCEE_QPay_PaymentType::getFinancialInstitutions('IDL'); - $view->financialInstitutionsSelected = Shopware()->QentaCheckoutPage()->financialInstitution; + $view->financialInstitutionsSelected = Shopware()->Container()->get('QentaCheckoutPage')->financialInstitution; break; @@ -1070,7 +1070,7 @@ private function isActivePayment($paymentName) { switch ($paymentName) { case 'qcp_invoice': - $currencies = Shopware()->QentaCheckoutPage()->getConfig()->INVOICE_CURRENCY; + $currencies = Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INVOICE_CURRENCY; if (isset($currencies)) { $currentCurrency = Shopware()->Shop()->getCurrency()->getCurrency(); @@ -1086,7 +1086,7 @@ private function isActivePayment($paymentName) return true; case 'qcp_installment': - $currencies = Shopware()->QentaCheckoutPage()->getConfig()->INSTALLMENT_CURRENCY; + $currencies = Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INSTALLMENT_CURRENCY; if (isset($currencies)) { $currentCurrency = Shopware()->Shop()->getCurrency()->getCurrency(); @@ -1136,10 +1136,10 @@ protected function hidePayment($payments, $paymentName) */ protected static function showErrorMessages($view) { - $view->qenta_error = Shopware()->QentaCheckoutPage()->qenta_action; - $view->qenta_message = Shopware()->QentaCheckoutPage()->qenta_message; - Shopware()->QentaCheckoutPage()->qenta_action = null; - Shopware()->QentaCheckoutPage()->qenta_message = null; + $view->qenta_error = Shopware()->Container()->get('QentaCheckoutPage')->qenta_action; + $view->qenta_message = Shopware()->Container()->get('QentaCheckoutPage')->qenta_message; + Shopware()->Container()->get('QentaCheckoutPage')->qenta_action = null; + Shopware()->Container()->get('QentaCheckoutPage')->qenta_message = null; } /** diff --git a/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Client/ClientAbstract.php b/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Client/ClientAbstract.php index 042bf69..551aa4e 100644 --- a/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Client/ClientAbstract.php +++ b/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Client/ClientAbstract.php @@ -402,7 +402,7 @@ protected function _sendRequest() $httpClient = $this->_getHttpClient(); $request = $httpClient->post($this->_getRequestUrl(), [ - 'body' => $this->_requestData, + 'form_params' => $this->_requestData, 'headers' => [ 'User-Agent' => $this->getUserAgentString() ] diff --git a/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Response/ResponseAbstract.php b/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Response/ResponseAbstract.php index 76842dc..6cdd23b 100644 --- a/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Response/ResponseAbstract.php +++ b/Frontend/QentaCheckoutPage/Components/QentaCEE/Stdlib/Response/ResponseAbstract.php @@ -104,6 +104,8 @@ public function __construct($response) { if ($response instanceof Response) { $this->_response = QentaCEE_Stdlib_SerialApi::decode($response->getBody()); + } elseif ($response instanceof \GuzzleHttp\Psr7\Response) { + $this->_response = QentaCEE_Stdlib_SerialApi::decode($response->getBody()->getContents()); } elseif (is_array($response)) { $this->_response = $response; } else { diff --git a/Frontend/QentaCheckoutPage/Controllers/Frontend/QentaCheckoutPage.php b/Frontend/QentaCheckoutPage/Controllers/Frontend/QentaCheckoutPage.php index 298b4f7..5bb2b26 100644 --- a/Frontend/QentaCheckoutPage/Controllers/Frontend/QentaCheckoutPage.php +++ b/Frontend/QentaCheckoutPage/Controllers/Frontend/QentaCheckoutPage.php @@ -60,9 +60,9 @@ public function indexAction() } /** @var Shopware_Plugins_Frontend_QentaCheckoutPage_Models_Page $oPageModel */ - $oPageModel = Shopware()->QentaCheckoutPage()->getPage(); + $oPageModel = Shopware()->Container()->get('QentaCheckoutPage')->getPage(); - $sPaymentType = Shopware()->QentaCheckoutPage()->getPaymentShortName(); + $sPaymentType = Shopware()->Container()->get('QentaCheckoutPage')->getPaymentShortName(); $fAmount = $this->getAmount(); $sCurrency = $this->getCurrencyShortName(); @@ -83,16 +83,16 @@ public function indexAction() ); $aParams = Array( - 'sCoreId' => Shopware()->SessionID(), + 'sCoreId' => Shopware()->Session()->get('sessionId'), '__shop' => Shopware()->Shop()->getId(), - 'wQentaCheckoutPageId' => Shopware()->QentaCheckoutPage()->getTransactionId(), - 'displayText' => Shopware()->QentaCheckoutPage()->getConfig()->display_text + 'wQentaCheckoutPageId' => Shopware()->Container()->get('QentaCheckoutPage')->getTransactionId(), + 'displayText' => Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->display_text ); $checkoutUrl = $this->Front()->Router()->assemble( Array('controller' => 'checkout', 'action' => 'confirm', 'sUseSSL' => true) ); - $bUseIframe = (Shopware()->QentaCheckoutPage()->getConfig()->use_iframe == 1); + $bUseIframe = (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->use_iframe == 1); $sOrderVariables = Shopware()->Session()->sOrderVariables; $existingOrder = Shopware()->Models()->getRepository('Shopware\Models\Order\Order')->findByNumber($sOrderVariables['sOrderNumber']); @@ -102,11 +102,11 @@ public function indexAction() } else { /** @var Shopware_Plugins_Frontend_QentaCheckoutPage_Models_Transaction $oTransaction */ - $oTransaction = Shopware()->QentaCheckoutPage()->getTransaction(); + $oTransaction = Shopware()->Container()->get('QentaCheckoutPage')->getTransaction(); $oTransaction->create($aParams['wQentaCheckoutPageId'], $oTransaction->generateHash($aParams['wQentaCheckoutPageId'], $fAmount, $sCurrency), - Shopware()->QentaCheckoutPage()->getPaymentShortName(), + Shopware()->Container()->get('QentaCheckoutPage')->getPaymentShortName(), $_SESSION); $oResponse = $oPageModel->initiatePayment($sPaymentType, $fAmount, $sCurrency, $sReturnUrl, $sConfigmrUrl, $aParams); @@ -117,9 +117,9 @@ public function indexAction() if($oResponse->hasFailed()) { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: '. __METHOD__ . ':' . $oResponse->getError()); - Shopware()->QentaCheckoutPage()->qenta_message = $oResponse->getError(); - Shopware()->QentaCheckoutPage()->qenta_action = 'failure'; + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: '. __METHOD__ . ':' . $oResponse->getError()->getConsumerMessage()); + Shopware()->Container()->get('QentaCheckoutPage')->qenta_message = $oResponse->getError()->getConsumerMessage(); + Shopware()->Container()->get('QentaCheckoutPage')->qenta_action = 'failure'; //if an error occurs we should not show followup page in iframe. $bUseIframe = false; $sRedirectUrl = $checkoutUrl; @@ -151,17 +151,18 @@ public function indexAction() public function confirmAction() { /** @var Shopware_Plugins_Frontend_QentaCheckoutPage_Models_Transaction $oTransaction */ - $oTransaction = Shopware()->QentaCheckoutPage()->getTransaction(); + $oTransaction = Shopware()->Container()->get('QentaCheckoutPage')->getTransaction(); try { Shopware()->Plugins()->Controller()->ViewRenderer()->setNoRender(); $post = $this->Request()->getPost(); - Shopware()->Pluginlogger()->info('QentaCheckoutPage: ' . __METHOD__ . '--' . __LINE__ . ':' . print_r($post, + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: ' . __METHOD__ . '--' . __LINE__ . ':' . print_r($post, 1)); $paymentUniqueId = $this->Request()->getParam('wQentaCheckoutPageId'); - if (Shopware()->QentaCheckoutPage()->getConfig()->setAsTransactionID() == 'gatewayReferenceNumber') { + $sCoreId = $this->Request()->getParam('sCoreId'); + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->setAsTransactionID() == 'gatewayReferenceNumber') { $sTransactionIdField = 'gatewayReferenceNumber'; } else { $sTransactionIdField = 'orderNumber'; @@ -170,28 +171,32 @@ public function confirmAction() $transactionData = $oTransaction->read($paymentUniqueId); if (!is_array($transactionData)) { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: ' . __METHOD__ . ':invalid transaction data'); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: ' . __METHOD__ . ':invalid transaction data'); die(QentaCEE_QPay_ReturnFactory::generateConfirmResponseString('invalid transaction data')); } $sessionData = unserialize($transactionData['session']); if($sessionData === false) { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: '. __METHOD__ . ':Validation error: invalid session data'); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: '. __METHOD__ . ':Validation error: invalid session data'); die(QentaCEE_QPay_ReturnFactory::generateConfirmResponseString('Validation error: invalid session data')); } // restore session $_SESSION = $sessionData; + if (is_array($sessionData) && isset($sessionData['Shopware'])) { + Shopware()->Session()->offsetSet('sOrderVariables', $sessionData['Shopware']['sOrderVariables']); + Shopware()->Session()->offsetSet('sQentaConfirmMail', $sessionData['Shopware']['sQentaConfirmMail']); + } // restore remote address $_SERVER['REMOTE_ADDR'] = $transactionData['remoteAddr']; $return = QentaCEE_QPay_ReturnFactory::getInstance($post, - Shopware()->QentaCheckoutPage()->getConfig()->SECRET); - $paymentState = Shopware()->QentaCheckoutPage()->getPaymentStatusId($return->getPaymentState()); + Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->SECRET); + $paymentState = Shopware()->Container()->get('QentaCheckoutPage')->getPaymentStatusId($return->getPaymentState()); if ( ! $return->validate()) { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: ' . __METHOD__ . ':Validation error: invalid response'); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: ' . __METHOD__ . ':Validation error: invalid response'); die(QentaCEE_QPay_ReturnFactory::generateConfirmResponseString('Validation error: invalid response')); } @@ -238,10 +243,15 @@ public function confirmAction() $sOrderNumber, $paymentUniqueId, $paymentState)); } + Shopware()->Container()->get('dbal_connection')->delete( + 's_order', + ['temporaryID' => $sCoreId, 'ordernumber' => '0'] + ); + $update['orderId'] = $sOrderNumber; } - if (Shopware()->QentaCheckoutPage()->getConfig()->saveResponseTo()) { + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->saveResponseTo()) { $this->saveComments($return, Shopware()->Session()->sOrderVariables['sOrderNumber']); } break; @@ -251,7 +261,7 @@ public function confirmAction() //Set qentaState for pending mail check Shopware()->Session()->sOrderVariables['qentaState'] = 'pending'; $sendMail = false; - if (Shopware()->QentaCheckoutPage()->getConfig()->SEND_PENDING_MAILS) { + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->SEND_PENDING_MAILS) { $sendMail = true; } $sOrderNumber = $this->saveOrder( @@ -266,9 +276,14 @@ public function confirmAction() $sOrderNumber, $paymentUniqueId, $paymentState)); } + Shopware()->Container()->get('dbal_connection')->delete( + 's_order', + ['temporaryID' => $sCoreId, 'ordernumber' => '0'] + ); + $update['orderId'] = $sOrderNumber; - if (Shopware()->QentaCheckoutPage()->getConfig()->saveResponseTo()) { + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->saveResponseTo()) { $this->saveComments($return, Shopware()->Session()->sOrderVariables['sOrderNumber']); } break; @@ -276,12 +291,12 @@ public function confirmAction() $sOrderVariables = Shopware()->Session()->sOrderVariables; $existingOrder = Shopware()->Models()->getRepository('Shopware\Models\Order\Order')->findByNumber($sOrderVariables['sOrderNumber']); - if (($existingOrder[0] instanceof \Shopware\Models\Order\Order) && $existingOrder[0]->getPaymentStatus()->getId() !== Shopware()->QentaCheckoutPage()->getPaymentStatusId(QentaCEE_QPay_ReturnFactory::STATE_PENDING)) { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: ' . __METHOD__ . ': do not modify payment status as the order is in a final state!'); + if (($existingOrder[0] instanceof \Shopware\Models\Order\Order) && $existingOrder[0]->getPaymentStatus()->getId() !== Shopware()->Container()->get('QentaCheckoutPage')->getPaymentStatusId(QentaCEE_QPay_ReturnFactory::STATE_PENDING)) { + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: ' . __METHOD__ . ': do not modify payment status as the order is in a final state!'); die(QentaCEE_QPay_ReturnFactory::generateConfirmResponseString('Can not overwrite payment status as the order is in a final state!')); } else if ($existingOrder[0] instanceof \Shopware\Models\Order\Order) { $status = $existingOrder[0]->getPaymentStatus(); - if ($status->getId() === Shopware()->QentaCheckoutPage()->getPaymentStatusId(QentaCEE_QPay_ReturnFactory::STATE_PENDING)) { + if ($status->getId() === Shopware()->Container()->get('QentaCheckoutPage')->getPaymentStatusId(QentaCEE_QPay_ReturnFactory::STATE_PENDING)) { // save existing order for failed payment $sOrderNumber = $this->savePaymentStatus( $transactionId, @@ -310,7 +325,7 @@ public function confirmAction() $oTransaction->update($paymentUniqueId, $update); } catch (Exception $e) { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: ' . __METHOD__ . '.--' . __LINE__ . ':' . $e->getMessage()); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: ' . __METHOD__ . '.--' . __LINE__ . ':' . $e->getMessage()); die(QentaCEE_QPay_ReturnFactory::generateConfirmResponseString(htmlspecialchars($e->getMessage()))); } @@ -325,12 +340,13 @@ public function returnAction() $paymentUniqueId = $this->Request()->getParam('wQentaCheckoutPageId'); /** @var Shopware_Plugins_Frontend_QentaCheckoutPage_Models_Transaction $oTransaction */ - $oTransaction = Shopware()->QentaCheckoutPage()->getTransaction(); + $oTransaction = Shopware()->Container()->get('QentaCheckoutPage')->getTransaction(); $transactionData = $oTransaction->read($paymentUniqueId); // write back modified sessiondata, might be modified by the confirm (server2server) request $savedSessionData = unserialize($transactionData['session']); if (is_array($savedSessionData) && isset($savedSessionData['Shopware'])) { + //$_SESSION = $savedSessionData; Shopware()->Session()->offsetSet('sOrderVariables', $savedSessionData['Shopware']['sOrderVariables']); Shopware()->Session()->offsetSet('sQentaConfirmMail', $savedSessionData['Shopware']['sQentaConfirmMail']); } @@ -342,61 +358,66 @@ public function returnAction() $result->cleared = false; } $post = $this->Request()->getPost(); - Shopware()->Pluginlogger()->info('QentaCheckoutPage: '.__METHOD__ . '--' . __LINE__ . ':' . print_r($post, 1)); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: '.__METHOD__ . '--' . __LINE__ . ':' . print_r($post, 1)); try { $return = QentaCEE_QPay_ReturnFactory::getInstance( $post, - Shopware()->QentaCheckoutPage()->getConfig()->SECRET + Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->SECRET ); switch ($return->getPaymentState()) { case QentaCEE_QPay_ReturnFactory::STATE_SUCCESS: /** @var $return QentaCEE_QPay_Return_Success */ - $sRedirectUrl = $this->Front()->Router()->assemble( - Array('controller' => 'checkout', 'action' => 'finish', 'sUseSSL' => true) - ); + + Shopware()->Modules()->Basket()->sDeleteBasket(); + $sRedirectUrl = $this->Front()->Router()->assemble( + Array('module' => 'frontend', 'controller' => 'checkout', 'action' => 'finish', 'sUseSSL' => true, 'sUniqueID' => $paymentUniqueId) + ); break; case QentaCEE_QPay_ReturnFactory::STATE_PENDING: /** @var $return QentaCEE_QPay_Return_Pending */ - $sRedirectUrl = $this->Front()->Router()->assemble( - Array('controller' => 'checkout', 'action' => 'finish', 'sUseSSL' => true, 'ispending' => true) - ); + + Shopware()->Modules()->Basket()->sDeleteBasket(); + $sRedirectUrl = $this->Front()->Router()->assemble( + Array('module' => 'frontend', 'controller' => 'checkout', 'action' => 'finish', 'sUseSSL' => true, 'ispending' => true, 'sUniqueID' => $paymentUniqueId) + ); break; case QentaCEE_QPay_ReturnFactory::STATE_CANCEL: /** @var $return QentaCEE_QPay_Return_Cancel */ + if(isset($_SESSION["qcp_redirect_url"])) { unset($_SESSION["qcp_redirect_url"]); } - $sRedirectUrl = $this->Front()->Router()->assemble( - Array('controller' => 'checkout', 'action' => 'confirm', 'sUseSSL' => true) - ); - Shopware()->QentaCheckoutPage()->qenta_action = 'cancel'; + $sRedirectUrl = $this->Front()->Router()->assemble( + Array('controller' => 'checkout', 'action' => 'confirm', 'sUseSSL' => true) + ); + Shopware()->Container()->get('QentaCheckoutPage')->qenta_action = 'cancel'; break; case QentaCEE_QPay_ReturnFactory::STATE_FAILURE: default: /** @var $return QentaCEE_QPay_Return_Failure */ - if(isset($_SESSION["qcp_redirect_url"])) { - unset($_SESSION["qcp_redirect_url"]); - } - Shopware()->QentaCheckoutPage()->qenta_message = $return->getErrors()->getConsumerMessage(); - Shopware()->QentaCheckoutPage()->qenta_action = 'external_error'; - $sRedirectUrl = $this->Front()->Router()->assemble( - Array('controller' => 'checkout', 'action' => 'confirm', 'sUseSSL' => true) - ); - } + if(isset($_SESSION["qcp_redirect_url"])) { + unset($_SESSION["qcp_redirect_url"]); + } + Shopware()->Container()->get('QentaCheckoutPage')->qenta_message = $return->getErrors()->getConsumerMessage(); + Shopware()->Container()->get('QentaCheckoutPage')->qenta_action = 'external_error'; + $sRedirectUrl = $this->Front()->Router()->assemble( + Array('controller' => 'checkout', 'action' => 'confirm', 'sUseSSL' => true) + ); + } } catch (Exception $e) { - Shopware()->Pluginlogger()->error('QentaCheckoutPage: '.__METHOD__ . ':' . $e->getMessage()); - Shopware()->QentaCheckoutPage()->qenta_action = 'failure'; + Shopware()->Container()->get('pluginlogger')->error('QentaCheckoutPage: '.__METHOD__ . ':' . $e->getMessage()); + Shopware()->Container()->get('QentaCheckoutPage')->qenta_action = 'failure'; } //reset transactionId - Shopware()->QentaCheckoutPage()->transactionId = null; + Shopware()->Container()->get('QentaCheckoutPage')->transactionId = null; - $bUseIframe = (Shopware()->QentaCheckoutPage()->getConfig()->use_iframe == 1); + $bUseIframe = (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->use_iframe == 1); if($bUseIframe) { @@ -435,11 +456,11 @@ protected function saveComments(QentaCEE_Stdlib_Return_ReturnAbstract $return = - $field = Shopware()->QentaCheckoutPage()->getConfig()->saveResponseTo(); - Shopware()->Pluginlogger()->info('QentaCheckoutPage: Comment field:' . $field); + $field = Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->saveResponseTo(); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: Comment field:' . $field); if ($field == 'internalcomment') { - Shopware()->Pluginlogger()->info('QentaCheckoutPage: Saving internal comment'); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: Saving internal comment'); Shopware()->Db()->update( 's_order', array($field => implode("\n", $comments)), @@ -451,7 +472,7 @@ protected function saveComments(QentaCEE_Stdlib_Return_ReturnAbstract $return = ->where('ordernumber = ?', array($orderNumber)); $orderId = Shopware()->Db()->fetchOne($sql); - Shopware()->Pluginlogger()->info('QentaCheckoutPage: Saving attribute'); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: Saving attribute'); Shopware()->Db()->update( 's_order_attributes', array($field => implode("\n", $comments)), diff --git a/Frontend/QentaCheckoutPage/Models/Config.php b/Frontend/QentaCheckoutPage/Models/Config.php index 7576f74..d68c14e 100644 --- a/Frontend/QentaCheckoutPage/Models/Config.php +++ b/Frontend/QentaCheckoutPage/Models/Config.php @@ -71,7 +71,7 @@ public function getImageUrl() */ public function getLanguage() { - return Shopware()->Locale()->getLanguage(); + return substr(Shopware()->Container()->get('shop')->getLocale()->getLocale(), 0, 2); } public function getPrefix($type) diff --git a/Frontend/QentaCheckoutPage/Models/Page.php b/Frontend/QentaCheckoutPage/Models/Page.php index aa8563d..3bd091b 100644 --- a/Frontend/QentaCheckoutPage/Models/Page.php +++ b/Frontend/QentaCheckoutPage/Models/Page.php @@ -48,13 +48,13 @@ protected function getFrontendClient(Shopware_Plugins_Frontend_QentaCheckoutPage 'CUSTOMER_ID' => $oConfig->customerid, 'SHOP_ID' => $oConfig->shopid, 'SECRET' => $oConfig->secret, - 'LANGUAGE' => Shopware()->Locale()->getLanguage() + 'LANGUAGE' => substr(Shopware()->Container()->get('shop')->getLocale()->getLocale(), 0, 2) )); $oInit->setPluginVersion($this->getPluginVersion()); $oInit->setMaxRetries($oConfig->max_retries); - $oInit->setOrderReference(Shopware()->QentaCheckoutPage()->getOrderReference()); - $oInit->setOrderDescription(Shopware()->QentaCheckoutPage()->getOrderDescription()); + $oInit->setOrderReference(Shopware()->Container()->get('QentaCheckoutPage')->getOrderReference()); + $oInit->setOrderDescription(Shopware()->Container()->get('QentaCheckoutPage')->getOrderDescription()); $oInit->setImageUrl($oConfig->getImageUrl()); $oInit->setServiceUrl($oConfig->service_url); @@ -76,14 +76,14 @@ protected function getFrontendClient(Shopware_Plugins_Frontend_QentaCheckoutPage */ public function initiatePayment($paymentType, $amount, $currency, $returnUrl, $confimUrl, $params = array()) { - $oFrontendClient = $this->getFrontendClient(Shopware()->QentaCheckoutPage()->getConfig()); - if (Shopware()->QentaCheckoutPage()->getConfig()->FINANCIAL_INSTITUTION_SELECTION_ENABLED + $oFrontendClient = $this->getFrontendClient(Shopware()->Container()->get('QentaCheckoutPage')->getConfig()); + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->FINANCIAL_INSTITUTION_SELECTION_ENABLED && in_array(strtolower($paymentType), - Shopware()->QentaCheckoutPage()->getConfig()->getPaymentsFinancialInstitution()) + Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->getPaymentsFinancialInstitution()) ) { - $oFrontendClient->setFinancialInstitution(Shopware()->QentaCheckoutPage()->financialInstitution); + $oFrontendClient->setFinancialInstitution(Shopware()->Container()->get('QentaCheckoutPage')->financialInstitution); } - $email = (string) Shopware()->QentaCheckoutPage()->getUser('user')->email; + $email = (string) Shopware()->Container()->get('QentaCheckoutPage')->getUser('user')->email; $oFrontendClient->setPaymentType($paymentType) ->setAmount($amount) @@ -106,19 +106,19 @@ public function initiatePayment($paymentType, $amount, $currency, $returnUrl, $c if ($paymentType == \QentaCEE_QPay_PaymentType::MASTERPASS) { $oFrontendClient->setShippingProfile('NO_SHIPPING'); } - if (Shopware()->QentaCheckoutPage()->getConfig()->SEND_BASKET_DATA - || ($paymentType == QentaCEE_QPay_PaymentType::INVOICE && Shopware()->QentaCheckoutPage()->getConfig()->INVOICE_PROVIDER != 'payolution') - || ($paymentType == QentaCEE_QPay_PaymentType::INSTALLMENT && Shopware()->QentaCheckoutPage()->getConfig()->INSTALLMENT_PROVIDER != 'payolution') + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->SEND_BASKET_DATA + || ($paymentType == QentaCEE_QPay_PaymentType::INVOICE && Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INVOICE_PROVIDER != 'payolution') + || ($paymentType == QentaCEE_QPay_PaymentType::INSTALLMENT && Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->INSTALLMENT_PROVIDER != 'payolution') ) { $oFrontendClient->setBasket($this->getShoppingBasket()); } - if (Shopware()->QentaCheckoutPage()->getConfig()->ENABLE_DUPLICATE_REQUEST_CHECK){ + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->ENABLE_DUPLICATE_REQUEST_CHECK){ $oFrontendClient->setDuplicateRequestCheck(true); } $customerStatement = sprintf('%9s', substr(Shopware()->Config()->get('ShopName'), 0, 9)); if ($paymentType != \QentaCEE_QPay_PaymentType::POLI) { - $customerStatement .= ' ' . Shopware()->QentaCheckoutPage()->wQentaCheckoutPageId; + $customerStatement .= ' ' . Shopware()->Container()->get('QentaCheckoutPage')->wQentaCheckoutPageId; } $oFrontendClient->setCustomerStatement($customerStatement); @@ -126,14 +126,14 @@ public function initiatePayment($paymentType, $amount, $currency, $returnUrl, $c foreach ($params as $k => $v) $oFrontendClient->$k = $v; - Shopware()->Pluginlogger()->info('QentaCheckoutPage: '.__METHOD__ . ':' . print_r($oFrontendClient->getRequestData(),true)); + Shopware()->Container()->get('pluginlogger')->info('QentaCheckoutPage: '.__METHOD__ . ':' . print_r($oFrontendClient->getRequestData(),true)); try { return $oFrontendClient->initiate(); } catch (\Exception $e) { - Shopware()->Pluginlogger()->error('QentaCheckoutPage: '.__METHOD__ . ':' . $e->getMessage()); - Shopware()->QentaCheckoutPage()->qenta_action = 'failure'; - Shopware()->QentaCheckoutPage()->qenta_message = $e->getMessage(); + Shopware()->Container()->get('pluginlogger')->error('QentaCheckoutPage: '.__METHOD__ . ':' . $e->getMessage()); + Shopware()->Container()->get('QentaCheckoutPage')->qenta_action = 'failure'; + Shopware()->Container()->get('QentaCheckoutPage')->qenta_message = $e->getMessage(); } return null; @@ -151,11 +151,11 @@ protected function getPluginVersion() if(defined('Shopware::VERSION')){ $shopversion = Shopware::VERSION; } else { - $shopversion = \PackageVersions\Versions::getVersion('shopware/shopware'); + $shopversion = Shopware()->Container()->get('shopware.release')->getVersion(); } if ( ! strlen($shopversion)) { - $shopversion = '>5.2.21'; + $shopversion = '>5.7.0'; } return QentaCEE_QPay_FrontendClient::generatePluginVersion( @@ -173,9 +173,9 @@ protected function getPluginVersion() public function getUserDescription() { return sprintf('%s %s %s', - Shopware()->QentaCheckoutPage()->getUser('user')->email, - Shopware()->QentaCheckoutPage()->getUser('billingaddress')->firstname, - Shopware()->QentaCheckoutPage()->getUser('billingaddress')->lastname + Shopware()->Container()->get('QentaCheckoutPage')->getUser('user')->email, + Shopware()->Container()->get('QentaCheckoutPage')->getUser('billingaddress')->firstname, + Shopware()->Container()->get('QentaCheckoutPage')->getUser('billingaddress')->lastname ); } @@ -191,12 +191,12 @@ public function getConsumerData($paymentType) $consumerData->setIpAddress($_SERVER['REMOTE_ADDR']); $consumerData->setUserAgent($_SERVER['HTTP_USER_AGENT']); - if (Shopware()->QentaCheckoutPage()->getConfig()->send_additional_data + if (Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->send_additional_data || $paymentType == QentaCEE_QPay_PaymentType::INSTALLMENT || $paymentType == QentaCEE_QPay_PaymentType::INVOICE || $paymentType == QentaCEE_QPay_PaymentType::P24 ) { - $consumerData->setEmail(Shopware()->QentaCheckoutPage()->getUser('user')->email); + $consumerData->setEmail(Shopware()->Container()->get('QentaCheckoutPage')->getUser('user')->email); $consumerData->addAddressInformation($this->getAddress('billing')); $consumerData->addAddressInformation($this->getAddress('shipping')); @@ -232,18 +232,18 @@ protected function getAddress($type = 'billing') $address = new QentaCEE_Stdlib_ConsumerData_Address(QentaCEE_Stdlib_ConsumerData_Address::TYPE_BILLING); break; } - $address->setFirstname(Shopware()->QentaCheckoutPage()->getUser($prefix)->firstname); - $address->setLastname(Shopware()->QentaCheckoutPage()->getUser($prefix)->lastname); - $address->setAddress1(Shopware()->QentaCheckoutPage()->getUser($prefix)->street . ' ' . Shopware()->QentaCheckoutPage()->getUser($prefix)->streetnumber); - $address->setZipCode(Shopware()->QentaCheckoutPage()->getUser($prefix)->zipcode); - $address->setCity(Shopware()->QentaCheckoutPage()->getUser($prefix)->city); + $address->setFirstname(Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->firstname); + $address->setLastname(Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->lastname); + $address->setAddress1(Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->street . ' ' . Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->streetnumber); + $address->setZipCode(Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->zipcode); + $address->setCity(Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->city); switch ($type) { case 'billing': - $address->setCountry(Shopware()->QentaCheckoutPage()->getUser('country')->countryiso); - $address->setPhone(Shopware()->QentaCheckoutPage()->getUser($prefix)->phone); + $address->setCountry(Shopware()->Container()->get('QentaCheckoutPage')->getUser('country')->countryiso); + $address->setPhone(Shopware()->Container()->get('QentaCheckoutPage')->getUser($prefix)->phone); break; case 'shipping': - $address->setCountry(Shopware()->QentaCheckoutPage()->getUser('countryShipping')->countryiso); + $address->setCountry(Shopware()->Container()->get('QentaCheckoutPage')->getUser('countryShipping')->countryiso); break; } return $address; diff --git a/Frontend/QentaCheckoutPage/Models/Resources.php b/Frontend/QentaCheckoutPage/Models/Resources.php index 471df7d..f39a000 100644 --- a/Frontend/QentaCheckoutPage/Models/Resources.php +++ b/Frontend/QentaCheckoutPage/Models/Resources.php @@ -158,7 +158,7 @@ public function getPaymentMethods() */ public function __set($var = null, $val = null) { - Shopware()->Session()->_SESSION[Shopware_Plugins_Frontend_QentaCheckoutPage_Bootstrap::NAME][$var] = serialize($val); + Shopware()->Session()->offsetSet(Shopware_Plugins_Frontend_QentaCheckoutPage_Bootstrap::NAME . '_' . $var, serialize($val)); } /** @@ -168,8 +168,8 @@ public function __set($var = null, $val = null) */ public function __get($var = null) { - if (!empty($var) && isset(Shopware()->Session()->_SESSION[Shopware_Plugins_Frontend_QentaCheckoutPage_Bootstrap::NAME][$var])) { - return unserialize(Shopware()->Session()->_SESSION[Shopware_Plugins_Frontend_QentaCheckoutPage_Bootstrap::NAME][$var]); + if (!empty($var) && Shopware()->Session()->has(Shopware_Plugins_Frontend_QentaCheckoutPage_Bootstrap::NAME . '_' . $var)) { + return unserialize(Shopware()->Session()->offsetGet(Shopware_Plugins_Frontend_QentaCheckoutPage_Bootstrap::NAME . '_' . $var)); } else { return null; } @@ -216,7 +216,7 @@ public function getUser($key = '') */ public function getPaymentShortName() { - $aPaymentType = $this->getPaymentMethods()->getOneByFullName(Shopware()->QentaCheckoutPage()->getUser('payment')->name); + $aPaymentType = $this->getPaymentMethods()->getOneByFullName(Shopware()->Container()->get('QentaCheckoutPage')->getUser('payment')->name); return $aPaymentType['call']; } diff --git a/Frontend/QentaCheckoutPage/Models/Transaction.php b/Frontend/QentaCheckoutPage/Models/Transaction.php index 1f2caf1..c843383 100644 --- a/Frontend/QentaCheckoutPage/Models/Transaction.php +++ b/Frontend/QentaCheckoutPage/Models/Transaction.php @@ -116,7 +116,7 @@ public function update($qentaCheckoutPageId, $update) public function generateHash($id, $amount, $currencycode) { return md5( - Shopware()->QentaCheckoutPage()->getConfig()->SECRET . '|' . $id . '|' . $amount . '|' . $currencycode + Shopware()->Container()->get('QentaCheckoutPage')->getConfig()->SECRET . '|' . $id . '|' . $amount . '|' . $currencycode ); } diff --git a/README.md b/README.md index 2c2624a..1b37f5f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Qenta Checkout Page plugin for Shopware [![License](https://img.shields.io/badge/license-GPLv2-blue.svg)](https://raw.githubusercontent.com/qenta-cee/shopware-qcp/master/LICENSE) -[![Shopware](https://img.shields.io/badge/Shopware-v5.2.0--v5.6.8-green.svg)](https://www.shopware.com/) +[![Shopware](https://img.shields.io/badge/Shopware-v5.7.0--v5.7.16-green.svg)](https://www.shopware.com/) [![PHP v7.4](https://img.shields.io/badge/php-v7.4-green.svg)](http://www.php.net) ---- @@ -15,7 +15,7 @@ Our [Online Guides](https://guides.qenta.com/shop_plugins/qpay/shopware/start/ " Be careful after installing/updating the plugin from the GitHub master branch. Your Shopware installation might notify you about an upgrade at the [Shopware store](http://store.shopware.com/wirecard01501/wirecard-checkout-page.html). **This upgrade will revert the plugin to the latest version on the Shopware store.** -**For Shopware versions 5.2.22 - 5.2.24 there can be problems with the shopversion from Shopware AG.** +**For Shopware versions 5.7.0 - 5.7.16 there can be problems with the shopversion from Shopware AG.** ## Qenta Checkout Page Qenta Checkout Page is designed to meet the ambitious demands of merchants offering a wide range of payment methods while at the same time fulfilling PCI DSS compliance.