/** * Event listener method handles all Frontend actions * * @param Enlight_Event_EventArgs $args */ static function onPostRatepayDispatch(Enlight_Event_EventArgs $args) { $config = Shopware()->Plugins()->Frontend()->PigmbhRatePAYPayment()->Config(); Shopware()->Template()->addTemplateDir(dirname(__FILE__) . '/Views/Frontend/'); /** @var $request Enlight_Controller_Request_RequestHttp */ $request = $args->getSubject()->Request(); // just be active in the frontend and while the plugin is enabled if ($request->getModuleName() == 'frontend' && $config->multishopactive == true) { $view = $args->getSubject()->View(); Shopware()->Session()->pi_ratepay_rate_calc_path = Shopware()->Config()->get('basepath') . '/engine/Shopware/Plugins/Default/Frontend/PigmbhRatePAYPayment/Ratenrechner/'; // return if no template could be found. if(!$view->hasTemplate()) { return; } $userData = $view->sUserData; if(isset($userData['billingadress']['id'])) { Shopware()->Session()->RatepayCustomerId=$userData['billingadress']['id']; } $ratepayPayment=checkRatepayPayment($userData); if ($userData && $ratepayPayment) { checkBillingEqualShipping($userData, $view); checkB2BAllowed($userData, $view); if(Shopware()->Session()->ratepayB2BInvoice && $userData["additional"]["payment"]["name"] == "RatePAYInvoice" || Shopware()->Session()->ratepayB2BRate && $userData["additional"]["payment"]["name"] == "RatePAYRate" || Shopware()->Session()->ratepayB2BDebit && $userData["additional"]["payment"]["name"] == "RatePAYDebit" || Shopware()->Session()->ratePAYadressDiff) { $sql = "UPDATE `s_user` SET `paymentID` = ? WHERE `id` = ?"; Shopware()->Db()->query($sql, array( (int)Shopware()->Config()->Paymentdefault, (int)$userData['billingaddress']['userID'] )); } } $view->extendsTemplate('index/header.tpl'); //Checks if customer can pay with RatePAY, sets error messages and loads payment_fieldset template //Also implements fix for older templates and sets debit data // sViewport has been removed - instead $args->getSubject()->Request()->getControllerName() can be used if ($request->getControllerName() == 'account' || $request->getControllerName() == 'checkout' || $request->getControllerName() == 'register') { $basket = Shopware()->Session()->sOrderVariables['sBasket']; //gets userage and checks user data if ($userData) { $userAge = getUserAge($userData, $view); checkBillingEqualShipping($userData, $view); checkUserData($userData, $view, $userAge); checkB2BAllowed($userData, $view); $view->debitData = getEncodedDebitData($userData['billingaddress']['userID']); if(!isset($view->debitData)) $view->debitData = getDebitData(); } //displays surcharge at payment selection if($basket){ setSurcharge($basket, $view); Shopware()->Session()->pi_ratepay_Warenkorbbetrag = number_format($basket['AmountNumeric'], 2, ".", ""); } $view->activateDebit = $config->activate_debit; $view->extendsTemplate('register/payment_fieldset.tpl'); //Saves data entered in RatePAY form if ($request->getActionName() == 'savePayment') { $post = $args->getSubject()->Request()->getPost(); setDirectDebitSession($post); if (isset($post['saveRatepayInvoiceData']) || isset($post['saveRatepayRateData']) || isset($post['saveRatepayDebitData'])){ saveUserData($args); } elseif($post['register']['payment'] == getDebitPaymentId() || ($post['register']['payment']== getRatePaymentId() && Shopware()->Session()->RatepayDirectDebit)){ if(!checkDebitData($post)){ header('Location:'.str_replace("savePayment","payment",Shopware()->Config()->Host.$_SERVER['REQUEST_URI'])); //break; } else{ Shopware()->Session()->RatepayRateMissingBankData = false; Shopware()->Session()->RatepayDebitMissingBankData = false; saveDebitData($args); } } } //template fix and saving of direct debit selection for ratepay installment if($request->getActionName() == 'payment'){ if(Shopware()->Session()->RatepayDebitMissingBankData){ $view->RatepayDebitMissingBankData = true; } elseif(Shopware()->Session()->RatepayRateMissingBankData){ $view->RatepayRateMissingBankData = true; } } //Sets debit data if(Shopware()->Session()->RatepayDirectDebit){ $view->ratepayDebitPayType = Shopware()->Session()->RatepayDirectDebit; } //Extends checkout with RatePAY AGB, rate calculator and payment notices and also sets template vars if ($request->getControllerName() == 'checkout' && $request->getActionName() != 'finish' && $request->getActionName() != 'cart' && $request->sTargetAction != 'cart' && isset($ratepayPayment)) { $view->extendsTemplate('checkout/confirm.tpl'); setTemplateVars($view, $request, $config, $userData); } //Confirms RatePAY order at finish page if ($request->getControllerName() == 'checkout' && $request->getActionName() == 'finish' && $request->getActionName() != 'cart' && $ratepayPayment && !Shopware()->Session()->pi_ratepay_Confirm){ confirmPayment($config, $userData); } } } }
/** * Sets content customer bank data for request * * @param Object $customer Request customer object * @param Array $user Current user */ function setRatepayContentCustomerBankData($customer, $user) { $config = Shopware()->Plugins()->Frontend()->PigmbhRatePAYPayment()->Config(); $debitData = array(); if(($user['additional']['payment']['id'] == getRatePaymentId() && $config->bankdata_rate ) ||($user['additional']['payment']['id'] == getDebitPaymentId() && $config->bankdata_debit) ) { $debitData= getEncodedDebitData($user['billingaddress']['userID']); } else{ $debitData = getDebitData(); } $bankData = $customer->addChild('bank-account'); $bankData->addCDataChild('owner', $debitData['owner']); $bankData->addChild('bank-account-number', $debitData['accountnumber']); $bankData->addChild('bank-code', $debitData['bankcode']); $bankData->addCDataChild('bank-name', $debitData['bankname']); }