/** * @param \Enlight_Controller_ActionEventArgs $args * @return bool */ public function onPostDispatchAccount($args) { $action = $args->getSubject(); $request = $action->Request(); $view = $action->View(); if ($request->getParam('ppplusRedirect')) { $values = $request->getPost(); $values['payment'] = $values['sPayment']; $values['isPost'] = true; $view->assign('sFormData', $values); } if ($request->getActionName() !== 'index' && $request->getActionName() !== 'payment') { return false; } $newDescription = $this->bootstrap->Config()->get('paypalPlusDescription', ''); $newAdditionalDescription = $this->bootstrap->Config()->get('paypalPlusAdditionalDescription', ''); if ($request->getActionName() === 'payment') { //Fix payment description $payments = $action->View()->getAssign('sPaymentMeans'); if (empty($payments)) { return false; } foreach ($payments as $key => $payment) { if ($payment['name'] !== 'paypal') { continue; } $validator = new APIValidator($this->bootstrap->get('paypal_plus.rest_client')); //Check if paypal plus is available if (!$validator->isAPIAvailable()) { continue; } $payments[$key]['description'] = $newDescription; $payments[$key]['additionaldescription'] = $payment['additionaldescription'] . $newAdditionalDescription; $view->assign('sPaymentMeans', $payments); break; } } if ($request->getActionName() === 'index') { $user = $view->getAssign('sUserData'); if (!empty($user['additional']['payment']['name']) && $user['additional']['payment']['name'] === 'paypal') { //Check if paypal plus is available $validator = new APIValidator($this->bootstrap->get('paypal_plus.rest_client')); if (!$validator->isAPIAvailable()) { return false; } $user['additional']['payment']['description'] = $newDescription; $user['additional']['payment']['additionaldescription'] = $newAdditionalDescription; $view->assign('sUserData', $user); } } }
/** * extends the PayPal description * * @param View $view */ private function addTemplateVariables(View $view) { $newDescription = $this->bootstrap->Config()->get('paypalPlusDescription', ''); $newAdditionalDescription = $this->bootstrap->Config()->get('paypalPlusAdditionalDescription', ''); $payments = $view->getAssign('sPayments'); $validator = new APIValidator($this->restClient); if (empty($payments)) { return; } foreach ($payments as $key => $payment) { if ($payment['name'] !== 'paypal' || !$validator->isAPIAvailable()) { continue; } //Update the payment description $payments[$key]['description'] = $newDescription; $payments[$key]['additionaldescription'] = $payment['additionaldescription'] . $newAdditionalDescription; break; } $view->assign('sPayments', $payments); $user = $view->getAssign('sUserData'); if (!empty($user['additional']['payment']['name']) && $user['additional']['payment']['name'] === 'paypal' && $validator->isAPIAvailable()) { $user['additional']['payment']['description'] = $newDescription; $user['additional']['payment']['additionaldescription'] = $newAdditionalDescription; $view->assign('sUserData', $user); } if (method_exists($this->paypalBootstrap, 'getPayment')) { $payPalPaymentId = $this->paypalBootstrap->getPayment()->getId(); } else { //fallback for SwagPaymentPaypal version < 3.3.4 $payPalPaymentId = $this->paypalBootstrap->Payment()->getId(); } $view->assign('PayPalPaymentId', $payPalPaymentId); }