Skip to content

Commit

Permalink
Adding unique id to authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg, Dake committed Apr 14, 2014
1 parent 0b9ab54 commit 2f6583a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ php.ini.sample
/app/Mage.php
/app/.htaccess
/app/code/core/*
/app/code/community/Phoenix/*
/app/design/install
/app/design/adminhtml/default/default/layout/admin.xml
/app/design/adminhtml/default/default/layout/adminnotification.xml
Expand Down
12 changes: 6 additions & 6 deletions app/code/local/Litle/CreditCard/Model/PaymentLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ public function getTokenInfo($payment)
return $retArray;
}

public function creditCardOrPaypageOrToken($payment)
public function creditCardOrPaypageOrToken($payment, $info)
{
$info = $this->getInfoInstance();
$vaultIndex = $info->getAdditionalInformation('cc_vaulted');
$payment_hash = array();
if ($vaultIndex > 0) {
Expand Down Expand Up @@ -686,7 +685,7 @@ public function authorize(Varien_Object $payment, $amount)
$info->setAdditionalInformation('orderSource', 'ecommerce');
}

$hash_in = generateAuthorizationHash();
$hash_in = $this->generateAuthorizationHash($orderId, $amountToPass, $info, $payment);

$litleRequest = new LitleOnlineRequest();
$litleResponse = $litleRequest->authorizationRequest($hash_in);
Expand All @@ -705,6 +704,7 @@ public function authorize(Varien_Object $payment, $amount)
function generateAuthorizationHash($orderId, $amountToPass, $info, $payment) {
$hash = array(
'orderId' => $orderId,
'id' => $orderId,
'amount' => $amountToPass,
'orderSource' => $info->getAdditionalInformation('orderSource'),
'billToAddress' => $this->getBillToAddress($payment),
Expand All @@ -715,8 +715,8 @@ function generateAuthorizationHash($orderId, $amountToPass, $info, $payment) {
Mage::app()->getStore()
->getBaseUrl())
);

$payment_hash = $this->creditCardOrPaypageOrToken($payment);
$payment_hash = $this->creditCardOrPaypageOrToken($payment, $info);
$hash_temp = array_merge($hash, $payment_hash);
$merchantData = $this->merchantData($payment);
$hash_in = array_merge($hash_temp, $merchantData);
Expand Down Expand Up @@ -770,7 +770,7 @@ public function capture(Varien_Object $payment, $amount)
'shipToAddress' => $this->getAddressInfo($payment),
'enhancedData' => $this->getEnhancedData($payment)
);
$payment_hash = $this->creditCardOrPaypageOrToken($payment);
$payment_hash = $this->creditCardOrPaypageOrToken($payment, $info);
$hash = array_merge($hash_temp, $payment_hash);
}
$merchantData = $this->merchantData($payment);
Expand Down
48 changes: 48 additions & 0 deletions test/unit/PaymentLogicTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* Copyright (c) 2011 Litle & Co.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
require_once(getenv('MAGENTO_HOME')."/app/Mage.php");
require_once(getenv('MAGENTO_HOME')."/app/code/core/Mage/Core/Block/Abstract.php");
require_once(getenv('MAGENTO_HOME')."/app/code/core/Mage/Core/Block/Template.php");
require_once(getenv('MAGENTO_HOME')."/app/code/core/Mage/Adminhtml/Block/Template.php");
require_once(getenv('MAGENTO_HOME')."/app/code/core/Mage/Adminhtml/Block/Widget/Container.php");
require_once(getenv('MAGENTO_HOME')."/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php");
require_once(getenv('MAGENTO_HOME')."/app/code/local/Litle/CreditCard/Model/PaymentLogic.php");

class PaymentLogicTest extends PHPUnit_Framework_TestCase
{
public function testGenerateUniqueId()
{
Mage::init();
$payment = new Varien_Object();
$order = new Varien_Object();
$billingAddress = new Varien_Object();
$order->setBillingAddress($billingAddress);
$payment->setOrder($order);
$litle = new Litle_CreditCard_Model_PaymentLogic();
$mock = $this->getMock('Mage_Payment_Model_Info');
$hash = $litle->generateAuthorizationHash('123','100', $mock, $payment);
$this->assertEquals('123', $hash['id']);
}
}

0 comments on commit 2f6583a

Please sign in to comment.