Skip to content

Commit

Permalink
Dev v3.5.4 (#38)
Browse files Browse the repository at this point in the history
* Fix for template area scope to make it frontend data

* Additional error handling added

* Bug fix: MPP min amount was not reflecting for PDP page

* Bug fix - obsolete sql attribute removed

* Version 3.5.4 update and Bug fix for ACL

* Check for Telesales extension for admin order

* composer description updated

* copy updated
  • Loading branch information
nandadubey authored May 24, 2018
1 parent f3d220f commit 1b69770
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions build/affirm_tar_to_connect_config.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
return array(
'base_dir' => 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',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "affirm/affirm-php",
"description": "Affirm PHP bindings",
"description": "Affirm payment integration for Magento 1",
"type": "magento-module",
"keywords": [
"affirm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
24 changes: 22 additions & 2 deletions extension/app/code/community/Affirm/Affirm/Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -906,4 +922,8 @@ public function isAvailableForQuote($quote = null)

return true;
}

public function setHelperClass($class = 'affirm'){
$this->_affirmHelperClass = $class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion extension/app/code/community/Affirm/Affirm/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Affirm_Affirm>
<version>3.5.3</version>
<version>3.5.4</version>
</Affirm_Affirm>
</modules>
<global>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@
}

$installer->endSetup();
?>

Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?php
/** @var Mage_Core_Block_Template $this **/
?>
<?php
$url = 'http://help.merchants.affirm.com/article/67-virtual-terminal-overview';
?>

<h3>
Affirm is not available as a payment method in Magento at this time. Instead you may use Affirm's Virtual Terminal to process payment.
<a href="<?php echo $url; ?>"><?php echo $url; ?></a>
</h3>
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.
</h3>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/** @var Affirm_Affirm_Block_Payment_Form $this **/
?>
<style type="text/css">
.affirm-module-version {
display: none;
}

.affirm_payment_info {
color: #6f6f6f;
font-size: 14px;
}
</style>
<ul class="form-list affirm" id="payment_form_affirm" style="display:none;">
<li class="form-alt">
<div class="affirm_payment_info">
<p><?php echo $this->__('If you have Affirm Telesales enabled, User will be sent Affirm checkout link to securely complete the purchase and will be redirected back to your site after confirmation or cancellation.'); ?></p>
</div>
</li>
</ul>
<span class="affirm-module-version"><?php echo $this->helper('affirm')->getModuleConfigVersion(); ?></span>
Loading

0 comments on commit 1b69770

Please sign in to comment.