diff --git a/app/code/community/Lyra/Payzen/Block/Abstract.php b/app/code/community/Lyra/Payzen/Block/Abstract.php index 26b14fc7..c9952cb5 100644 --- a/app/code/community/Lyra/Payzen/Block/Abstract.php +++ b/app/code/community/Lyra/Payzen/Block/Abstract.php @@ -1,6 +1,6 @@ _checkAndGetSkinUrl($this->getConfigData('module_logo')); - if (! Mage::helper('payzen')->isAdmin() && $logoURL) { + if (! $this->_getHelper()->isAdmin() && $logoURL) { $logo = Mage::getConfig()->getBlockClassName('core/template'); $logo = new $logo; $logo->setTemplate('payzen/logo.phtml'); @@ -45,7 +45,7 @@ protected function _checkAndGetSkinUrl($fileName) } $filePath = Mage::getBaseDir('media') . DS . 'payzen' . DS . 'logos' . DS . $fileName; - if (! file_exists($filePath)) { + if (! $this->_getHelper()->fileExists($filePath)) { return false; } @@ -57,7 +57,7 @@ public function getCcTypeImageSrc($card) $card = strtolower($card); $path = Mage::getBaseDir('media') . DS . 'payzen' . DS . 'ct' . DS . $card . '.png'; - if (file_exists($path)) { + if ($this->_getHelper()->fileExists($path)) { return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'payzen/ct/' . $card . '.png'; } else { return false; @@ -73,4 +73,14 @@ public function getConfigData($name) { return $this->_getModel()->getConfigData($name); } + + /** + * Return payzen data helper. + * + * @return Lyra_Payzen_Helper_Data + */ + protected function _getHelper() + { + return Mage::helper('payzen'); + } } diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/Redirect.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/Redirect.php index a668921b..f00738af 100644 --- a/app/code/community/Lyra/Payzen/Block/Adminhtml/Redirect.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/Redirect.php @@ -1,6 +1,6 @@ Mage::helper('payzen')->__('Magento category'), 'style' => 'width: 200px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_Label + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_Label ) ); @@ -38,7 +39,7 @@ public function __construct() array( 'label' => Mage::helper('payzen')->__('PayZen category'), 'style' => 'width: 200px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_List($options) + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_List($options) ) ); diff --git a/app/code/community/Lyra/Payzen/Block/Field/Choozeo/CustgroupOptions.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Choozeo/CustgroupOptions.php similarity index 73% rename from app/code/community/Lyra/Payzen/Block/Field/Choozeo/CustgroupOptions.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Choozeo/CustgroupOptions.php index 4f001345..f13851a2 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/Choozeo/CustgroupOptions.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Choozeo/CustgroupOptions.php @@ -1,6 +1,6 @@ Mage::helper('payzen')->__('Label'), 'style' => 'width: 260px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_Label + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_Label ) ); $this->addColumn( diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Column/EditableLabel.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Column/EditableLabel.php new file mode 100644 index 00000000..3d60ece7 --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Column/EditableLabel.php @@ -0,0 +1,43 @@ +column['class'] ? $this->column['class'] : 'input-text') . '"'; + $html .= ' style="'. ($this->column['style'] ? ' ' . $this->column['style'] : '') . '"'; + $html .= '>'; + + $html .= ''; + + $codeInputName = str_replace($this->columnName, 'code', $this->inputName); + $html .= ''; + + $countInputName = str_replace($this->columnName, 'count', $this->inputName); + $html .= ''; + + $html .= ''; + + return $html; + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Field/Column/Label.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Column/Label.php similarity index 84% rename from app/code/community/Lyra/Payzen/Block/Field/Column/Label.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Column/Label.php index 6932a1ee..b8a93ddc 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/Column/Label.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Column/Label.php @@ -1,6 +1,6 @@ unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); + $element->setDisabled(true); + } + + return parent::render($element); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Field/CustgroupOptions.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/CustgroupOptions.php similarity index 91% rename from app/code/community/Lyra/Payzen/Block/Field/CustgroupOptions.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/CustgroupOptions.php index 32c2fe1e..99303c32 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/CustgroupOptions.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/CustgroupOptions.php @@ -1,6 +1,6 @@ Mage::helper('payzen')->__('Customer group'), 'style' => 'width: 260px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_Label + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_Label ) ); $this->addColumn( diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Fullcb/CustgroupOptions.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Fullcb/CustgroupOptions.php new file mode 100644 index 00000000..51fac498 --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Fullcb/CustgroupOptions.php @@ -0,0 +1,31 @@ +_default = array('amount_min' => '100', 'amount_max' => '1500'); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Fullcb/PaymentOptions.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Fullcb/PaymentOptions.php new file mode 100644 index 00000000..512661cc --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Fullcb/PaymentOptions.php @@ -0,0 +1,129 @@ +addColumn( + 'label', + array( + 'label' => Mage::helper('payzen')->__('Label'), + 'style' => 'width: 220px;', + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_EditableLabel + ) + ); + + $this->addColumn( + 'amount_min', + array( + 'label' => Mage::helper('payzen')->__('Min. amount'), + 'style' => 'width: 120px;' + ) + ); + + $this->addColumn( + 'amount_max', + array( + 'label' => Mage::helper('payzen')->__('Max. amount'), + 'style' => 'width: 120px;' + ) + ); + + $this->addColumn( + 'rate', + array( + 'label' => Mage::helper('payzen')->__('Rate'), + 'style' => 'width: 100px;', + ) + ); + + $this->addColumn( + 'cap', + array( + 'label' => Mage::helper('payzen')->__('Cap'), + 'style' => 'width: 100px;', + ) + ); + + $this->_addAfter = false; + + parent::__construct(); + + $this->setTemplate('payzen/field/array.phtml'); + } + + /** + * Obtain existing data from form element. + * + * Each row will be instance of Varien_Object + * + * @return array + */ + public function getArrayRows() + { + /** @var array[string][array] $defaultOptions */ + $defaultOptions = array( + 'FULLCB3X' => array( + 'label' => Mage::helper('payzen')->__('Payment in %s times', '3'), + 'count' => '3', + 'rate' => '1.4', + 'cap' => '9' + ), + 'FULLCB4X' => array( + 'label' => Mage::helper('payzen')->__('Payment in %s times', '4'), + 'count' => '4', + 'rate' => '2.1', + 'cap' => '12' + ) + ); + + $savedOptions = $this->getElement()->getValue(); + if (! is_array($savedOptions)) { + $savedOptions = array(); + } + + foreach ($savedOptions as $id => $savedOption) { + if (key_exists($savedOption['code'], $defaultOptions)) { + unset($defaultOptions[$savedOption['code']]); + } + } + + // add not saved yet options + foreach ($defaultOptions as $code => $defaultOption) { + $option = array( + 'code' => $code, + 'label' => $defaultOption['label'], + 'count' => $defaultOption['count'], + 'amount_min' => '', + 'amount_max' => '', + 'rate' => $defaultOption['rate'], + 'cap' => $defaultOption['cap'] + ); + + $savedOptions[uniqid('_' . $code . '_')] = $option; + } + + $this->getElement()->setValue($savedOptions); + return parent::getArrayRows(); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Field/Gift/AddedCards.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Gift/AddedCards.php similarity index 79% rename from app/code/community/Lyra/Payzen/Block/Field/Gift/AddedCards.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Gift/AddedCards.php index 06e3c448..3a3ae73b 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/Gift/AddedCards.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Gift/AddedCards.php @@ -1,6 +1,6 @@ Mage::helper('payzen')->__('Card logo'), 'style' => 'width: 340px;', 'size' => '20', - 'renderer' => new Lyra_Payzen_Block_Field_Gift_UploadButton + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Gift_UploadButton ) ); diff --git a/app/code/community/Lyra/Payzen/Block/Field/Gift/UploadButton.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Gift/UploadButton.php similarity index 86% rename from app/code/community/Lyra/Payzen/Block/Field/Gift/UploadButton.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Gift/UploadButton.php index 6b6483fa..496d225c 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/Gift/UploadButton.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Gift/UploadButton.php @@ -1,6 +1,6 @@ addData( array( - 'button_label' => Mage::helper('payzen')->__((string)$fieldConfig->button_label), + 'button_label' => Mage::helper('payzen')->__((string) $fieldConfig->button_label), 'button_url' => $this->getUrl($fieldConfig->button_url), 'html_id' => $element->getHtmlId() ) diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/KeyTest.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/KeyTest.php new file mode 100644 index 00000000..7e62d5b0 --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/KeyTest.php @@ -0,0 +1,41 @@ +unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); $fieldConfig = $element->getFieldConfig(); - if (isset($fieldConfig->is_country) && (bool)$fieldConfig->is_country) { + if (isset($fieldConfig->is_country) && (bool) $fieldConfig->is_country) { $name = Mage::app()->getLocale()->getCountryTranslation($element->getValue()); if (! empty($name)) { $element->setValue($name); diff --git a/app/code/community/Lyra/Payzen/Block/Field/Multi/PaymentOptions.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Multi/PaymentOptions.php similarity index 90% rename from app/code/community/Lyra/Payzen/Block/Field/Multi/PaymentOptions.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Multi/PaymentOptions.php index 67943d57..8245ece9 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/Multi/PaymentOptions.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Multi/PaymentOptions.php @@ -1,6 +1,6 @@ unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); + + $store = Mage::app()->getAnyStoreView(); // either default or any other store view + $ipnUrl = Mage::helper('payzen')->prepareUrl($element->getValue(), $store->getId()); + $element->setValue($ipnUrl); + + $warnImg = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'payzen/warn.png'; + $comment = ''; + $comment .= '' + . $element->getComment() . ''; + $element->setComment($comment); + + return str_replace('class="note"', '', parent::render($element)); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Field/Oney/PaymentOptions.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Oney/PaymentOptions.php similarity index 76% rename from app/code/community/Lyra/Payzen/Block/Field/Oney/PaymentOptions.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Oney/PaymentOptions.php index c63a4ae6..6112358a 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/Oney/PaymentOptions.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Oney/PaymentOptions.php @@ -1,6 +1,6 @@ //getElement()->getDisabled()) { $script .= ' - toggleValueElements({checked: true}, $("payment_payzen_oney_payment_options").parentNode);'; + toggleValueElements({checked: true}, $("payment_payzen_oney_oney_payment_options").parentNode);'; } $script .= ' - Event.observe($("payment_payzen_oney_enable_payment_options"), "change", function() { - toggleValueElements( - $("payment_payzen_oney_payment_options_inherit"), - $("payment_payzen_oney_payment_options").parentNode - ); - }); + Event.observe($("payment_payzen_oney_oney_enable_payment_options"), "change", function() { + toggleValueElements( + $("payment_payzen_oney_oney_payment_options_inherit"), + $("payment_payzen_oney_oney_payment_options").parentNode + ); }); + }); //]]> '; } diff --git a/app/code/community/Lyra/Payzen/Block/Field/SectionTitle.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/SectionTitle.php similarity index 88% rename from app/code/community/Lyra/Payzen/Block/Field/SectionTitle.php rename to app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/SectionTitle.php index 1ce6d350..1bace3f5 100644 --- a/app/code/community/Lyra/Payzen/Block/Field/SectionTitle.php +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/SectionTitle.php @@ -1,6 +1,6 @@ Mage::helper('payzen')->__('Method title'), 'style' => 'width: 210px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_Label + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_Label ) ); $this->addColumn( @@ -52,7 +53,7 @@ public function __construct() array( 'label' => Mage::helper('payzen')->__('Type'), 'style' => 'width: 130px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_List($options) + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_List($options) ) ); @@ -68,7 +69,7 @@ public function __construct() array( 'label' => Mage::helper('payzen')->__('Rapidity'), 'style' => 'width: 75px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_List($options) + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_List($options) ) ); @@ -85,7 +86,7 @@ public function __construct() array( 'label' => Mage::helper('payzen')->__('Delay'), 'style' => 'width: 90px;', - 'renderer' => new Lyra_Payzen_Block_Field_Column_List($options) + 'renderer' => new Lyra_Payzen_Block_Adminhtml_System_Config_Field_Column_List($options) ) ); @@ -106,8 +107,6 @@ public function __construct() public function getArrayRows() { $value = array(); - - /** @var array[string][string] $methods */ $methods = $this->_getAllShippingMethods(); $savedMethods = $this->getElement()->getValue(); @@ -169,7 +168,6 @@ protected function _getAllShippingMethods() continue; } - // $carrierTitle = $carrierModel->getConfigData('title'); foreach ($carrierMethods as $methodCode => $methodTitle) { $code = $carrierCode . '_' . $methodCode; @@ -215,7 +213,7 @@ protected function _toHtml() } }); - // enable delay select for rows with speed == PRIORITY & type = RECLAIM_IN_SHOP + // enable delay select for rows with speed equals PRIORITY and type equals RECLAIM_IN_SHOP $$("select.payzen_list_delay").each(function(elt) { var speedName = elt.name.replace("[delay]", "[speed]"); var typeName = elt.name.replace("[delay]", "[type]"); diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Standard/UseOney.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Standard/UseOney.php new file mode 100644 index 00000000..d0ac927f --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Field/Standard/UseOney.php @@ -0,0 +1,42 @@ +_columns['amount_max']); } } diff --git a/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Fieldset/Payment.php b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Fieldset/Payment.php new file mode 100644 index 00000000..39270438 --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Adminhtml/System/Config/Fieldset/Payment.php @@ -0,0 +1,56 @@ +getOriginalData(); + + + if (isset($data['feature']) && key_exists($data['feature'], $features) && ! $features[$data['feature']]) { + return ''; + } + + if (isset($data['feature']) && ($data['feature'] === 'multi')) { + $comment = ''; + if ($features['restrictmulti']) { + $comment = '
'; + $comment .= $element->getComment(); + $comment .= '
'; + } + + $element->setComment($comment); + } + + return parent::render($element); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Choozeo.php b/app/code/community/Lyra/Payzen/Block/Choozeo.php index 78175486..7a9bfe09 100644 --- a/app/code/community/Lyra/Payzen/Block/Choozeo.php +++ b/app/code/community/Lyra/Payzen/Block/Choozeo.php @@ -1,6 +1,6 @@ setTemplate('payzen/fullcb.phtml'); + } + + public function getPaymentOptions() + { + if ($this->_getModel()->getConfigData('enable_payment_options') != 1) { + // local payment options selection is not allowed + return false; + } + + $amount = $this->getMethod()->getInfoInstance()->getQuote()->getBaseGrandTotal(); + return $this->_getModel()->getPaymentOptions($amount); + } + + public function getHtmlReview(array $option, $first) + { + $quote = $this->getMethod()->getInfoInstance()->getQuote(); + $amount = $quote->getGrandTotal(); + + $block = $this->getLayout()->createBlock('payzen/fullcb_review') + ->setOption($option) + ->setAmount($amount) + ->setFirst($first); + + return $block->toHtml(); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Fullcb/Review.php b/app/code/community/Lyra/Payzen/Block/Fullcb/Review.php new file mode 100644 index 00000000..7247df6f --- /dev/null +++ b/app/code/community/Lyra/Payzen/Block/Fullcb/Review.php @@ -0,0 +1,125 @@ +setTemplate('payzen/fullcb/review.phtml'); + } + + /** + * Set Fullcb option to review. + * + * @param string $url + * @return Lyra_Payzen_Block_Fullcb_Review + */ + public function setOption($option) + { + $this->_option = $option; + return $this; + } + + /** + * Set order amount. + * + * @param float $amount + * @return Lyra_Payzen_Block_Fullcb_Review + */ + public function setAmount($amount) + { + $this->_amount = $amount; + return $this; + } + + /** + * Set first option flag. + * + * @param bool $first + * @return Lyra_Payzen_Block_Oney_Review + */ + public function setFirst($first) + { + $this->_first = $first; + return $this; + } + + public function getFirst() + { + return $this->_first; + } + + public function getOptionDetails() + { + $details = new Varien_Object(); + + if (is_array($this->_option) && ! empty($this->_option)) { + $amount = $this->_amount; + $count = (int) $this->_option['count']; + $rate = (float) $this->_option['rate']; + + $maxFees = (int) $this->_option['cap']; + switch ($count) { + case 3: + $maxFees = self::FULLCB_THREE_TIMES_MAX_FEES; + break; + case 4: + $maxFees = self::FULLCB_FOUR_TIMES_MAX_FEES; + break; + default: + $maxFees = null; + break; + } + + $payment = round($amount / $count, 2); + + $fees = round($amount * $rate / 100, 2); + if ($maxFees) { + $fees = min($fees, $maxFees); + } + + $first = $amount - ($payment * ($count - 1)) + $fees; + + $details->setOptionCode($this->_option['code']); + $details->setOrderTotal($this->currency($amount)); + $details->setFirstPayment($this->currency($first)); + $details->setCount($count - 1); // real number of payments concerned by funding + $details->setMonthlyPayment($this->currency($payment)); + $details->setFundingTotal($this->currency($amount + $fees)); + $details->setFundingFees($this->currency($fees)); + } + + return $details; + } + + public function currency($amount) + { + return Mage::helper('core')->currency($amount, true, true); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Gift.php b/app/code/community/Lyra/Payzen/Block/Gift.php index 06454ae2..76bbee62 100644 --- a/app/code/community/Lyra/Payzen/Block/Gift.php +++ b/app/code/community/Lyra/Payzen/Block/Gift.php @@ -1,6 +1,6 @@ _getHelper()->fileExists($path)) { return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'payzen/gift/' . $card . '.png'; } else { return false; diff --git a/app/code/community/Lyra/Payzen/Block/Giropay.php b/app/code/community/Lyra/Payzen/Block/Giropay.php index daf432c7..d08bd6ce 100644 --- a/app/code/community/Lyra/Payzen/Block/Giropay.php +++ b/app/code/community/Lyra/Payzen/Block/Giropay.php @@ -1,6 +1,6 @@ '; diff --git a/app/code/community/Lyra/Payzen/Block/Multi.php b/app/code/community/Lyra/Payzen/Block/Multi.php index 26d30fbc..55e34c60 100644 --- a/app/code/community/Lyra/Payzen/Block/Multi.php +++ b/app/code/community/Lyra/Payzen/Block/Multi.php @@ -1,6 +1,6 @@ getCustomer(); foreach ($customer->getAddresses() as $address) { $options[] = array( - 'value' => $address->getId(), - 'label' => $address->format('oneline') + 'value' => $address->getId(), + 'label' => $address->format('oneline') ); } @@ -40,7 +40,7 @@ public function getHtmlSelect() ->setName('shipping_address') ->setId($this->getUniqId()) ->setClass('payzen-address-select') - ->setExtraParams('onchange="payzenUpdateShippingBlock();" style="width: 100%;"') + ->setExtraParams('onchange="payzenUpdateShippingBlock(event);" style="width: 100%;"') ->setValue($this->getAddress()->getCustomerAddressId()) ->setOptions($options); diff --git a/app/code/community/Lyra/Payzen/Block/Oneclick/Shipping/Method.php b/app/code/community/Lyra/Payzen/Block/Oneclick/Shipping/Method.php index 4ada74c8..71c01cf4 100644 --- a/app/code/community/Lyra/Payzen/Block/Oneclick/Shipping/Method.php +++ b/app/code/community/Lyra/Payzen/Block/Oneclick/Shipping/Method.php @@ -1,6 +1,6 @@ getParentBlock() ? $this->getParentBlock()->getNameInLayout() - : 'payzen_oneclick_product_shipping'; - - if (strpos($parentName, 'product') !== false) { - return Lyra_Payzen_Helper_Payment::ONECLICK_LOCATION_PRODUCT; - } elseif (strpos($parentName, 'cart') !== false) { - return Lyra_Payzen_Helper_Payment::ONECLICK_LOCATION_CART; - } else { - return null; - } - } - protected function _afterToHtml($html) { $this->_method = null; diff --git a/app/code/community/Lyra/Payzen/Block/Oney.php b/app/code/community/Lyra/Payzen/Block/Oney.php index 97e1158d..903e376f 100644 --- a/app/code/community/Lyra/Payzen/Block/Oney.php +++ b/app/code/community/Lyra/Payzen/Block/Oney.php @@ -1,6 +1,6 @@ _option) && ! empty($this->_option)) { $amount = $this->_amount; - $count = (int)$this->_option['count']; - $rate = (float)$this->_option['rate']; + $count = (int) $this->_option['count']; + $rate = (float) $this->_option['rate']; $maxFees = null; switch ($count) { @@ -113,7 +113,7 @@ public function getOptionDetails() $details->setMonthlyPayment($this->currency($payment)); $details->setFundingTotal($this->currency(($count - 1) * $payment - $fees)); $details->setFundingFees($this->currency($fees)); - $details->setTaeg(''); // TODO calculate TAEG + $details->setTaeg(''); } return $details; diff --git a/app/code/community/Lyra/Payzen/Block/Paypal.php b/app/code/community/Lyra/Payzen/Block/Paypal.php index 3d701d36..8badc551 100644 --- a/app/code/community/Lyra/Payzen/Block/Paypal.php +++ b/app/code/community/Lyra/Payzen/Block/Paypal.php @@ -1,6 +1,6 @@ setTemplate('payzen/sepa.phtml'); + } +} diff --git a/app/code/community/Lyra/Payzen/Block/Sofort.php b/app/code/community/Lyra/Payzen/Block/Sofort.php index 690c4c65..c1d7d30f 100644 --- a/app/code/community/Lyra/Payzen/Block/Sofort.php +++ b/app/code/community/Lyra/Payzen/Block/Sofort.php @@ -1,6 +1,6 @@ false, + 'prodfaq' => true, + 'acquis' => true, + 'restrictmulti' => false, + + 'multi' => true, + 'gift' => true, + 'oney' => true, + 'paypal' => true, + 'sofort' => true, + 'postfinance' => false, + 'giropay' => true, + 'ideal' => true, + 'choozeo' => false, + 'fullcb' => true, + 'sepa' => true + ); + /** * Shortcut method to get general PayZen module configuration. * @@ -76,7 +99,7 @@ public function getConfigGroupTitle($group) $config->loadFile(Mage::getConfig()->getModuleDir('etc', 'Lyra_Payzen').DS.'system.xml'); $node = $config->getNode('sections/payment/groups/'.$group); - return Mage::helper('payzen')->__((string)$node->label); + return Mage::helper('payzen')->__((string) $node->label); } /** @@ -146,13 +169,25 @@ public function isCurrentlySecure() public function isMaintenanceMode() { $maintenanceFile = Mage::getRoot() . '/maintenance.flag'; - if (file_exists($maintenanceFile)) { + if ($this->fileExists($maintenanceFile)) { return true; } return false; } + /** + * Return true if file exists. Uses Varien_Io_File API. + * + * @param $fileName + * @return bool + */ + public function fileExists($fileName) + { + $io = new Varien_Io_File(); + return $io->fileExists($fileName); + } + /** * Add a model config parameter for each of given $options (multi payment options). * @@ -214,7 +249,7 @@ public function log($message, $level = null) $currentMethod = $this->_getCallerMethod(); $log = ''; - $log .= 'PayZen 1.8.0'; + $log .= 'PayZen 1.9.0'; $log .= ' - ' . $currentMethod; $log .= ' : ' . $message; @@ -231,7 +266,11 @@ protected function _getCallerMethod() $traces = debug_backtrace(); if (isset($traces[2])) { - return $traces[2]['class'] . '::' . $traces[2]['function']; + $trace = ''; + + $trace .= isset($traces[2]['class']) ? ($traces[2]['class'] . '::') : ''; + $trace .= isset($traces[2]['function']) ? $traces[2]['function'] : ''; + return $trace; } return null; diff --git a/app/code/community/Lyra/Payzen/Helper/Payment.php b/app/code/community/Lyra/Payzen/Helper/Payment.php index 31002afc..55437a23 100644 --- a/app/code/community/Lyra/Payzen/Helper/Payment.php +++ b/app/code/community/Lyra/Payzen/Helper/Payment.php @@ -1,6 +1,6 @@ addStatusHistoryComment( - $this->_getHelper()->__('Client sent to PayZen platform.'), + $this->_getHelper()->__('Client sent to PayZen gateway.'), false )->save(); // clear quote data - $controller->getCheckout()->clear(); + $controller->getCheckout()->setQuoteId(null); + $controller->getCheckout()->setLastSuccessQuoteId(null); // inactivate quote $quote = Mage::getModel('sales/quote')->load($order->getQuoteId()); @@ -85,7 +86,7 @@ public function doPaymentForm($controller) $quote->setIsActive(false)->save(); } - // redirect to platform + // redirect to gateway $this->_getHelper()->log("Display payment form and JavaScript for order #{$order->getId()}."); $controller->loadLayout(); @@ -125,9 +126,9 @@ public function doPaymentReturn($controller) "{$ip} tries to access payzen/payment/return page without valid signature with parameters: " . print_r($request, true), Zend_Log::ERR ); -// $this->_getHelper()->log( -// 'Signature algorithm selected in module settings must be the same as one selected in PayZen Back Office.' -// ); + $this->_getHelper()->log( + 'Signature algorithm selected in module settings must be the same as one selected in PayZen Back Office.' + ); $controller->redirectError($order); return; @@ -146,9 +147,9 @@ public function doPaymentReturn($controller) if ($order->getStatus() == 'pending_payment') { // order waiting for payment - $this->_getHelper()->log("Order #{$order->getId()} is waiting payment."); + $this->_getHelper()->log("Order #{$order->getId()} is waiting for payment."); - if ($response->isAcceptedPayment()) { + if ($this->_isPaymentSuccessfullyProcessed($response)) { $this->_getHelper()->log( "Payment for order #{$order->getId()} has been confirmed by client return ! " . " This means the notification URL did not work.", @@ -182,10 +183,10 @@ public function doPaymentReturn($controller) 'payzen_to_validate' /* payment will be done after manual validation */ ); - if ($response->isAcceptedPayment() && in_array($order->getStatus(), $successStatuses)) { + if ($this->_isPaymentSuccessfullyProcessed($response) && in_array($order->getStatus(), $successStatuses)) { $this->_getHelper()->log("Order #{$order->getId()} is confirmed."); $controller->redirectResponse($order, true /* is success ? */); - } elseif ($order->isCanceled() && ! $response->isAcceptedPayment()) { + } elseif ($order->isCanceled() && ! $this->_isPaymentSuccessfullyProcessed($response)) { $this->_getHelper()->log("Order #{$order->getId()} cancelation is confirmed."); $controller->redirectResponse($order, false /* is success ? */); } else { @@ -231,9 +232,9 @@ public function doPaymentCheck($controller) "{$ip} tries to access payzen/payment/check page without valid signature with parameters: " . print_r($post, true), Zend_Log::ERR ); -// $this->_getHelper()->log( -// 'Signature algorithm selected in module settings must be the same as one selected in PayZen Back Office.' -// ); + $this->_getHelper()->log( + 'Signature algorithm selected in module settings must be the same as one selected in PayZen Back Office.' + ); $controller->getResponse()->setBody($response->getOutputForPlatform('auth_fail')); return; @@ -244,9 +245,9 @@ public function doPaymentCheck($controller) $reviewStatuses = array('payment_review', 'payzen_to_validate', 'fraud'); if ($order->getStatus() == 'pending_payment' || in_array($order->getStatus(), $reviewStatuses)) { // order waiting for payment - $this->_getHelper()->log("Order #{$order->getId()} is waiting payment."); + $this->_getHelper()->log("Order #{$order->getId()} is waiting for payment."); - if ($response->isAcceptedPayment()) { + if ($this->_isPaymentSuccessfullyProcessed($response)) { $this->_getHelper()->log( "Payment for order #{$order->getId()} has been confirmed by notification URL." ); @@ -282,7 +283,7 @@ public function doPaymentCheck($controller) 'complete' /* case of virtual orders */ ); - if ($response->isAcceptedPayment() && in_array($order->getStatus(), $successStatuses)) { + if ($this->_isPaymentSuccessfullyProcessed($response) && in_array($order->getStatus(), $successStatuses)) { $this->_getHelper()->log("Order #{$order->getId()} is confirmed."); if ($response->get('operation_type') == 'CREDIT') { @@ -320,7 +321,7 @@ public function doPaymentCheck($controller) 'Amount' => $amountDetail, 'Transaction ID' => $transactionId, 'Transaction Status' => $response->getTransStatus(), - 'Payment Mean' => $response->get('card_brand'), + 'Means of Payment' => $response->get('card_brand'), 'Credit Card Number' => $response->get('card_number'), 'Expiration Date' => $expiry ); @@ -336,7 +337,7 @@ public function doPaymentCheck($controller) $order->save(); $controller->getResponse()->setBody($response->getOutputForPlatform('payment_ok_already_done')); - } elseif ($order->isCanceled() && ! $response->isAcceptedPayment()) { + } elseif ($order->isCanceled() && ! $this->_isPaymentSuccessfullyProcessed($response)) { $this->_getHelper()->log("Order #{$order->getId()} cancelation is confirmed."); $controller->getResponse()->setBody($response->getOutputForPlatform('payment_ko_already_done')); } else { @@ -350,6 +351,16 @@ public function doPaymentCheck($controller) } } + private function _isPaymentSuccessfullyProcessed(Lyra_Payzen_Model_Api_Response $response) + { + if ($response->isAcceptedPayment()) { + return true; + } + + return ! $response->getTransStatus() && $response->get('identifier') && + in_array($response->get('identifier_status'), array('CREATED', 'UPDATED')); + } + /** * Update order status and eventually create invoice. * @@ -377,7 +388,7 @@ protected function _registerOrder(Mage_Sales_Model_Order $order, Lyra_Payzen_Mod $order->setHoldBeforeStatus($stateObject->getBeforeStatus()); } - // save platform responses + // save gateway responses $this->updatePaymentInfo($order, $response); // try to save PayZen identifier if any @@ -391,7 +402,7 @@ protected function _registerOrder(Mage_Sales_Model_Order $order, Lyra_Payzen_Mod $sendEmail = true; if ($info = $response->get('order_info')) { - $sendEmail = (bool)substr($info, strlen('send_confirmation=')); + $sendEmail = (bool) substr($info, strlen('send_confirmation=')); } if ($sendEmail) { @@ -415,6 +426,11 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) ->setAdditionalInformation(self::ALL_RESULTS, serialize($response->getAllResults())) ->setAdditionalInformation(self::TRANS_UUID, $response->get('trans_uuid')); + if ($response->isCancelledPayment()) { + // no more data to save + return; + } + if ($response->get('brand_management')) { $brandInfo = Mage::helper('core')->jsonDecode($response->get('brand_management'), Zend_Json::TYPE_OBJECT); @@ -422,11 +438,6 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) $order->getPayment()->setAdditionalInformation(self::BRAND_USER_CHOICE, $userChoice); } - if ($response->isCancelledPayment()) { - // no more data to save - return; - } - // save risk control result if any $riskControl = $response->getRiskControl(); if (! empty($riskControl)) { @@ -469,17 +480,18 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) 'Extra Transaction ID' => property_exists($trs, 'ext_trans_id') && isset($trs->{'ext_trans_id'}) ? $trs->{'ext_trans_id'} : '', 'Transaction Status' => $trs->{'trans_status'}, - 'Payment Mean' => $trs->{'card_brand'}, + 'Means of Payment' => $trs->{'card_brand'}, 'Credit Card Number' => $trs->{'card_number'}, 'Expiration Date' => $expiry ); $transactionType = $this->convertTxnType($trs->{'trans_status'}); - - $this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo); + if ($transactionType) { + $this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo); + } } } else { - // 3-DS authentication result + // 3DS authentication result $threedsCavv = ''; if ($response->get('threeds_status') === 'Y') { $threedsCavv = $response->get('threeds_cavv'); @@ -508,7 +520,7 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) $option = @unserialize($order->getPayment()->getAdditionalData()); // get choosen payment option if any if ($response->get('sequence_number') == 1 && (stripos($order->getPayment()->getMethod(), 'payzen_multi') === 0) && is_array($option) && ! empty($option)) { - + // first payment of payment in installments if (isset($option['first']) && $option['first']) { $firstAmount = round($totalAmount * $option['first'] / 100); } else { @@ -518,7 +530,7 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) // double cast to avoid rounding $installmentAmount = (int) (string) (($totalAmount - $firstAmount) / ((int) $option['count'] - 1)); - for ($i = 1; $i <= (int)$option['count']; $i++) { + for ($i = 1; $i <= (int) $option['count']; $i++) { $transactionId = $response->get('trans_id') . '-' . $i; $delay = (int) $option['period'] * ($i - 1); @@ -563,13 +575,15 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) 'Transaction ID' => $transactionId, 'Transaction Status' => ($i == 1) ? $response->getTransStatus() : $this->getNextInstallmentsTransStatus($response->getTransStatus()), - 'Payment Mean' => $response->get('card_brand'), + 'Means of Payment' => $response->get('card_brand'), 'Credit Card Number' => $response->get('card_number'), 'Expiration Date' => $expiry, - '3-DS Authentication' => $threedsCavv + '3DS Authentication' => $threedsCavv ); - $this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo); + if ($transactionType) { + $this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo); + } } } else { // save transaction details to sales_payment_transaction @@ -598,13 +612,15 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response) 'Presentation Date' => Mage::helper('core')->formatDate(date('Y-m-d', $firstDate)), 'Transaction ID' => $transactionId, 'Transaction Status' => $response->getTransStatus(), - 'Payment Mean' => $response->get('card_brand'), + 'Means of Payment' => $response->get('card_brand'), 'Credit Card Number' => $response->get('card_number'), 'Expiration Date' => $expiry, - '3-DS Authentication' => $threedsCavv + '3DS Authentication' => $threedsCavv ); - $this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo); + if ($transactionType) { + $this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo); + } } } @@ -627,27 +643,35 @@ protected function _saveIdentifier(Mage_Sales_Model_Order $order, Lyra_Payzen_Mo $this->_getHelper()->log( "Identifier for customer #{$customer->getId()} successfully " - . "created or updated on payment platform. Let's save it to customer entity." + . "created or updated on payment gateway. Let's save it to customer entity." ); $customer->setData('payzen_identifier', $response->get('identifier')); // mask all card digits unless the last 4 ones $number = $response->get('card_number'); - $part1 = substr($number, 0, strpos($number, 'X')); - $part2 = substr($number, strpos($number, 'X')); - - $maskedCard = str_repeat('X', strlen($part1)) . $part2; - - if ($response->get('expiry_month') && $response->get('expiry_year')) { - // format card expiration data - $maskedCard .= ' '; - $maskedCard .= str_pad($response->get('expiry_month'), 2, '0', STR_PAD_LEFT); - $maskedCard .= '/'; - $maskedCard .= $response->get('expiry_year'); + $masked = ''; + + $matches = array(); + if (preg_match('#^([A-Z]{2}[0-9]{2}[A-Z0-9]{10,30})(_[A-Z0-9]{8,11})?$#i', $number, $matches)) { + // IBAN(_BIC) + $masked .= isset($matches[2]) ? str_replace('_', '', $matches[2]) . ' / ' : ''; // BIC + + $iban = $matches[1]; + $masked .= substr($iban, 0, 4) . str_repeat('X', strlen($iban) - 8) . substr($iban, -4); + } elseif (strlen($number) > 4) { + $masked = str_repeat('X', strlen($number) - 4) . substr($number, -4); + + if ($response->get('expiry_month') && $response->get('expiry_year')) { + // format card expiration data + $masked .= ' '; + $masked .= str_pad($response->get('expiry_month'), 2, '0', STR_PAD_LEFT); + $masked .= ' / '; + $masked .= $response->get('expiry_year'); + } } - $customer->setData('payzen_masked_card', $maskedCard); + $customer->setData('payzen_masked_card', $masked); $customer->save(); @@ -662,7 +686,7 @@ public function createInvoice(Mage_Sales_Model_Order $order) // flag that is true if automatically create invoice $autoCapture = $this->_getHelper()->getCommonConfigData('capture_auto', $order->getStore()->getId()); - if (! $autoCapture || $order->getStatus() != 'processing' || ! $order->canInvoice()) { + if (! $autoCapture || ($order->getState() != 'processing') || ! $order->canInvoice()) { // creating invoice not allowed return; } @@ -693,7 +717,7 @@ protected function _cancelOrder(Mage_Sales_Model_Order $order, Lyra_Payzen_Model $order->registerCancellation($response->getMessage()); - // save platform responses + // save gateway responses $this->updatePaymentInfo($order, $response); $order->save(); @@ -746,7 +770,7 @@ public function addTransaction($payment, $type, $transactionId, $additionalInfo, ->isFailsafe(true); if ($payment->hasIsTransactionClosed()) { - $transaction->setIsClosed((int)$payment->getIsTransactionClosed()); + $transaction->setIsClosed((int) $payment->getIsTransactionClosed()); } //set transaction addition information @@ -795,10 +819,15 @@ public function nextOrderState($response, $order, $ignoreFraud = false) $newStatus = 'payment_review'; $newState = $this->_getHelper()->getReviewState(); } else { - $newStatus = $this->_getHelper()->getCommonConfigData( - 'registered_order_status', - $order->getStore()->getId() - ); + if ($this->isSofort($response) || $this->isSepa($response)) { + // pending funds transfer order state + $newStatus = 'payzen_pending_transfer'; + } else { + $newStatus = $this->_getHelper()->getCommonConfigData( + 'registered_order_status', + $order->getStore()->getId() + ); + } $processingStatuses = Mage::getModel('sales/order_config') ->getStateStatuses(Mage_Sales_Model_Order::STATE_PROCESSING, false); @@ -827,6 +856,16 @@ public function nextOrderState($response, $order, $ignoreFraud = false) return $stateObject; } + public function isSofort($response) + { + return $response->get('card_brand') == 'SOFORT_BANKING'; + } + + public function isSepa($response) + { + return $response->get('card_brand') == 'SDD'; + } + /** * Convert PayZen transaction statuses to magento transaction statuses * @@ -861,7 +900,7 @@ public function convertTxnType($payzenType) break; default: - $type = ''; // unknown + $type = null; // unknown break; } diff --git a/app/code/community/Lyra/Payzen/Helper/Util.php b/app/code/community/Lyra/Payzen/Helper/Util.php index dd200d0b..7969397d 100644 --- a/app/code/community/Lyra/Payzen/Helper/Util.php +++ b/app/code/community/Lyra/Payzen/Helper/Util.php @@ -1,6 +1,6 @@ array( + 'name' => "#^[A-ZÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜÇ/ '-]{1,63}$#ui", + 'street' => "#^[A-Z0-9ÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜÇ/ '.,-]{1,127}$#ui", + 'zip' => '#^[0-9]{5}$#', + 'city' => "#^[A-Z0-9ÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜÇ/ '-]{1,127}$#ui", + 'country' => '#^FR|GP|MQ|GF|RE|YT$#i', + 'phone' => '#^[0-9]{10}$#' + ), + 'fullcb' => array( + 'name' => "#^[A-Za-z0-9àâçèéêîôùû]+([ \-']?[A-Za-z0-9àâçèéêîôùû]+)*$#", + 'street' => '#^[^;]*$#', + 'zip' => '#^[0-9]{5}$#', + 'city' => '#^[^;]*$#', + 'country' => '#^FR$#', + 'phone' => '#^(0|33)[0-9]{9}$#' + ) + ); + /** * Normalize shipping method name. * @@ -250,7 +269,7 @@ public function setCartData($order, &$payzenRequest) } $priceInCents = $currency->convertAmountToInteger($item->getPrice()); - $qty = (int)$item->getQtyOrdered(); + $qty = (int) $item->getQtyOrdered(); $payzenRequest->addProduct( preg_replace($notAllowed, ' ', $label), @@ -385,21 +404,21 @@ public function setAdditionalShippingData($order, &$payzenRequest, $useOney = fa } } - public function checkAddressValidity($address) + public function checkAddressValidity($address, $payment) { if (! $address) { return; } - // oney validation regular expressions - $nameRegex = "#^[A-ZÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜÇ/ '-]{1,63}$#ui"; - $phoneRegex = "#^[0-9]{10}$#"; - $cityRegex = "#^[A-Z0-9ÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜÇ/ '-]{1,127}$#ui"; - $streetRegex = "#^[A-Z0-9ÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜÇ/ '.,-]{1,127}$#ui"; + $regex = self::$address_regex[$payment]; - $availableCountries = Mage::getModel('payzen/source_oney_availableCountries')->getCountryCodes(); - $countryRegex = "#^" . implode('|', $availableCountries) . "$#i"; - $zipRegex = "#^[0-9]{5}$#"; + // specific validation regular expressions + $nameRegex = $regex['name']; + $phoneRegex = $regex['phone']; + $cityRegex = $regex['city']; + $streetRegex = $regex['street']; + $countryRegex = $regex['country']; + $zipRegex = $regex['zip']; // error messages $invalidMsg = 'The field %s of your %s is invalid.'; diff --git a/app/code/community/Lyra/Payzen/Model/Api/Api.php b/app/code/community/Lyra/Payzen/Model/Api/Api.php index c5e338c5..dba84502 100644 --- a/app/code/community/Lyra/Payzen/Model/Api/Api.php +++ b/app/code/community/Lyra/Payzen/Model/Api/Api.php @@ -1,6 +1,6 @@ 'PostFinance mode E-finance', 'RUPAY' => 'RuPay', 'SCT' => 'Virement SEPA', 'SDD' => 'Prélèvement SEPA', 'SOFORT_BANKING' => 'Sofort', 'TRUFFAUT_CDX' => 'Carte cadeau Truffaut', 'VILLAVERDE' => 'Carte cadeau Villaverde', - 'VILLAVERDE_SB' => 'Carte cadeau Villaverde - SandBox' + 'VILLAVERDE_SB' => 'Carte cadeau Villaverde - SandBox', 'ECCARD' => 'EC Card' ); } diff --git a/app/code/community/Lyra/Payzen/Model/Api/Currency.php b/app/code/community/Lyra/Payzen/Model/Api/Currency.php index a269b053..73804235 100644 --- a/app/code/community/Lyra/Payzen/Model/Api/Currency.php +++ b/app/code/community/Lyra/Payzen/Model/Api/Currency.php @@ -1,6 +1,6 @@ get('nb_products') ? $this->get('nb_products') : 0; $ok = true; @@ -454,6 +455,7 @@ public function addProduct($label, $amount, $qty, $ref, $type) $ok &= $this->addField('vads_product_qty' . $index, 'Product quantity', '#^[1-9]\d*$#u', false, 255, $qty); $ok &= $this->addField('vads_product_ref' . $index, 'Product reference', '#^[A-Za-z0-9]{0,64}$#u', false, 64, $ref); $ok &= $this->addField('vads_product_type' . $index, 'Product type', '#^' . implode('|', self::$ACCORD_CATEGORIES) . '$#u', false, 30, $type); + $ok &= $this->addField('vads_product_vat' . $index, 'Product tax rate', '#^((\d{1,12})|(\d{1,2}\.\d{1,4}))$#u', false, 12, $vat); // increment the number of products $ok &= $this->set('nb_products', $index + 1); diff --git a/app/code/community/Lyra/Payzen/Model/Api/Response.php b/app/code/community/Lyra/Payzen/Model/Api/Response.php index ed130eb5..2c1ef699 100644 --- a/app/code/community/Lyra/Payzen/Model/Api/Response.php +++ b/app/code/community/Lyra/Payzen/Model/Api/Response.php @@ -1,6 +1,6 @@ array(true, 'Paiement valide traité'), - 'payment_ko' => array(true, 'Paiement invalide traité'), - 'payment_ok_already_done' => array(true, 'Paiement valide traité, déjà enregistré'), - 'payment_ko_already_done' => array(true, 'Paiement invalide traité, déjà enregistré'), - 'order_not_found' => array(false, 'Impossible de retrouver la commande'), - 'payment_ko_on_order_ok' => array(false, 'Code paiement invalide reçu pour une commande déjà validée'), - 'auth_fail' => array(false, 'Echec d\'authentification'), - 'empty_cart' => array(false, 'Le panier a été vidé avant la redirection'), - 'unknown_status' => array(false, 'Statut de commande inconnu'), - 'amount_error' => array(false, 'Le montant payé est différent du montant intial'), + 'payment_ok' => array(true, 'Accepted payment, order has been updated.'), + 'payment_ko' => array(true, 'Payment failure, order has been cancelled.'), + 'payment_ko_bis' => array(true, 'Payment failure.'), + 'payment_ok_already_done' => array(true, 'Accepted payment, already registered.'), + 'payment_ko_already_done' => array(true, 'Payment failure, already registered.'), + 'order_not_found' => array(false, 'Order not found.'), + 'payment_ko_on_order_ok' => array(false, 'Order status does not match the payment result.'), + 'auth_fail' => array(false, 'An error occurred while computing the signature.'), + 'empty_cart' => array(false, 'Empty cart detected before order processing.'), + 'unknown_status' => array(false, 'Unknown order status.'), + 'amount_error' => array(false, 'Total paid is different from order amount.'), 'ok' => array(true, ''), 'ko' => array(false, '') ); @@ -452,7 +453,6 @@ public function getOutputForPlatform($case = '', $extra_message = '', $original_ } $content = $success ? 'OK-' : 'KO-'; - $content .= $this->get('trans_id'); $content .= "$message\n"; $response = ''; diff --git a/app/code/community/Lyra/Payzen/Model/Api/Ws/AuthenticationRequestData.php b/app/code/community/Lyra/Payzen/Model/Api/Ws/AuthenticationRequestData.php index 877af655..300a39c9 100644 --- a/app/code/community/Lyra/Payzen/Model/Api/Ws/AuthenticationRequestData.php +++ b/app/code/community/Lyra/Payzen/Model/Api/Ws/AuthenticationRequestData.php @@ -1,6 +1,6 @@ __((string)$this->getFieldConfig()->label); - $column = Mage::helper('payzen')->__((string)$column); + $field = Mage::helper('payzen')->__((string) $this->getFieldConfig()->label); + $column = Mage::helper('payzen')->__((string) $column); $group = Mage::helper('payzen')->getConfigGroupTitle($this->getGroupId()); // main message diff --git a/app/code/community/Lyra/Payzen/Model/Field/AvailableLanguages.php b/app/code/community/Lyra/Payzen/Model/Field/AvailableLanguages.php index 99630360..284be870 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/AvailableLanguages.php +++ b/app/code/community/Lyra/Payzen/Model/Field/AvailableLanguages.php @@ -1,6 +1,6 @@ getAnyStoreView(); // either default or any other store view - - $checkUrl = Mage::helper('payzen')->prepareUrl($this->getValue(), $store->getId()); - $this->setValue($checkUrl); - - parent::_afterLoad(); - return $this; - } -} diff --git a/app/code/community/Lyra/Payzen/Model/Field/Choozeo/CustgroupOptions.php b/app/code/community/Lyra/Payzen/Model/Field/Choozeo/CustgroupOptions.php index 98db5fe0..6d428935 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Choozeo/CustgroupOptions.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Choozeo/CustgroupOptions.php @@ -1,6 +1,6 @@ getValue(); $data = $this->getGroups('payzen_choozeo'); // get data of FacilyPay Oney config group - if ($data['fields']['active']['value']) { // FacilyPay Oney is activated + if ($data['fields']['choozeo_active']['value']) { // FacilyPay Oney is activated foreach ($values as $key => $value) { if (empty($value) || ($value['code'] !== 'all')) { continue; diff --git a/app/code/community/Lyra/Payzen/Model/Field/Choozeo/PaymentOptions.php b/app/code/community/Lyra/Payzen/Model/Field/Choozeo/PaymentOptions.php index 1c89ddf3..a1624bc6 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Choozeo/PaymentOptions.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Choozeo/PaymentOptions.php @@ -1,6 +1,6 @@ getValue(); + + $data = $this->getGroups('payzen_fullcb'); // get data of FullCB config group + if ($data['fields']['fullcb_active']['value']) { // FullCB is activated + foreach ($values as $key => $value) { + if (empty($value) || ($value['code'] !== 'all')) { + continue; + } + + if (empty($value['amount_min'])) { + $field = 'Minimum amount'; + } elseif (empty($value['amount_max'])) { + $field = 'Maximum amount'; + } + + if (isset($field)) { + $field = Mage::helper('payzen')->__($field); // translate field name + $group = Mage::helper('payzen')->getConfigGroupTitle($this->getGroupId()); + $msg = Mage::helper('payzen')->__('Please enter a value for «ALL GROUPS - %s» in «%s» section as agreed with your bank.', $field, $group); + + // throw exception + Mage::throwException($msg); + } + } + } + + return parent::_beforeSave(); + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Field/Fullcb/PaymentOptions.php b/app/code/community/Lyra/Payzen/Model/Field/Fullcb/PaymentOptions.php new file mode 100644 index 00000000..04a4ac4a --- /dev/null +++ b/app/code/community/Lyra/Payzen/Model/Field/Fullcb/PaymentOptions.php @@ -0,0 +1,58 @@ +getValue(); + + if (! is_array($values) || empty($values)) { + $this->setValue(array()); + } else { + $i = 0; + foreach ($values as $key => $value) { + $i++; + + if (empty($value)) { + continue; + } + + if (empty($value['label'])) { + $this->_throwError('Label', $i); + } + if (! empty($value['amount_min']) && (! is_numeric($value['amount_min']) || $value['amount_min'] < 0)) { + $this->_throwError('Minimum amount', $i); + } + if (! empty($value['amount_max']) && (! is_numeric($value['amount_max']) || $value['amount_max'] < 0)) { + $this->_throwError('Maximum amount', $i); + } + if (! is_numeric($value['rate']) || $value['rate'] > 100 || $value['rate'] < 0) { + $this->_throwError('Rate', $i); + } + if (! is_numeric($value['cap']) || $value['cap'] < 0) { + $this->_throwError('Cap', $i); + } + } + } + + return parent::_beforeSave(); + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Field/Gift/AddedCards.php b/app/code/community/Lyra/Payzen/Model/Field/Gift/AddedCards.php index 9395e891..a6d53a12 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Gift/AddedCards.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Gift/AddedCards.php @@ -1,6 +1,6 @@ fileExists($uploadDir . strtolower($card['code'] . '.png'))) { $cards[$key]['logo'] = strtolower($card['code'] . '.png'); } diff --git a/app/code/community/Lyra/Payzen/Model/Field/Logo.php b/app/code/community/Lyra/Payzen/Model/Field/Logo.php index e4173c3a..3d517d27 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Logo.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Logo.php @@ -1,6 +1,6 @@ message)) { Mage::throwException( - $this->message . "\n" . Mage::helper('payzen')->__('FacilyPay Oney payment mean cannot be used.') + $this->message . "\n" . Mage::helper('payzen')->__('FacilyPay Oney means of payment cannot be used.') ); } diff --git a/app/code/community/Lyra/Payzen/Model/Field/Oney/CustgroupOptions.php b/app/code/community/Lyra/Payzen/Model/Field/Oney/CustgroupOptions.php index 65a1a03c..0841335c 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Oney/CustgroupOptions.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Oney/CustgroupOptions.php @@ -1,6 +1,6 @@ getValue(); $data = $this->getGroups('payzen_oney'); // get data of FacilyPay Oney config group - if ($data['fields']['active']['value']) { // FacilyPay Oney is activated + if ($data['fields']['oney_active']['value']) { // FacilyPay Oney is activated foreach ($values as $key => $value) { if (empty($value) || ($value['code'] !== 'all')) { continue; diff --git a/app/code/community/Lyra/Payzen/Model/Field/Oney/PaymentOptions.php b/app/code/community/Lyra/Payzen/Model/Field/Oney/PaymentOptions.php index 138dc1c1..e8c752f5 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Oney/PaymentOptions.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Oney/PaymentOptions.php @@ -1,6 +1,6 @@ getValue())) > 127) { - $field = Mage::helper('payzen')->__((string)$this->getFieldConfig()->label); + $field = Mage::helper('payzen')->__((string) $this->getFieldConfig()->label); $group = Mage::helper('payzen')->getConfigGroupTitle($this->getGroupId()); $msg = sprintf(Mage::helper('payzen')->__('Invalid value for field «%s» in section «%s».'), $field, $group); diff --git a/app/code/community/Lyra/Payzen/Model/Field/ShipOptions.php b/app/code/community/Lyra/Payzen/Model/Field/ShipOptions.php index 45224257..81002ad6 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/ShipOptions.php +++ b/app/code/community/Lyra/Payzen/Model/Field/ShipOptions.php @@ -1,6 +1,6 @@ getValue(); if (! empty($value) && ! preg_match('|^https?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $value)) { - $field = Mage::helper('payzen')->__((string)$this->getFieldConfig()->label); + $field = Mage::helper('payzen')->__((string) $this->getFieldConfig()->label); $group = Mage::helper('payzen')->getConfigGroupTitle($this->getGroupId()); $msg = sprintf(Mage::helper('payzen')->__("Invalid value for field «%s» in section «%s»."), $field, $group); diff --git a/app/code/community/Lyra/Payzen/Model/Field/Standard/CardInfoModes.php b/app/code/community/Lyra/Payzen/Model/Field/Standard/CardInfoModes.php index 3172f57d..7af0210b 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Standard/CardInfoModes.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Standard/CardInfoModes.php @@ -1,6 +1,6 @@ error) { - Mage::throwException(Mage::helper('payzen')->__('The card data entry on merchant site cannot be used without enabling SSL.')); + Mage::throwException(Mage::helper('payzen')->__('The bank data acquisition on merchant site cannot be used without enabling SSL.')); } return parent::afterCommitCallback(); diff --git a/app/code/community/Lyra/Payzen/Model/Field/Standard/UseOney.php b/app/code/community/Lyra/Payzen/Model/Field/Standard/UseOney.php index 63744637..77f97995 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/Standard/UseOney.php +++ b/app/code/community/Lyra/Payzen/Model/Field/Standard/UseOney.php @@ -1,6 +1,6 @@ message = ''; - if ($this->getValue() /* propose FacilyPay Oney in standard payment enabled */) { + if ($this->getValue() /* propose FacilyPay Oney in one-time payment enabled */) { $data = $this->getGroups('payzen_oney'); // get data of FacilyPay Oney config group - $oneyActive = isset($data['fields']['active']['value']) && $data['fields']['active']['value']; + $oneyActive = isset($data['fields']['oney_active']['value']) && $data['fields']['oney_active']['value']; if ($oneyActive) { $this->setValue(0); @@ -48,7 +48,7 @@ public function save() public function afterCommitCallback() { if (! empty($this->message)) { - Mage::throwException($this->message . "\n" . Mage::helper('payzen')->__('FacilyPay Oney payment mean cannot be used.')); + Mage::throwException($this->message . "\n" . Mage::helper('payzen')->__('FacilyPay Oney means of payment cannot be used.')); } return parent::afterCommitCallback(); diff --git a/app/code/community/Lyra/Payzen/Model/Field/ThemeConfig.php b/app/code/community/Lyra/Payzen/Model/Field/ThemeConfig.php index 024b503b..47a61293 100644 --- a/app/code/community/Lyra/Payzen/Model/Field/ThemeConfig.php +++ b/app/code/community/Lyra/Payzen/Model/Field/ThemeConfig.php @@ -1,6 +1,6 @@ getValue(); if (! empty($value) && ! preg_match('#^[^;=]+=[^;=]*(;[^;=]+=[^;=]*)*;?$#', $value)) { - $field = Mage::helper('payzen')->__((string)$this->getFieldConfig()->label); + $field = Mage::helper('payzen')->__((string) $this->getFieldConfig()->label); $group = Mage::helper('payzen')->getConfigGroupTitle($this->getGroupId()); $msg = sprintf(Mage::helper('payzen')->__("Invalid value for field «%s» in section «%s»."), $field, $group); diff --git a/app/code/community/Lyra/Payzen/Model/Field/Translatable.php b/app/code/community/Lyra/Payzen/Model/Field/Translatable.php new file mode 100644 index 00000000..f51c215b --- /dev/null +++ b/app/code/community/Lyra/Payzen/Model/Field/Translatable.php @@ -0,0 +1,48 @@ +getValue(); + $default = (string) Mage::getConfig()->getNode('default/' . $this->getPath()); + if ($value && ($value === $default)) { + $translator = Mage::getSingleton('core/translate'); + $locale = $translator->getLocale(); + + // force default view locale + $viewLocale = Mage::getStoreConfig('general/locale/code', 0); + $translator->setLocale($viewLocale)->init('frontend', true); + + $this->setValue(Mage::helper('payzen')->__($value)); + + // restore initial locale + $translator->setLocale($locale)->init('adminhtml', true); + } + + return $this; + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Observer.php b/app/code/community/Lyra/Payzen/Model/Observer.php index e3dff01a..efce9c35 100644 --- a/app/code/community/Lyra/Payzen/Model/Observer.php +++ b/app/code/community/Lyra/Payzen/Model/Observer.php @@ -1,6 +1,6 @@ getRequest()->getPost('order')) { - $flag = isset($data['send_confirmation']) ? (bool)$data['send_confirmation'] : false; + $flag = isset($data['send_confirmation']) ? (bool) $data['send_confirmation'] : false; } $session = Mage::getSingleton('adminhtml/session_quote'); @@ -246,7 +246,7 @@ public function doOneclickQuoteProcess($observer) } } elseif ($block->getNameInLayout() == 'alert.urls') { if (($product = Mage::registry('product')) && $product->getId()) { - $this->_oneclickQuoteProcess($block->getProduct()); + $this->_oneclickQuoteProcess($product); } } } @@ -331,7 +331,7 @@ public function doPaymentButtonsManage($observer) if ($order && $order->getPayment() && stripos($order->getPayment()->getMethod(), 'payzen_') === 0) { switch ($order->getStatus()) { case 'payzen_to_validate': - $message = $this->_getHelper()->__('Are you sure you want to validate this order in PayZen platform ?'); + $message = $this->_getHelper()->__('Are you sure you want to validate this order in PayZen gateway ?'); $block->addButton('payzen_validate_payment', array( 'label' => $this->_getHelper()->__('Validate payment'), diff --git a/app/code/community/Lyra/Payzen/Model/Order.php b/app/code/community/Lyra/Payzen/Model/Order.php index e8e7617a..f48b5477 100644 --- a/app/code/community/Lyra/Payzen/Model/Order.php +++ b/app/code/community/Lyra/Payzen/Model/Order.php @@ -1,6 +1,6 @@ _payzenRequest->set('amount', $currency->convertAmountToInteger($amount)); - $this->_payzenRequest->set('contrib', 'Magento1.4-1.9_1.8.0/' . Mage::getVersion() . '/' . PHP_VERSION); + $this->_payzenRequest->set('contrib', 'Magento1.4-1.9_1.9.0/' . Mage::getVersion() . '/' . PHP_VERSION); // set config parameters $configFields = array('site_id', 'key_test', 'key_prod', 'ctx_mode', 'capture_delay', 'validation_mode', @@ -115,7 +115,7 @@ public function getFormFields($order) // activate 3ds ? $threedsMpi = null; - $configOptions = unserialize($this->getConfigData('custgroup_threeds_min_amount')); + $configOptions = unserialize($this->_getHelper()->getCommonConfigData('custgroup_threeds_min_amount')); if (is_array($configOptions) && ! empty($configOptions)) { $group = $order->getCustomerGroupId(); @@ -144,10 +144,11 @@ public function getFormFields($order) $threedsMinAmount = $allThreedsMinAmount; } - if ($threedsMinAmount && $order->getTotalDue() < $threedsMinAmount) { + if ($threedsMinAmount && ($order->getTotalDue() < $threedsMinAmount)) { $threedsMpi = '2'; } } + $this->_payzenRequest->set('threeds_mpi', $threedsMpi); $this->_payzenRequest->set('cust_email', $order->getCustomerEmail()); @@ -221,7 +222,7 @@ public function getConfigData($field, $storeId = null) } /** - * Return the payment platform URL. + * Return the payment gateway URL. * * @return string */ @@ -454,7 +455,8 @@ public function denyPayment(Mage_Payment_Model_Info $payment) // new transaction status $additionalInfo['Transaction Status'] = 'CANCELLED'; - $this->_getPaymentHelper()->addTransaction($payment, Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, $transactionId, $additionalInfo); + $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID; + $this->_getPaymentHelper()->addTransaction($payment, $transactionType, $transactionId, $additionalInfo); return true; // let Magento cancel order } catch(Lyra_Payzen_Model_WsException $e) { @@ -626,8 +628,8 @@ public function validate() $shippingAddress = $info->getQuote()->isVirtual() ? null : $info->getQuote()->getShippingAddress(); } - Mage::helper('payzen/util')->checkAddressValidity($billingAddress); - Mage::helper('payzen/util')->checkAddressValidity($shippingAddress); + Mage::helper('payzen/util')->checkAddressValidity($billingAddress, 'oney'); + Mage::helper('payzen/util')->checkAddressValidity($shippingAddress, 'oney'); return $this; } else { @@ -1004,7 +1006,7 @@ protected function createRefundTransaction($payment, $commonResponse, $paymentRe 'Amount' => $amountDetail, 'Transaction ID' => $transactionId, 'Transaction Status' => $commonResponse->getTransactionStatusLabel(), - 'Payment Mean' => $cardResponse->getBrand(), + 'Means of Payment' => $cardResponse->getBrand(), 'Credit Card Number' => $cardResponse->getNumber(), 'Expiration Date' => $expiry ); diff --git a/app/code/community/Lyra/Payzen/Model/Payment/Choozeo.php b/app/code/community/Lyra/Payzen/Model/Payment/Choozeo.php index 5e0d7e9f..e553f25c 100644 --- a/app/code/community/Lyra/Payzen/Model/Payment/Choozeo.php +++ b/app/code/community/Lyra/Payzen/Model/Payment/Choozeo.php @@ -1,6 +1,6 @@ _payzenRequest->set('cust_status', 'PRIVATE'); + $this->_payzenRequest->set('validation_mode', '0'); + $this->_payzenRequest->set('capture_delay', '0'); + + // override with selected FullCB payment card + $info = $this->getInfoInstance(); + + // set choosen option if any + if ($info->getAdditionalData() && ($option = @unserialize($info->getAdditionalData()))) { + $this->_payzenRequest->set('payment_cards', $option['code']); + } else { + $this->_payzenRequest->set('payment_cards', 'FULLCB3X;FULLCB4X'); + } + } + + /** + * Assign data to info model instance + * + * @param mixed $data + * @return Mage_Payment_Model_Info + */ + public function assignData($data) + { + $info = $this->getInfoInstance(); + + $option = $this->_getOption($data->getPayzenFullcbOption()); + + // init all payment data + $info->setAdditionalData($option ? serialize($option) : null) + ->setCcType(null) + ->setCcLast4(null) + ->setCcNumber(null) + ->setCcCid(null) + ->setCcExpMonth(null) + ->setCcExpYear(null); + + return $this; + } + + /** + * Return true if the method can be used at this time + * + * @return bool + */ + public function isAvailable($quote = null) + { + if (! parent::isAvailable($quote)) { + return false; + } + + $amount = $quote ? $quote->getBaseGrandTotal() : null; + if ($amount) { + if ($this->getConfigData('enable_payment_options') == 1) { + $options = $this->getPaymentOptions($amount); + return ! empty($options); + } + } + + return true; + } + + /** + * Get available payment options for the current cart amount. + * @param double $amount a given amount + * @return array[string][array] an array "$code => $option" of available options + */ + public function getPaymentOptions($amount) + { + $configOptions = unserialize($this->getConfigData('payment_options')); + if (! is_array($configOptions) || empty($configOptions)) { + return false; + } + + $availOptions = array(); + foreach ($configOptions as $code => $value) { + if (empty($value)) { + continue; + } + + if ((! $amount || ! $value['amount_min'] || $amount > $value['amount_min']) + && (! $amount || ! $value['amount_max'] || $amount < $value['amount_max'])) { + // option will be available + $availOptions[$code] = $value; + } + } + + return $availOptions; + } + + protected function _getOption($code) + { + $info = $this->getInfoInstance(); + if ($info instanceof Mage_Sales_Model_Order_Payment) { + $amount = $info->getOrder()->getBaseGrandTotal(); + } else { + $amount = $info->getQuote()->getBaseGrandTotal(); + } + + $options = $this->getPaymentOptions($amount); + if ($code && $options[$code]) { + return $options[$code]; + } else { + return false; + } + } + + /** + * Validate payment method information object + * + * @param Mage_Payment_Model_Info $info + * @return Mage_Payment_Model_Abstract + */ + public function validate() + { + $info = $this->getInfoInstance(); + if ($info instanceof Mage_Sales_Model_Order_Payment) { + $billingAddress = $info->getOrder()->getBillingAddress(); + $shippingAddress = $info->getOrder()->getIsVirtual() ? null : $info->getOrder()->getShippingAddress(); + } else { + $billingAddress = $info->getQuote()->getBillingAddress(); + $shippingAddress = $info->getQuote()->isVirtual() ? null : $info->getQuote()->getShippingAddress(); + } + + Mage::helper('payzen/util')->checkAddressValidity($billingAddress, 'fullcb'); + Mage::helper('payzen/util')->checkAddressValidity($shippingAddress, 'fullcb'); + + return $this; + + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Payment/Gift.php b/app/code/community/Lyra/Payzen/Model/Payment/Gift.php index 24ff7de3..dea545e2 100644 --- a/app/code/community/Lyra/Payzen/Model/Payment/Gift.php +++ b/app/code/community/Lyra/Payzen/Model/Payment/Gift.php @@ -1,6 +1,6 @@ getCustomerId() && ! preg_match(Lyra_Payzen_Helper_Util::CUST_ID_REGEX, $quote->getCustomerId())) { // customer id doesn't match FacilyPay Oney rules - $msg = 'Customer ID "%s" does not match PayZen specifications. The regular expression for this field is %s. FacilyPay Oney payment mean cannot be used.'; + $msg = 'Customer ID "%s" does not match PayZen specifications. The regular expression for this field is %s. FacilyPay Oney means of payment cannot be used.'; $this->_getHelper()->log(sprintf($msg, $quote->getCustomerId(), Lyra_Payzen_Helper_Util::CUST_ID_REGEX), Zend_Log::WARN); return false; } @@ -170,7 +170,7 @@ public function isAvailable($quote = null) if (! preg_match(Lyra_Payzen_Helper_Util::ORDER_ID_REGEX, $quote->getReservedOrderId())) { // order id doesn't match FacilyPay Oney rules - $msg = 'The order ID "%s" does not match PayZen specifications. The regular expression for this field is %s. FacilyPay Oney payment mean cannot be used.'; + $msg = 'The order ID "%s" does not match PayZen specifications. The regular expression for this field is %s. FacilyPay Oney means of payment cannot be used.'; $this->_getHelper()->log(sprintf($msg, $quote->getReservedOrderId(), Lyra_Payzen_Helper_Util::ORDER_ID_REGEX), Zend_Log::WARN); return false; } @@ -184,7 +184,7 @@ public function isAvailable($quote = null) if (! preg_match(Lyra_Payzen_Helper_Util::PRODUCT_REF_REGEX, $item->getProductId())) { // product id doesn't match FacilyPay Oney rules - $msg = 'Product reference "%s" does not match PayZen specifications. The regular expression for this field is %s. FacilyPay Oney payment mean cannot be used.'; + $msg = 'Product reference "%s" does not match PayZen specifications. The regular expression for this field is %s. FacilyPay Oney means of payment cannot be used.'; $this->_getHelper()->log(sprintf($msg, $item->getProductId(), Lyra_Payzen_Helper_Util::PRODUCT_REF_REGEX), Zend_Log::WARN); return false; } diff --git a/app/code/community/Lyra/Payzen/Model/Payment/Paypal.php b/app/code/community/Lyra/Payzen/Model/Payment/Paypal.php index 63c279fd..f064a80f 100644 --- a/app/code/community/Lyra/Payzen/Model/Payment/Paypal.php +++ b/app/code/community/Lyra/Payzen/Model/Payment/Paypal.php @@ -1,6 +1,6 @@ _payzenRequest->set('payment_cards', 'SDD'); + $this->_payzenRequest->set('page_action', $this->getConfigData('mandate_mode')); + } + + /** + * Assign data to info model instance. + * + * @param mixed $data + * @return Mage_Payment_Model_Info + */ + public function assignData($data) + { + $info = $this->getInfoInstance(); + + // init all payment data + $info->setCcType(null) + ->setCcLast4(null) + ->setCcNumber(null) + ->setCcCid(null) + ->setCcExpMonth(null) + ->setCcExpYear(null) + ->setAdditionalData(null); + + return $this; + } + + public function canUseForCountry($country) + { + $availableCountries = Mage::getModel('payzen/source_sepa_availableCountries')->getCountryCodes(); + + if ($this->getConfigData('allowspecific') == 1) { + $availableCountries = explode(',', $this->getConfigData('specificcountry')); + } + + return in_array($country, $availableCountries); + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Payment/Sofort.php b/app/code/community/Lyra/Payzen/Model/Payment/Sofort.php index 2b53258b..ef48437d 100644 --- a/app/code/community/Lyra/Payzen/Model/Payment/Sofort.php +++ b/app/code/community/Lyra/Payzen/Model/Payment/Sofort.php @@ -1,6 +1,6 @@ _getHelper()->isAdmin() && ($this->isLocalCcType() || $this->isLocalCcInfo())) { // set payment_cards $this->_payzenRequest->set('payment_cards', $info->getCcType()); + + if ($info->getCcType() === 'BANCONTACT') { + // may not disable 3-DS for Bancontact Mistercash + $this->_payzenRequest->set('threeds_mpi', null); + } } else { // payment_cards is given as csv by magento $paymentCards = explode(',', $this->getConfigData('payment_cards')); @@ -41,6 +46,7 @@ protected function _setExtraFields($order) // add FacilyPay Oney payment cards $paymentCards .= ';' . ($testMode ? 'ONEY_SANDBOX' : 'ONEY'); } + $this->_payzenRequest->set('payment_cards', $paymentCards); } @@ -78,7 +84,6 @@ protected function _setExtraFields($order) } else { if ($this->isLocalCcInfo() && $info->getAdditionalData()) { // additional_data is used to stock cc_register flag // customer wants to register card data - if ($customer->getPayzenIdentifier()) { // customer has already an identifier $this->_getHelper()->log('Customer ' . $customer->getEmail() . ' has an identifier and chose to update it with new card info.'); @@ -146,7 +151,8 @@ public function getAvailableCcTypes() $cards = array_diff($cards, array('ONEY_SANDBOX', 'ONEY')); } - if (! $this->_getHelper()->isAdmin() && $this->isLocalCcType() && $this->getConfigData('use_oney_in_standard')) { + if (! $this->_getHelper()->isAdmin() && $this->isLocalCcType() + && $this->getConfigData('use_oney_in_standard')) { $testMode = $this->_getHelper()->getCommonConfigData('ctx_mode') == 'TEST'; $cards[] = $testMode ? 'ONEY_SANDBOX' : 'ONEY'; @@ -158,6 +164,7 @@ public function getAvailableCcTypes() $availCards[$code] = $label; } } + return $availCards; } @@ -197,7 +204,8 @@ public function isIdentifierPayment($customer) $info = $this->getInfoInstance(); // payment by identifier - return $customer->getPayzenIdentifier() && $info->getAdditionalInformation(Lyra_Payzen_Helper_Payment::IDENTIFIER); + return $customer->getPayzenIdentifier() + && $info->getAdditionalInformation(Lyra_Payzen_Helper_Payment::IDENTIFIER); } /** @@ -344,16 +352,22 @@ protected function _doInstantPayment($payment) $captureDelay = $this->getConfigData('capture_delay', $storeId); // get sub-module specific param if (! is_numeric($captureDelay)) { - $captureDelay = $this->_getHelper()->getCommonConfigData('capture_delay', $storeId); // get general param + // get general param + $captureDelay = $this->_getHelper()->getCommonConfigData('capture_delay', $storeId); } + if (is_numeric($captureDelay)) { - $paymentRequest->setExpectedCaptureDate(new DateTime('@' . strtotime("+$captureDelay days", $timestamp))); + $paymentRequest->setExpectedCaptureDate( + new DateTime('@' . strtotime("+$captureDelay days", $timestamp)) + ); } $validationMode = $this->getConfigData('validation_mode', $storeId); // get sub-module specific param if ($validationMode === '-1') { - $validationMode = $this->_getHelper()->getCommonConfigData('validation_mode', $storeId); // get general param + // get general param + $validationMode = $this->_getHelper()->getCommonConfigData('validation_mode', $storeId); } + if ($validationMode !== '') { $paymentRequest->setManualValidation($validationMode); } @@ -383,7 +397,10 @@ protected function _doInstantPayment($payment) $billingDetailsRequest->setLastName($order->getBillingAddress()->getLastname()); $billingDetailsRequest->setPhoneNumber($order->getBillingAddress()->getTelephone()); $billingDetailsRequest->setEmail($order->getCustomerEmail()); - $billingDetailsRequest->setAddress(trim($order->getBillingAddress()->getStreet(1) . ' ' . $order->getBillingAddress()->getStreet(2))); + + $address = $order->getBillingAddress()->getStreet(1) . ' ' . $order->getBillingAddress()->getStreet(2); + $billingDetailsRequest->setAddress(trim($address)); + $billingDetailsRequest->setZipCode($order->getBillingAddress()->getPostcode()); $billingDetailsRequest->setCity($order->getBillingAddress()->getCity()); $billingDetailsRequest->setState($order->getBillingAddress()->getRegion()); @@ -396,6 +413,7 @@ protected function _doInstantPayment($payment) } else { $language = $this->_getHelper()->getCommonConfigData('language', $storeId); } + $billingDetailsRequest->setLanguage($language); // shipping details generation @@ -474,7 +492,7 @@ protected function _doInstantPayment($payment) $stateObject->setStatus($stateObject->getBeforeStatus()); } - // save platform responses + // save gateway responses $this->_getPaymentHelper()->updatePaymentInfo($order, $wrapper); // try to create invoice @@ -482,7 +500,6 @@ protected function _doInstantPayment($payment) $stateObject->setIsNotified(true); return $stateObject; - } catch(Lyra_Payzen_Model_WsException $e) { $this->_getHelper()->log("[$requestId] {$e->getMessage()}", Zend_Log::WARN); @@ -491,14 +508,20 @@ protected function _doInstantPayment($payment) $this->_getAdminSession()->addError($this->_getHelper()->__($e->getMessage())); Mage::throwException(''); } catch(\SoapFault $f) { - $this->_getHelper()->log("[$requestId] SoapFault with code {$f->faultcode}: {$f->faultstring}.", Zend_Log::WARN); + $this->_getHelper()->log( + "[$requestId] SoapFault with code {$f->faultcode}: {$f->faultstring}.", + Zend_Log::WARN + ); $warn = $this->_getHelper()->__('Please correct this error to use PayZen web services.'); $this->_getAdminSession()->addWarning($warn); $this->_getAdminSession()->addError($f->faultstring); Mage::throwException(''); } catch(\UnexpectedValueException $e) { - $this->_getHelper()->log("[$requestId] createPayment error with code {$e->getCode()}: {$e->getMessage()}.", Zend_Log::ERR); + $this->_getHelper()->log( + "[$requestId] createPayment error with code {$e->getCode()}: {$e->getMessage()}.", + Zend_Log::ERR + ); if ($e->getCode() === -1) { $this->_getAdminSession()->addError($this->_getHelper()->__('Authentication error ! ')); @@ -508,7 +531,10 @@ protected function _doInstantPayment($payment) Mage::throwException(''); } catch (Exception $e) { - $this->_getHelper()->log("[$requestId] Exception with code {$e->getCode()}: {$e->getMessage()}", Zend_Log::ERR); + $this->_getHelper()->log( + "[$requestId] Exception with code {$e->getCode()}: {$e->getMessage()}", + Zend_Log::ERR + ); $this->_getAdminSession()->addError($e->getMessage()); Mage::throwException(''); @@ -522,7 +548,7 @@ protected function _doInstantPayment($payment) public function isLocalCcInfo() { return $this->_getHelper()->isCurrentlySecure() // this is a double check, it's also done on backend side - && $this->getConfigData('card_info_mode') == 3; + && $this->getConfigData('card_info_mode') == 3; } /** diff --git a/app/code/community/Lyra/Payzen/Model/Resource/Setup.php b/app/code/community/Lyra/Payzen/Model/Resource/Setup.php index 8de73c6d..72adff89 100644 --- a/app/code/community/Lyra/Payzen/Model/Resource/Setup.php +++ b/app/code/community/Lyra/Payzen/Model/Resource/Setup.php @@ -1,6 +1,6 @@ getConfigArray('product_categories') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => Mage::helper('payzen')->__($name) + $options[] = array( + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) ); } - array_unshift($options, array('value' => 'CUSTOM_MAPPING', 'label' => Mage::helper('payzen')->__('(Use category mapping below)'))); + array_unshift($options, array('value' => 'CUSTOM_MAPPING', 'label' => Mage::helper('payzen')->__('(Use category mapping below)'))); return $options; } diff --git a/app/code/community/Lyra/Payzen/Model/Source/CtxModes.php b/app/code/community/Lyra/Payzen/Model/Source/CtxModes.php index 5ea2d27b..9faa8180 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/CtxModes.php +++ b/app/code/community/Lyra/Payzen/Model/Source/CtxModes.php @@ -1,6 +1,6 @@ getConfigArray('ctx_modes') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => $name + $options[] = array( + 'value' => $code, + 'label' => $name ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Gift/GiftCards.php b/app/code/community/Lyra/Payzen/Model/Source/Gift/GiftCards.php index af7bb928..13d83e01 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Gift/GiftCards.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Gift/GiftCards.php @@ -1,6 +1,6 @@ getSupportedGcTypes() as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => $name + $options[] = array( + 'value' => $code, + 'label' => $name ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Languages.php b/app/code/community/Lyra/Payzen/Model/Source/Languages.php index 7527c5e3..f4a22fb1 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Languages.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Languages.php @@ -1,6 +1,6 @@ $name) { $options[] = array ( - 'value' => $code, - 'label' => Mage::helper('payzen')->__($name) + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Multi/CardInfoModes.php b/app/code/community/Lyra/Payzen/Model/Source/Multi/CardInfoModes.php index 5ea27ee7..cd5660cf 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Multi/CardInfoModes.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Multi/CardInfoModes.php @@ -1,6 +1,6 @@ getConfigArray('multi_card_info_modes') as $code => $name) { - $options[] = array - ( + $options[] = array( 'value' => $code, 'label' => Mage::helper('payzen')->__($name) ); diff --git a/app/code/community/Lyra/Payzen/Model/Source/Multi/PaymentCards.php b/app/code/community/Lyra/Payzen/Model/Source/Multi/PaymentCards.php index bd0e73aa..c44373e6 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Multi/PaymentCards.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Multi/PaymentCards.php @@ -1,6 +1,6 @@ $code, - 'label' => $name + 'value' => $code, + 'label' => $name ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/PaymentCards.php b/app/code/community/Lyra/Payzen/Model/Source/PaymentCards.php index c730a7b9..df1525d0 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/PaymentCards.php +++ b/app/code/community/Lyra/Payzen/Model/Source/PaymentCards.php @@ -1,6 +1,6 @@ '', - 'label' => Mage::helper('payzen')->__('ALL') + 'value' => '', + 'label' => Mage::helper('payzen')->__('ALL') ); foreach (Lyra_Payzen_Model_Api_Api::getSupportedCardTypes() as $code => $name) { @@ -32,8 +32,8 @@ public function toOptionArray() } $options[] = array ( - 'value' => $code, - 'label' => $name + 'value' => $code, + 'label' => $name ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/ReturnModes.php b/app/code/community/Lyra/Payzen/Model/Source/ReturnModes.php index f76f5c60..e7c3108f 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/ReturnModes.php +++ b/app/code/community/Lyra/Payzen/Model/Source/ReturnModes.php @@ -1,6 +1,6 @@ getConfigArray('return_modes') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => Mage::helper('payzen')->__($name) + $options[] = array( + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Sepa/AvailableCountries.php b/app/code/community/Lyra/Payzen/Model/Source/Sepa/AvailableCountries.php new file mode 100644 index 00000000..c94e4472 --- /dev/null +++ b/app/code/community/Lyra/Payzen/Model/Source/Sepa/AvailableCountries.php @@ -0,0 +1,47 @@ +_availableCountries as $code) { + $name = Mage::app()->getLocale()->getCountryTranslation($code); + if (empty($name)) { + $name = $code; + } + + $result[] = array( + 'value' => $code, + 'label' => $name + ); + } + + return $result; + } + + public function getCountryCodes() + { + return $this->_availableCountries; + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Source/Sepa/MandateModes.php b/app/code/community/Lyra/Payzen/Model/Source/Sepa/MandateModes.php new file mode 100644 index 00000000..71f8376f --- /dev/null +++ b/app/code/community/Lyra/Payzen/Model/Source/Sepa/MandateModes.php @@ -0,0 +1,34 @@ +getConfigArray('mandate_modes') as $code => $name) { + $options[] = array( + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) + ); + } + + return $options; + } +} diff --git a/app/code/community/Lyra/Payzen/Model/Source/SignAlgos.php b/app/code/community/Lyra/Payzen/Model/Source/SignAlgos.php index dc3aa551..797aada0 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/SignAlgos.php +++ b/app/code/community/Lyra/Payzen/Model/Source/SignAlgos.php @@ -1,6 +1,6 @@ getConfigArray('sign_algos') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => $name + $options[] = array( + 'value' => $code, + 'label' => $name ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Sofort/AvailableCountries.php b/app/code/community/Lyra/Payzen/Model/Source/Sofort/AvailableCountries.php index fb6685fd..24355775 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Sofort/AvailableCountries.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Sofort/AvailableCountries.php @@ -1,6 +1,6 @@ $code, - 'label' => $name + 'value' => $code, + 'label' => $name ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Standard/CardInfoModes.php b/app/code/community/Lyra/Payzen/Model/Source/Standard/CardInfoModes.php index 233dea64..08c4c2b9 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Standard/CardInfoModes.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Standard/CardInfoModes.php @@ -1,6 +1,6 @@ getConfigArray('card_info_modes') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => Mage::helper('payzen')->__($name) + if (($code == 3) && ! Lyra_Payzen_Helper_Data::$pluginFeatures['acquis']) { + // card data acquisition on merchant website not available for all + continue; + } + + $options[] = array( + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Standard/CardRegisterModes.php b/app/code/community/Lyra/Payzen/Model/Source/Standard/CardRegisterModes.php index a2f4d11d..44b58b58 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Standard/CardRegisterModes.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Standard/CardRegisterModes.php @@ -1,6 +1,6 @@ getConfigArray('card_register_modes') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => Mage::helper('payzen')->__($name) + $options[] = array( + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/Standard/OneClickLocations.php b/app/code/community/Lyra/Payzen/Model/Source/Standard/OneClickLocations.php index 77100ba4..adbb65d3 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/Standard/OneClickLocations.php +++ b/app/code/community/Lyra/Payzen/Model/Source/Standard/OneClickLocations.php @@ -1,6 +1,6 @@ getConfigArray('one_click_locations') as $code => $name) { - $options[] = array - ( - 'value' => $code, - 'label' => Mage::helper('payzen')->__($name) + $options[] = array( + 'value' => $code, + 'label' => Mage::helper('payzen')->__($name) ); } diff --git a/app/code/community/Lyra/Payzen/Model/Source/ValidationModes.php b/app/code/community/Lyra/Payzen/Model/Source/ValidationModes.php index bceab7ca..3c9e325c 100644 --- a/app/code/community/Lyra/Payzen/Model/Source/ValidationModes.php +++ b/app/code/community/Lyra/Payzen/Model/Source/ValidationModes.php @@ -1,6 +1,6 @@ (string)$code, - 'label' => Mage::helper('payzen')->__($name) + 'value' => (string) $code, + 'label' => Mage::helper('payzen')->__($name) ); } diff --git a/app/code/community/Lyra/Payzen/Model/WsException.php b/app/code/community/Lyra/Payzen/Model/WsException.php index cbedfc19..6a8b81a6 100644 --- a/app/code/community/Lyra/Payzen/Model/WsException.php +++ b/app/code/community/Lyra/Payzen/Model/WsException.php @@ -1,6 +1,6 @@ getCheckout()->getMessages(true); $this->getAdminSession()->getMessages(true); - $this->getAdminSession()->addError($this->__('An error has occured during the payment process.')); + $this->getAdminSession()->addError($this->__('An error has occurred during the payment process.')); + + $this->_getDataHelper()->log("Redirecting to order create page for order #{$order->getId()}."); $this->_redirect('adminhtml/sales_order_create/index'); } @@ -113,10 +115,12 @@ public function redirectResponse($order, $success, $checkUrlWarn = false) $storeId = $order->getStore()->getId(); if ($this->_getDataHelper()->getCommonConfigData('ctx_mode', $storeId) == 'TEST') { - // display going to production message - $message = $this->__('GOING INTO PRODUCTION
You want to know how to put your shop into production mode, please go to this URL : '); - $message .= 'https://secure.payzen.eu/html/faq/prod'; - $this->getAdminSession()->addNotice($message); + if (Lyra_Payzen_Helper_Data::$pluginFeatures['prodfaq']) { + // display going to production message + $message = $this->__('GOING INTO PRODUCTION
You want to know how to put your shop into production mode, please go to this URL : '); + $message .= 'https://secure.payzen.eu/html/faq/prod'; + $this->getAdminSession()->addNotice($message); + } if ($checkUrlWarn) { // order not validated by notification URL, in TEST mode, user is webmaster @@ -137,7 +141,9 @@ public function redirectResponse($order, $success, $checkUrlWarn = false) if ($success) { $this->_getDataHelper()->log("Redirecting to order review page for order #{$order->getId()}."); $this->getCheckout()->setLastSuccessQuoteId($order->getQuoteId()); - $this->getAdminSession()->addSuccess($this->__('The payment was successful. Your order was registered successfully.')); + $this->getAdminSession()->addSuccess( + $this->__('The payment was successful. Your order was registered successfully.') + ); $this->_redirect('adminhtml/sales_order/view', array('order_id' => $order->getId())); } else { $this->_getDataHelper()->log("Unsetting order data in session for order #{$order->getId()}."); diff --git a/app/code/community/Lyra/Payzen/controllers/PaymentController.php b/app/code/community/Lyra/Payzen/controllers/PaymentController.php index 65c1eae6..40ca86c8 100644 --- a/app/code/community/Lyra/Payzen/controllers/PaymentController.php +++ b/app/code/community/Lyra/Payzen/controllers/PaymentController.php @@ -1,6 +1,6 @@ _getDataHelper()->log('Start ================================================='); + if ($this->getRequest()->getParam('mode', null) === 'cancel') { + // load order + $lastIncrementId = $this->getCheckout()->getLastRealOrderId(); + $order = Mage::getModel('sales/order'); + $order->loadByIncrementId($lastIncrementId); + + if ($order->getId()) { + $this->_getDataHelper()->log("Cancel order #{$order->getId()} to allow payment retry."); + $order->registerCancellation($this->__('Payment canceled.'))->save(); + + $this->_getDataHelper()->log("Clean session for #{$order->getId()} and restore last quote if any."); + $this->getCheckout()->setLastBillingAgreementId(null) + ->setRedirectUrl(null) + ->setLastOrderId(null) + ->setLastRealOrderId(null) + ->setLastRecurringProfileIds(null) + ->setAdditionalMessages(null); + + $quote = Mage::getModel('sales/quote')->load($order->getQuoteId()); + if ($quote->getId()) { + $quote->setIsActive(true)->setReservedOrderId(null)->save(); + $this->getCheckout()->replaceQuote($quote); + } + } + } + $block = $this->getLayout()->createBlock('core/template')->setTemplate('payzen/iframe/loader.phtml'); $this->getResponse()->setBody($block->toHtml()); + $this->_getDataHelper()->log('End ================================================='); } /** @@ -165,7 +193,9 @@ public function oneclickPaymentAction() // restore initial checkout quote if ($this->getPayzenSession()->getPayzenInitialQuoteId()) { - $quote = Mage::getModel('sales/quote')->load((int)$this->getPayzenSession()->getPayzenInitialQuoteId(true)); + $quote = Mage::getModel('sales/quote')->load( + (int) $this->getPayzenSession()->getPayzenInitialQuoteId(true) + ); if ($quote->getId()) { $quote->setIsActive(true)->save(); @@ -218,13 +248,14 @@ protected function _updateOneclickQuote($ignoreNotices = false) if ($productId = $this->getRequest()->getPost('product', false)) { $product = Mage::getModel('catalog/product') ->setStoreId(Mage::app()->getStore()->getId()) - ->load((int)$productId); + ->load((int) $productId); if ($product->getId()) { // remove all 1-Click quote items to refresh it foreach ($oneClickQuote->getItemsCollection() as $item) { $oneClickQuote->removeItem($item->getId()); } + $oneClickQuote->getShippingAddress()->removeAllShippingRates(); $oneClickQuote->setCouponCode(''); @@ -286,9 +317,8 @@ protected function _updateOneclickQuote($ignoreNotices = false) } if (! $allAdded) { - $this->getCoreSession()->addError( - $this->__('Some of the products you requested are not available in the desired quantity.') - ); + $msg = 'Some of the products you requested are not available in the desired quantity.'; + $this->getCoreSession()->addError($this->__($msg)); } } } @@ -297,7 +327,7 @@ protected function _updateOneclickQuote($ignoreNotices = false) } $addressId = $this->getRequest()->getPost('shipping_address', false); - $customerAddress = Mage::getModel('customer/address')->load((int)$addressId); + $customerAddress = Mage::getModel('customer/address')->load((int) $addressId); if (! $oneClickQuote->isVirtual() && $customerAddress->getId()) { if ($customerAddress->getCustomerId() != Mage::getSingleton('customer/session')->getCustomer()->getId()) { Mage::throwException($this->__('Customer Address is not valid.')); @@ -331,7 +361,7 @@ public function redirectBack($msg) } /** - * Redirect to error page (when an unexpected error occured). + * Redirect to error page (when an unexpected error occurred). * * @param Mage_Sales_Model_Order $order */ @@ -360,10 +390,12 @@ public function redirectResponse($order, $success, $checkUrlWarn = false) $storeId = $order->getStore()->getId(); if ($this->_getDataHelper()->getCommonConfigData('ctx_mode', $storeId) == 'TEST') { - // display going to production message - $message = $this->__('GOING INTO PRODUCTION
You want to know how to put your shop into production mode, please go to this URL : '); - $message .= 'https://secure.payzen.eu/html/faq/prod'; - $this->getCoreSession()->addNotice($message); + if (Lyra_Payzen_Helper_Data::$pluginFeatures['prodfaq']) { + // display going to production message + $message = $this->__('GOING INTO PRODUCTION
You want to know how to put your shop into production mode, please go to this URL : '); + $message .= 'https://secure.payzen.eu/html/faq/prod'; + $this->getCoreSession()->addNotice($message); + } if ($checkUrlWarn) { // order not validated by notification URL, in TEST mode, user is webmaster @@ -416,7 +448,9 @@ public function redirectResponse($order, $success, $checkUrlWarn = false) $this->getPayzenSession()->unsPayzenInitialQuoteId(); // in case of 1-Click payment , redirect to referer URL - $this->_getDataHelper()->log("Redirecting to referer URL (product view or cart page) for order #{$order->getId()}."); + $this->_getDataHelper()->log( + "Redirecting to referer URL (product view or cart page) for order #{$order->getId()}." + ); $this->_redirectUrl($this->getPayzenSession()->getPayzenOneclickBackUrl(true)); } else { $this->_getDataHelper()->log("Restore cart for order #{$order->getId()} to allow re-order quicker."); diff --git a/app/code/community/Lyra/Payzen/data/payzen_setup/data-install-1.6.0.php b/app/code/community/Lyra/Payzen/data/payzen_setup/data-install-1.6.0.php index e4a83e28..315e16fd 100644 --- a/app/code/community/Lyra/Payzen/data/payzen_setup/data-install-1.6.0.php +++ b/app/code/community/Lyra/Payzen/data/payzen_setup/data-install-1.6.0.php @@ -1,6 +1,6 @@ select()->from($statusTable, 'status')->where('status = "payzen_to_validate"'); if (! $connection->fetchOne($select)) { // status does not exist $connection->insert( - $statusTable, - array('status' => 'payzen_to_validate', 'label' => 'To validate payment') + $statusTable, + array('status' => 'payzen_to_validate', 'label' => 'To validate payment') ); $connection->insert( - $stateTable, - array('status' => 'payzen_to_validate', 'state' => 'payment_review', 'is_default' => 0) + $stateTable, + array('status' => 'payzen_to_validate', 'state' => 'payment_review', 'is_default' => 0) ); } -$installer->endSetup(); \ No newline at end of file +$installer->endSetup(); diff --git a/app/code/community/Lyra/Payzen/data/payzen_setup/data-upgrade-1.8.0-1.9.0.php b/app/code/community/Lyra/Payzen/data/payzen_setup/data-upgrade-1.8.0-1.9.0.php new file mode 100644 index 00000000..493d9581 --- /dev/null +++ b/app/code/community/Lyra/Payzen/data/payzen_setup/data-upgrade-1.8.0-1.9.0.php @@ -0,0 +1,45 @@ +startSetup(); + +$connection = $installer->getConnection(); + +$statusTable = $installer->getTable('sales/order_status'); +$stateTable = $installer->getTable('sales/order_status_state'); + +$select = $connection->select()->from($statusTable, 'status')->where('status = "payzen_pending_transfer"'); +if (! $connection->fetchOne($select)) { // status does not exist + $connection->insert( + $statusTable, + array('status' => 'payzen_pending_transfer', 'label' => 'Pending funds transfer') + ); + + $connection->insert( + $stateTable, + array('status' => 'payzen_pending_transfer', 'state' => 'processing', 'is_default' => 0) + ); +} + +$installer->endSetup(); diff --git a/app/code/community/Lyra/Payzen/etc/config.xml b/app/code/community/Lyra/Payzen/etc/config.xml index 36c7c8b4..81d8d3ae 100644 --- a/app/code/community/Lyra/Payzen/etc/config.xml +++ b/app/code/community/Lyra/Payzen/etc/config.xml @@ -1,7 +1,7 @@1
- 2
@@ -174,11 +182,11 @@
3
- 4
- 1
- 2
PAYMENT
+ REGISTER_PAY
+ REGISTER
+