diff --git a/Makefile b/Makefile index 0196f91..402e32b 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ dependencies: package: validate_version mkdir -p ./var/ - cd ./extension && tar -cvf ../var/Affirm_Affirm-3.5.3.tgz * + cd ./extension && tar -cvf ../var/Affirm_Affirm-3.5.4.tgz * cd ./build && ./magento-tar-to-connect.phar affirm_tar_to_connect_config.php clean: diff --git a/build/affirm_tar_to_connect_config.php b/build/affirm_tar_to_connect_config.php index 2c5e85a..9aa8657 100644 --- a/build/affirm_tar_to_connect_config.php +++ b/build/affirm_tar_to_connect_config.php @@ -1,11 +1,11 @@ realpath('../var/'), -'archive_files' => 'Affirm_Affirm-3.5.3.tgz', +'archive_files' => 'Affirm_Affirm-3.5.4.tgz', 'extension_name' => 'Affirm_Magento', 'skip_version_compare' => true, -'extension_version' => '3.5.3', -'archive_connect' => 'Affirm_Affirm-3.5.3.tgz', +'extension_version' => '3.5.4', +'archive_connect' => 'Affirm_Affirm-3.5.4.tgz', 'path_output' => realpath('../var/'), 'stability' => 'stable', diff --git a/composer.json b/composer.json index 7ebbe4e..a95b8d2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "affirm/affirm-php", - "description": "Affirm PHP bindings", + "description": "Affirm payment integration for Magento 1", "type": "magento-module", "keywords": [ "affirm", diff --git a/extension/app/code/community/Affirm/Affirm/Block/Payment/Info.php b/extension/app/code/community/Affirm/Affirm/Block/Payment/Info.php index da4344d..7192908 100644 --- a/extension/app/code/community/Affirm/Affirm/Block/Payment/Info.php +++ b/extension/app/code/community/Affirm/Affirm/Block/Payment/Info.php @@ -28,6 +28,7 @@ class Affirm_Affirm_Block_Payment_Info extends Mage_Payment_Block_Info protected function _construct() { parent::_construct(); + $this->setData('area','frontend'); $this->setTemplate('affirm/affirm/payment/info/affirm.phtml'); } diff --git a/extension/app/code/community/Affirm/Affirm/Block/Promo/AsLowAs/Product.php b/extension/app/code/community/Affirm/Affirm/Block/Promo/AsLowAs/Product.php index 0c5f90c..8c0598e 100644 --- a/extension/app/code/community/Affirm/Affirm/Block/Promo/AsLowAs/Product.php +++ b/extension/app/code/community/Affirm/Affirm/Block/Promo/AsLowAs/Product.php @@ -34,7 +34,8 @@ protected function _toHtml() $mpp = $this->helper('affirm/promo_asLowAs')->getMinMPP(); if (!empty($mpp)) { - if ($this->getFinalPrice() < $mpp) { + $mpp_formatted = $this->helper('affirm/util')->formatCents($mpp); + if ($this->getFinalPrice() < $mpp_formatted) { return ""; } } diff --git a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer.php b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer.php index a8711cb..9af60c1 100644 --- a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer.php +++ b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer.php @@ -135,7 +135,12 @@ public function reactivateQuote($observer) $this->_isAffirmOrderSaveAfter = true; $quote = $observer->getQuote(); $methodInst = $quote->getPayment()->getMethodInstance(); - if (($methodInst->getCode() == Affirm_Affirm_Model_Payment::METHOD_CODE) && !$methodInst->redirectPreOrder()) { + if (!Mage::helper('affirm')->getAffirmTokenCode()) { + Mage::log('Confirm has no checkout token.'); + Mage::getSingleton('core/session')->addError('Payment has failed, please reload checkout page and try again. Checkout token is not available.'); + Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse(); + return; + } else if (($methodInst->getCode() == Affirm_Affirm_Model_Payment::METHOD_CODE) && !$methodInst->redirectPreOrder()) { $quote->setIsActive(true); $quote->save(); } diff --git a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/AfterSaveOrder.php b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/AfterSaveOrder.php index 2fffd9c..a84a94e 100644 --- a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/AfterSaveOrder.php +++ b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/AfterSaveOrder.php @@ -46,9 +46,10 @@ public function postDispatchSaveOrder($observer) $serializedRequest = $session->getAffirmOrderRequest(); $proxyRequest = unserialize($serializedRequest); $checkoutToken = Mage::registry('affirm_token_code'); + $lastOrderId = $session->getLastOrderId(); //Return, if order was placed before confirmation if (!($serializedRequest && $checkoutToken) || !Mage::helper('affirm')->isXhrRequest($proxyRequest) - || !$this->_isAffirmPaymentMethod($proxyRequest)) { + || !$this->_isAffirmPaymentMethod($proxyRequest) || !$lastOrderId) { return; } diff --git a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderEditSaveAdmin.php b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderEditSaveAdmin.php index 3a7ef33..d4fff7d 100644 --- a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderEditSaveAdmin.php +++ b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderEditSaveAdmin.php @@ -32,9 +32,11 @@ public function execute() $orderId = Mage::getSingleton('adminhtml/session_quote')->getOrderId(); $payment = Mage::getModel('sales/order')->load($orderId)->getPayment(); $oldPaymentMethod = $payment->getMethod(); + $telesalesEnabled = Mage::helper('core')->isModuleEnabled('Affirm_Telesales') ? true : false; if ($paymentData && isset($paymentData['method']) && $paymentData['method'] == Affirm_Affirm_Model_Payment::METHOD_CODE && - $paymentData['method'] != $oldPaymentMethod + $paymentData['method'] != $oldPaymentMethod && + !$telesalesEnabled ) { $request->initForward() ->setModuleName('admin') diff --git a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderSaveAdmin.php b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderSaveAdmin.php index 8b0160f..4b493dd 100644 --- a/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderSaveAdmin.php +++ b/extension/app/code/community/Affirm/Affirm/Model/Order/Observer/BeforeOrderSaveAdmin.php @@ -29,8 +29,10 @@ public function execute() { $request = Mage::app()->getRequest(); $paymentData = $request->getPost('payment'); + $telesalesEnabled = Mage::helper('core')->isModuleEnabled('Affirm_Telesales'); if ($paymentData && isset($paymentData['method']) && - $paymentData['method'] == Affirm_Affirm_Model_Payment::METHOD_CODE + $paymentData['method'] == Affirm_Affirm_Model_Payment::METHOD_CODE && + !$telesalesEnabled ) { $request->initForward() ->setModuleName('admin') diff --git a/extension/app/code/community/Affirm/Affirm/Model/Payment.php b/extension/app/code/community/Affirm/Affirm/Model/Payment.php index a6b8b1b..c6d05a2 100644 --- a/extension/app/code/community/Affirm/Affirm/Model/Payment.php +++ b/extension/app/code/community/Affirm/Affirm/Model/Payment.php @@ -75,6 +75,8 @@ class Affirm_Affirm_Model_Payment extends Mage_Payment_Model_Method_Abstract protected $_allowCurrencyCode = array('USD'); /**#@-*/ + protected $_affirmHelperClass = 'affirm'; + /** * Check method for processing with base currency * @@ -177,8 +179,9 @@ protected function _apiRequest($method, $path, $data = null, $storeId = null, $r $json = json_encode($data); $client->setRawData($json, 'application/json'); } - $client->setAuth(Mage::helper('affirm')->getApiKey($storeId), - Mage::helper('affirm')->getSecretKey($storeId), Zend_Http_Client::AUTH_BASIC + $helperClass = $this->_affirmHelperClass; + $client->setAuth(Mage::helper($helperClass)->getApiKey($storeId), + Mage::helper($helperClass)->getSecretKey($storeId), Zend_Http_Client::AUTH_BASIC ); $rawResult = $client->request($method)->getRawBody(); try { @@ -275,6 +278,10 @@ public function capture(Varien_Object $payment, $amount) $order = $payment->getOrder(); if($order) { $storeId = $order->getStoreId(); + if($payment->getAdditionalInformation('affirm_telesales')){ + $methodInst = $payment->getMethodInstance(); + $methodInst->setHelperClass('affirm_telesales'); + } } if (!$storeId) { $storeId = null; @@ -319,6 +326,10 @@ public function refund(Varien_Object $payment, $amount) $order = $payment->getOrder(); if($order) { $storeId = $order->getStoreId(); + if($payment->getAdditionalInformation('affirm_telesales')){ + $methodInst = $payment->getMethodInstance(); + $methodInst->setHelperClass('affirm_telesales'); + } } if (!$storeId) { $storeId = null; @@ -357,6 +368,10 @@ public function void(Varien_Object $payment) $order = $payment->getOrder(); if($order) { $storeId = $order->getStoreId(); + if($payment->getAdditionalInformation('affirm_telesales')){ + $methodInst = $payment->getMethodInstance(); + $methodInst->setHelperClass('affirm_telesales'); + } } if (!$storeId) { $storeId = null; @@ -451,6 +466,7 @@ public function processConfirmOrder($order, $checkoutToken) $payment = $order->getPayment(); $payment->setAdditionalInformation(self::CHECKOUT_TOKEN, $checkoutToken); + $payment->setAdditionalInformation('affirm_telesales', false); $action = $this->getConfigData('payment_action'); //authorize the total amount. @@ -906,4 +922,8 @@ public function isAvailableForQuote($quote = null) return true; } + + public function setHelperClass($class = 'affirm'){ + $this->_affirmHelperClass = $class; + } } diff --git a/extension/app/code/community/Affirm/Affirm/controllers/Adminhtml/RuleController.php b/extension/app/code/community/Affirm/Affirm/controllers/Adminhtml/RuleController.php index 51f8379..c1b090d 100644 --- a/extension/app/code/community/Affirm/Affirm/controllers/Adminhtml/RuleController.php +++ b/extension/app/code/community/Affirm/Affirm/controllers/Adminhtml/RuleController.php @@ -287,5 +287,15 @@ public function chooserAction() protected function _title($text = null, $resetIfExists = true) { return parent::_title($text, $resetIfExists); - } + } + + /** + * Acl check for admin + * + * @return bool + */ + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('system/config/affirm'); + } } \ No newline at end of file diff --git a/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php b/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php index 6e4be63..891bfd6 100644 --- a/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php +++ b/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php @@ -97,7 +97,7 @@ public function confirmAction() $checkoutToken = $this->getRequest()->getParam('checkout_token'); $checkoutSession = Mage::helper('affirm')->getCheckoutSession(); if (!$checkoutToken) { - $checkoutSession->addError($this->__('Confirm has no checkout token.')); + $checkoutSession->addError($this->__('Error encountered during checkout. Confirm has no checkout token.')); $this->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse(); return; } @@ -174,7 +174,7 @@ protected function _processConfWithoutSaveOrder($checkoutToken) { $checkoutSession = Mage::helper('affirm')->getCheckoutSession(); if (!$checkoutToken) { - $checkoutSession->addError($this->__('Confirm has no checkout token.')); + $checkoutSession->addError($this->__('Error encountered during checkout. Confirm has no checkout token.')); $this->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse(); return; } diff --git a/extension/app/code/community/Affirm/Affirm/etc/config.xml b/extension/app/code/community/Affirm/Affirm/etc/config.xml index e26f82d..3a7f3ca 100644 --- a/extension/app/code/community/Affirm/Affirm/etc/config.xml +++ b/extension/app/code/community/Affirm/Affirm/etc/config.xml @@ -2,7 +2,7 @@ - 3.5.3 + 3.5.4 diff --git a/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.0.0.9-3.0.0.10.php b/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.0.0.9-3.0.0.10.php index f58b198..81c30a8 100644 --- a/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.0.0.9-3.0.0.10.php +++ b/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.0.0.9-3.0.0.10.php @@ -19,36 +19,10 @@ /** @var Mage_Core_Model_Resource_Setup $this */ $installer = $this; $installer->startSetup(); -//Add attribute to customer -try { - $setup = Mage::getModel('eav/entity_setup', 'core_setup'); - $entity = 'customer'; - $attributeCode = 'affirm_customer_mfp'; - - if (!Mage::getSingleton('eav/config')->getAttribute($entity, $attributeCode)->getId()) { - $setup->addAttribute($entity, $attributeCode, array( - 'type' => 'varchar', - 'input' => 'text', - 'label' => 'Multiple Financing Program value', - 'global' => 1, - 'required' => 0, - 'user_defined' => 1, - 'default' => '', - 'visible_on_front' => 0, - 'position' => 999 - )); - $setup->updateAttribute($entity, $attributeCode, 'is_visible', '0'); - $attribute = Mage::getModel('eav/config')->getAttribute($entity, $attributeCode); - $attribute->setData('used_in_forms', array('adminhtml_customer')); - $attribute->save(); - } - -} catch (Exception $e) { - Mage::logException($e); -} //Add attribute to product try { + $setup = Mage::getModel('eav/entity_setup', 'core_setup'); $entity = 'catalog_product'; $attributeCode = 'affirm_product_mfp'; $attribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode($entity, $attributeCode); diff --git a/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.3.6-3.5.2.php b/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.3.6-3.5.2.php index 1619dba..fa00af0 100644 --- a/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.3.6-3.5.2.php +++ b/extension/app/code/community/Affirm/Affirm/sql/affirm_setup/mysql4-upgrade-3.3.6-3.5.2.php @@ -54,5 +54,4 @@ } $installer->endSetup(); -?> diff --git a/extension/app/design/adminhtml/default/default/template/affirm/affirm/errorOrderCreatePageOnAffirmPayment.phtml b/extension/app/design/adminhtml/default/default/template/affirm/affirm/errorOrderCreatePageOnAffirmPayment.phtml index 8871d77..660d45f 100644 --- a/extension/app/design/adminhtml/default/default/template/affirm/affirm/errorOrderCreatePageOnAffirmPayment.phtml +++ b/extension/app/design/adminhtml/default/default/template/affirm/affirm/errorOrderCreatePageOnAffirmPayment.phtml @@ -1,11 +1,6 @@ - -

- Affirm is not available as a payment method in Magento at this time. Instead you may use Affirm's Virtual Terminal to process payment. - -

+ For orders created using Magento Admin, Affirm is only available as a payment method via Telesales at this time. Please contact your Affirm representative for more information. + \ No newline at end of file diff --git a/extension/app/design/adminhtml/default/default/template/affirm/affirm/payment/form/affirm.phtml b/extension/app/design/adminhtml/default/default/template/affirm/affirm/payment/form/affirm.phtml new file mode 100644 index 0000000..3bfe7ac --- /dev/null +++ b/extension/app/design/adminhtml/default/default/template/affirm/affirm/payment/form/affirm.phtml @@ -0,0 +1,21 @@ + + + +helper('affirm')->getModuleConfigVersion(); ?> \ No newline at end of file diff --git a/extension/package.xml b/extension/package.xml index 53b1725..6de9d49 100644 --- a/extension/package.xml +++ b/extension/package.xml @@ -1,16 +1,16 @@ Affirm_Affirm - 3.5.3 + 3.5.4 stable BSD-3-Clause community Affirm functions as an alternative payment method and offers easy financing. Affirm functions as an alternative payment method and offers easy financing. - Payment restrictions via rules and admin notification and other bug fixes + Bug Fixes Affirmaffirmmts@affirm.com - 2018-03-20 + 2018-05-11 diff --git a/extension/skin/frontend/base/default/js/affirm/checkout.js b/extension/skin/frontend/base/default/js/affirm/checkout.js index c9e54f0..e3623d7 100644 --- a/extension/skin/frontend/base/default/js/affirm/checkout.js +++ b/extension/skin/frontend/base/default/js/affirm/checkout.js @@ -120,17 +120,29 @@ document.observe('dom:loaded', function () { window.addEventListener('load', function() { if ($('onestep_form')) { - if (typeof window.OneStep.Views.Init.prototype.updateOrder == 'function') { - window.OneStep.Views.Init.prototype.updateOrder = window.OneStep.Views.Init.prototype.updateOrder.wrap( - function (parentMethod) { - if (isAffirmMethod()) { - callMageWorldCheckoutForAffirm(); - } else { - return parentMethod(); + if(checkNested(window, 'OneStep', 'Views', 'Init', 'prototype')) { + if (typeof window.OneStep.Views.Init.prototype.updateOrder == 'function') { + window.OneStep.Views.Init.prototype.updateOrder = window.OneStep.Views.Init.prototype.updateOrder.wrap( + function (parentMethod) { + if (isAffirmMethod()) { + callMageWorldCheckoutForAffirm(); + } else { + return parentMethod(); + } + } + ) + } + } + } +}); - } - ) +function checkNested(obj /*, level1, level2, ... levelN*/) { + for (var i = 1; i < arguments.length; i++) { + if (!obj.hasOwnProperty(arguments[i])) { + return false; } + obj = obj[arguments[i]]; } -}); \ No newline at end of file + return true; +} \ No newline at end of file