Version Notes
Add option for merchant to include Yellow transaction fees in amount invoiced to customer.
Download this release
Release Info
| Developer | Tawfek Daghistani |
| Extension | Yellow_Pay |
| Version | 1.0.3 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.2 to 1.0.3
- app/code/local/Yellow/Bitcoin/Block/Adminhtml/Sales/Order/Total/Fee.php +10 -0
- app/code/local/Yellow/Bitcoin/Block/Sales/Order/Fee.php +94 -0
- app/code/local/Yellow/Bitcoin/Model/Bitcoin.php +63 -2
- app/code/local/Yellow/Bitcoin/Model/Observer.php +67 -0
- app/code/local/Yellow/Bitcoin/Model/Sales/Order/Total/Creditmemo/Fee.php +42 -0
- app/code/local/Yellow/Bitcoin/Model/Sales/Order/Total/Invoice/Fee.php +49 -0
- app/code/local/Yellow/Bitcoin/Model/Sales/Quote/Address/Total/Fee.php +83 -0
- app/code/local/Yellow/Bitcoin/etc/config.xml +83 -1
- app/code/local/Yellow/Bitcoin/etc/system.xml +11 -1
- app/code/local/Yellow/Bitcoin/sql/bitcoin_setup/mysql4-upgrade-0.1.3-1.0.2.php +1 -0
- app/code/local/Yellow/Bitcoin/sql/bitcoin_setup/mysql4-upgrade-1.0.2-1.0.3.php +46 -0
- app/design/adminhtml/default/default/layout/bitcoin.xml +53 -0
- app/design/adminhtml/default/default/template/bitcoin/sales/order/refunded.phtml +16 -0
- app/design/adminhtml/default/default/template/bitcoin/sales/order/total.phtml +9 -0
- app/design/frontend/base/default/layout/bitcoin.xml +47 -0
- app/design/frontend/base/default/template/bitcoin/checkout/total/fee.phtml +15 -0
- app/etc/modules/Yellow_Bitcoin.xml +1 -1
- package.xml +5 -6
app/code/local/Yellow/Bitcoin/Block/Adminhtml/Sales/Order/Total/Fee.php
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Yellow_Bitcoin_Block_Adminhtml_Sales_Order_Total_Fee extends Mage_Adminhtml_Block_Sales_Order_Create_Totals_Default
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Use your own template if necessary
|
| 7 |
+
* See "sales/order/create/totals/default.phtml" for model
|
| 8 |
+
*/
|
| 9 |
+
//protected $_template = 'bitcoin/sales/order/total/fee.phtml';
|
| 10 |
+
}
|
app/code/local/Yellow/Bitcoin/Block/Sales/Order/Fee.php
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
* The MIT License (MIT)
|
| 5 |
+
*
|
| 6 |
+
* Copyright (c) 2014 YellowPay.co
|
| 7 |
+
*
|
| 8 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 9 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 10 |
+
* in the Software without restriction, including without limitation the rights
|
| 11 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 12 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 13 |
+
* furnished to do so, subject to the following conditions:
|
| 14 |
+
*
|
| 15 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 16 |
+
* copies or substantial portions of the Software.
|
| 17 |
+
*
|
| 18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 19 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 20 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 21 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 22 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 23 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 24 |
+
* SOFTWARE.
|
| 25 |
+
*
|
| 26 |
+
* */
|
| 27 |
+
class Yellow_Bitcoin_Block_Sales_Order_Fee extends Mage_Core_Block_Template
|
| 28 |
+
{
|
| 29 |
+
|
| 30 |
+
protected $_template = 'bitcoin/checkout/total/fee.phtml';
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Get label cell tag properties
|
| 34 |
+
*
|
| 35 |
+
* @return string
|
| 36 |
+
*/
|
| 37 |
+
public function getLabelProperties()
|
| 38 |
+
{
|
| 39 |
+
return $this->getParentBlock()->getLabelProperties();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Get order store object
|
| 44 |
+
*
|
| 45 |
+
* @return Mage_Sales_Model_Order
|
| 46 |
+
*/
|
| 47 |
+
public function getOrder()
|
| 48 |
+
{
|
| 49 |
+
return $this->getParentBlock()->getOrder();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Get totals source object
|
| 54 |
+
*
|
| 55 |
+
* @return Mage_Sales_Model_Order
|
| 56 |
+
*/
|
| 57 |
+
public function getSource()
|
| 58 |
+
{
|
| 59 |
+
return $this->getParentBlock()->getSource();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Get value cell tag properties
|
| 64 |
+
*
|
| 65 |
+
* @return string
|
| 66 |
+
*/
|
| 67 |
+
public function getValueProperties()
|
| 68 |
+
{
|
| 69 |
+
return $this->getParentBlock()->getValueProperties();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
*
|
| 74 |
+
* @return Yellow_Bitcoin_Block_Sales_Order_Total
|
| 75 |
+
*/
|
| 76 |
+
public function initTotals()
|
| 77 |
+
{
|
| 78 |
+
if ((float) $this->getOrder()->getYellowFee()) {
|
| 79 |
+
$source = $this->getSource();
|
| 80 |
+
$value = $source->getYellowFee();
|
| 81 |
+
$label = "Transaction Fee" ;
|
| 82 |
+
|
| 83 |
+
$this->getParentBlock()->addTotal(new Varien_Object(array(
|
| 84 |
+
'code' => 'yellow_fee',
|
| 85 |
+
'strong' => false,
|
| 86 |
+
'label' => Mage::helper('bitcoin')->__($label),
|
| 87 |
+
'value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? - $value : $value
|
| 88 |
+
)));
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return $this;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
}
|
app/code/local/Yellow/Bitcoin/Model/Bitcoin.php
CHANGED
|
@@ -88,6 +88,14 @@ Class Yellow_Bitcoin_Model_Bitcoin extends Mage_Payment_Model_Method_Abstract
|
|
| 88 |
*/
|
| 89 |
private $api_uri_check_payment = "invoice/[id]/";
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
/**
|
| 92 |
* @type Mage_Sales_Model_Order
|
| 93 |
**/
|
|
@@ -360,8 +368,8 @@ Class Yellow_Bitcoin_Model_Bitcoin extends Mage_Payment_Model_Method_Abstract
|
|
| 360 |
$http_client = $this->getHTTPClient();
|
| 361 |
$yellow_payment_data = array(
|
| 362 |
"base_price" => $base_price, /// Set to 0.30 for testing
|
| 363 |
-
"base_ccy"
|
| 364 |
-
"callback"
|
| 365 |
);
|
| 366 |
$post_body = json_encode($yellow_payment_data);
|
| 367 |
$nonce = round(microtime(true) * 1000);
|
|
@@ -704,4 +712,57 @@ Class Yellow_Bitcoin_Model_Bitcoin extends Mage_Payment_Model_Method_Abstract
|
|
| 704 |
return $this->server_root;
|
| 705 |
}
|
| 706 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
}
|
| 88 |
*/
|
| 89 |
private $api_uri_check_payment = "invoice/[id]/";
|
| 90 |
|
| 91 |
+
/**
|
| 92 |
+
* check profile data
|
| 93 |
+
*
|
| 94 |
+
* @var String
|
| 95 |
+
*/
|
| 96 |
+
private $api_profile = "profile/";
|
| 97 |
+
|
| 98 |
+
|
| 99 |
/**
|
| 100 |
* @type Mage_Sales_Model_Order
|
| 101 |
**/
|
| 368 |
$http_client = $this->getHTTPClient();
|
| 369 |
$yellow_payment_data = array(
|
| 370 |
"base_price" => $base_price, /// Set to 0.30 for testing
|
| 371 |
+
"base_ccy" => $base_ccy, /// Set to "USD" for testing
|
| 372 |
+
"callback" => $ipnUrl
|
| 373 |
);
|
| 374 |
$post_body = json_encode($yellow_payment_data);
|
| 375 |
$nonce = round(microtime(true) * 1000);
|
| 712 |
return $this->server_root;
|
| 713 |
}
|
| 714 |
|
| 715 |
+
/**
|
| 716 |
+
* @param Mage_Sales_Model_Quote_Address $address
|
| 717 |
+
* @return bool
|
| 718 |
+
*/
|
| 719 |
+
public function canApplyFee(Mage_Sales_Model_Quote_Address $address)
|
| 720 |
+
{
|
| 721 |
+
$isEnabled = (bool) $this->getConfiguration("transaction_fee");
|
| 722 |
+
if(!$isEnabled)
|
| 723 |
+
{
|
| 724 |
+
return false;
|
| 725 |
+
}
|
| 726 |
+
//// check if the user select yellow as his selected payment method
|
| 727 |
+
if($address->getQuote()->getPayment()->getMethod() !== self::getCode())
|
| 728 |
+
{
|
| 729 |
+
return false;
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
return true;
|
| 733 |
+
}
|
| 734 |
+
|
| 735 |
+
/**
|
| 736 |
+
*
|
| 737 |
+
* @return float
|
| 738 |
+
* @throws Mage_Core_Exception
|
| 739 |
+
* @throws Zend_Http_Client_Exception
|
| 740 |
+
*/
|
| 741 |
+
public function getYellowFee()
|
| 742 |
+
{
|
| 743 |
+
$url = $this->server_root . $this->api_profile;
|
| 744 |
+
$nonce = round(microtime(true) * 1000);
|
| 745 |
+
$message = $nonce . $url;
|
| 746 |
+
$private_key = Mage::helper('core')->decrypt($this->getConfiguration("private_key"));
|
| 747 |
+
$hash = hash_hmac("sha256", $message, $private_key, false);
|
| 748 |
+
$http_client = $this->getHTTPClient();
|
| 749 |
+
$http_client->setHeaders($this->getHeaders($nonce, $hash));
|
| 750 |
+
$http_client->setMethod("GET")->setUri($url);
|
| 751 |
+
try {
|
| 752 |
+
$body = $http_client->request()->getBody();
|
| 753 |
+
$data = json_decode($body, true);
|
| 754 |
+
if(!isset($data["fee"])){
|
| 755 |
+
throw new \Exception("expected fee amount and got : " . json_encode($data) , "500");
|
| 756 |
+
}
|
| 757 |
+
return (float) $data["fee"];
|
| 758 |
+
} catch (\Exception $e) {
|
| 759 |
+
$this->log($e->getMessage());
|
| 760 |
+
$this->log("EXCEPTION:" . json_encode($e));
|
| 761 |
+
Mage::throwException(
|
| 762 |
+
Mage::helper('bitcoin')->__(
|
| 763 |
+
"We're sorry, an error has occurred while completing your `/profile` request. Please refresh the page to try again. If the error persists, please send us an email at support@yellowpay.co"
|
| 764 |
+
)
|
| 765 |
+
);
|
| 766 |
+
}
|
| 767 |
+
}
|
| 768 |
}
|
app/code/local/Yellow/Bitcoin/Model/Observer.php
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
* The MIT License (MIT)
|
| 5 |
+
*
|
| 6 |
+
* Copyright (c) 2014 YellowPay.co
|
| 7 |
+
*
|
| 8 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 9 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 10 |
+
* in the Software without restriction, including without limitation the rights
|
| 11 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 12 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 13 |
+
* furnished to do so, subject to the following conditions:
|
| 14 |
+
*
|
| 15 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 16 |
+
* copies or substantial portions of the Software.
|
| 17 |
+
*
|
| 18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 19 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 20 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 21 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 22 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 23 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 24 |
+
* SOFTWARE.
|
| 25 |
+
*
|
| 26 |
+
* */
|
| 27 |
+
class Yellow_Bitcoin_Model_Observer
|
| 28 |
+
{
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Set fee amount invoiced to the order
|
| 32 |
+
*
|
| 33 |
+
* @param Varien_Event_Observer $observer
|
| 34 |
+
* @return Yellow_Bitcoin_Model_Observer
|
| 35 |
+
*/
|
| 36 |
+
public function invoiceSaveAfter(Varien_Event_Observer $observer)
|
| 37 |
+
{
|
| 38 |
+
$invoice = $observer->getEvent()->getInvoice();
|
| 39 |
+
|
| 40 |
+
if ($invoice->getBaseYellowFeeAmount()) {
|
| 41 |
+
$order = $invoice->getOrder();
|
| 42 |
+
$order->setYellowFeeAmountInvoiced($order->getYellowFeeAmountInvoiced() + $invoice->getYellowFeeAmount());
|
| 43 |
+
$order->setBaseYellowFeeAmountInvoiced($order->getBaseYellowFeeAmountInvoiced() + $invoice->getBaseYellowFeeAmount());
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return $this;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Set fee amount refunded to the order
|
| 51 |
+
*
|
| 52 |
+
* @param Varien_Event_Observer $observer
|
| 53 |
+
* @return Yellow_Bitcoin_Model_Observer
|
| 54 |
+
*/
|
| 55 |
+
public function creditmemoSaveAfter(Varien_Event_Observer $observer)
|
| 56 |
+
{
|
| 57 |
+
$creditmemo = $observer->getEvent()->getCreditmemo();
|
| 58 |
+
|
| 59 |
+
if ($creditmemo->getYellowFeeAmount()) {
|
| 60 |
+
$order = $creditmemo->getOrder();
|
| 61 |
+
$order->setYellowFeeAmountRefunded($order->getYellowFeeAmountRefunded() + $creditmemo->getYellowFeeAmount());
|
| 62 |
+
$order->setBaseYellowFeeAmountRefunded($order->getBaseYellowFeeAmountRefunded() + $creditmemo->getBaseYellowFeeAmount());
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
return $this;
|
| 66 |
+
}
|
| 67 |
+
}
|
app/code/local/Yellow/Bitcoin/Model/Sales/Order/Total/Creditmemo/Fee.php
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
* The MIT License (MIT)
|
| 5 |
+
*
|
| 6 |
+
* Copyright (c) 2014 YellowPay.co
|
| 7 |
+
*
|
| 8 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 9 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 10 |
+
* in the Software without restriction, including without limitation the rights
|
| 11 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 12 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 13 |
+
* furnished to do so, subject to the following conditions:
|
| 14 |
+
*
|
| 15 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 16 |
+
* copies or substantial portions of the Software.
|
| 17 |
+
*
|
| 18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 19 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 20 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 21 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 22 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 23 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 24 |
+
* SOFTWARE.
|
| 25 |
+
*
|
| 26 |
+
* */
|
| 27 |
+
class Yellow_Bitcoin_Model_Sales_Order_Total_Creditmemo_Fee extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
|
| 28 |
+
{
|
| 29 |
+
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
|
| 30 |
+
{
|
| 31 |
+
$order = $creditmemo->getOrder();
|
| 32 |
+
$yellowFeeLeft = $order->getYellowFeeInvoiced() - $order->getYellowFeeRefunded();
|
| 33 |
+
$baseYellowFeeLeft = $order->getBaseYellowFeeInvoiced() - $order->getYellowBaseFeeRefunded();
|
| 34 |
+
if ($baseYellowFeeLeft > 0) {
|
| 35 |
+
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $yellowFeeLeft);
|
| 36 |
+
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseYellowFeeLeft);
|
| 37 |
+
$creditmemo->setYellowFee($yellowFeeLeft);
|
| 38 |
+
$creditmemo->setBaseYellowFee($baseYellowFeeLeft);
|
| 39 |
+
}
|
| 40 |
+
return $this;
|
| 41 |
+
}
|
| 42 |
+
}
|
app/code/local/Yellow/Bitcoin/Model/Sales/Order/Total/Invoice/Fee.php
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
* The MIT License (MIT)
|
| 5 |
+
*
|
| 6 |
+
* Copyright (c) 2014 YellowPay.co
|
| 7 |
+
*
|
| 8 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 9 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 10 |
+
* in the Software without restriction, including without limitation the rights
|
| 11 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 12 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 13 |
+
* furnished to do so, subject to the following conditions:
|
| 14 |
+
*
|
| 15 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 16 |
+
* copies or substantial portions of the Software.
|
| 17 |
+
*
|
| 18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 19 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 20 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 21 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 22 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 23 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 24 |
+
* SOFTWARE.
|
| 25 |
+
*
|
| 26 |
+
* */
|
| 27 |
+
class Yellow_Bitcoin_Model_Sales_Order_Total_Invoice_Fee extends Mage_Sales_Model_Order_Invoice_Total_Abstract
|
| 28 |
+
{
|
| 29 |
+
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
|
| 30 |
+
{
|
| 31 |
+
$order = $invoice->getOrder();
|
| 32 |
+
$yellowFeeLeft = $order->getYellowFee() - $order->getYellowFeeInvoiced();
|
| 33 |
+
$baseYellowFeeLeft = $order->getBaseYellowFee() - $order->getBaseYellowFeeInvoiced();
|
| 34 |
+
if (abs($baseYellowFeeLeft) < $invoice->getBaseGrandTotal()) {
|
| 35 |
+
$invoice->setGrandTotal($invoice->getGrandTotal() + $yellowFeeLeft);
|
| 36 |
+
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseYellowFeeLeft);
|
| 37 |
+
} else {
|
| 38 |
+
$yellowFeeLeft = $invoice->getGrandTotal() * -1;
|
| 39 |
+
$baseYellowFeeLeft = $invoice->getBaseGrandTotal() * -1;
|
| 40 |
+
|
| 41 |
+
$invoice->setGrandTotal(0);
|
| 42 |
+
$invoice->setBaseGrandTotal(0);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
$invoice->setYellowFee($yellowFeeLeft);
|
| 46 |
+
$invoice->setBaseYellowFee($baseYellowFeeLeft);
|
| 47 |
+
return $this;
|
| 48 |
+
}
|
| 49 |
+
}
|
app/code/local/Yellow/Bitcoin/Model/Sales/Quote/Address/Total/Fee.php
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
* The MIT License (MIT)
|
| 5 |
+
*
|
| 6 |
+
* Copyright (c) 2014 YellowPay.co
|
| 7 |
+
*
|
| 8 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 9 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 10 |
+
* in the Software without restriction, including without limitation the rights
|
| 11 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 12 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 13 |
+
* furnished to do so, subject to the following conditions:
|
| 14 |
+
*
|
| 15 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 16 |
+
* copies or substantial portions of the Software.
|
| 17 |
+
*
|
| 18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 19 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 20 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 21 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 22 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 23 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 24 |
+
* SOFTWARE.
|
| 25 |
+
*
|
| 26 |
+
* */
|
| 27 |
+
class Yellow_Bitcoin_Model_Sales_Quote_Address_Total_Fee extends Mage_Sales_Model_Quote_Address_Total_Abstract{
|
| 28 |
+
|
| 29 |
+
protected $_code = 'yellow_fee';
|
| 30 |
+
|
| 31 |
+
public function collect(Mage_Sales_Model_Quote_Address $address)
|
| 32 |
+
{
|
| 33 |
+
|
| 34 |
+
parent::collect($address);
|
| 35 |
+
|
| 36 |
+
/// reset values
|
| 37 |
+
$this->_setAmount(0);
|
| 38 |
+
$this->_setBaseAmount(0);
|
| 39 |
+
|
| 40 |
+
$address->setYellowFee(0);
|
| 41 |
+
$address->setBaseYellowFee(0);
|
| 42 |
+
|
| 43 |
+
$quote = $address->getQuote();
|
| 44 |
+
$quote->setYellowFee(0);
|
| 45 |
+
$quote->setBaseYellowFee(0);
|
| 46 |
+
|
| 47 |
+
$items = $this->_getAddressItems($address);
|
| 48 |
+
if (!count($items)) {
|
| 49 |
+
return $this; //this makes only address type shipping to come through
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
$model = Mage::getModel("bitcoin/bitcoin");
|
| 54 |
+
if($model->canApplyFee($address)){
|
| 55 |
+
$fee = $model->getYellowFee();
|
| 56 |
+
$totals = array_sum($address->getAllTotalAmounts());
|
| 57 |
+
//$baseTotals = array_sum($address->getAllBaseTotalAmounts());
|
| 58 |
+
$fee = round(($totals * $fee) / (1 - $fee) , 2, PHP_ROUND_HALF_UP );
|
| 59 |
+
if( $fee > 0 ){
|
| 60 |
+
$baseFee = $address->getQuote()->getStore()->convertPrice($fee, false);
|
| 61 |
+
$address->setYellowFee($fee);
|
| 62 |
+
$address->setBaseYellowFee($baseFee);
|
| 63 |
+
$quote->setYellowFee($fee);
|
| 64 |
+
$quote->setBaseYellowFee($baseFee);
|
| 65 |
+
$address->setGrandTotal($address->getGrandTotal() + $address->getYellowFee());
|
| 66 |
+
$address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseYellowFee());
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
}
|
| 70 |
+
return $this;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
public function fetch(Mage_Sales_Model_Quote_Address $address)
|
| 74 |
+
{
|
| 75 |
+
$fee = $address->getYellowFee();
|
| 76 |
+
$address->addTotal(array(
|
| 77 |
+
'code'=>$this->getCode(),
|
| 78 |
+
'title'=>Mage::helper('bitcoin')->__('Transaction Fee'),
|
| 79 |
+
'value'=> $fee
|
| 80 |
+
));
|
| 81 |
+
return $this;
|
| 82 |
+
}
|
| 83 |
+
}
|
app/code/local/Yellow/Bitcoin/etc/config.xml
CHANGED
|
@@ -27,13 +27,94 @@ SOFTWARE.
|
|
| 27 |
<config>
|
| 28 |
<modules>
|
| 29 |
<Yellow_Bitcoin>
|
| 30 |
-
<version>1.0.
|
| 31 |
<depends>
|
| 32 |
<Mage_Payment/>
|
| 33 |
</depends>
|
| 34 |
</Yellow_Bitcoin>
|
| 35 |
</modules>
|
| 36 |
<global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
<helpers>
|
| 38 |
<bitcoin>
|
| 39 |
<class>Yellow_Bitcoin_Helper</class>
|
|
@@ -183,6 +264,7 @@ SOFTWARE.
|
|
| 183 |
<private_key></private_key>
|
| 184 |
<payment_action>authorize</payment_action>
|
| 185 |
<db_log>0</db_log>
|
|
|
|
| 186 |
</bitcoin>
|
| 187 |
</payment>
|
| 188 |
</default>
|
| 27 |
<config>
|
| 28 |
<modules>
|
| 29 |
<Yellow_Bitcoin>
|
| 30 |
+
<version>1.0.3</version>
|
| 31 |
<depends>
|
| 32 |
<Mage_Payment/>
|
| 33 |
</depends>
|
| 34 |
</Yellow_Bitcoin>
|
| 35 |
</modules>
|
| 36 |
<global>
|
| 37 |
+
<sales>
|
| 38 |
+
<quote>
|
| 39 |
+
<totals>
|
| 40 |
+
<yellow_fee>
|
| 41 |
+
<class>bitcoin/sales_quote_address_total_fee</class>
|
| 42 |
+
<renderer>bitcoin/sales_order_fee</renderer>
|
| 43 |
+
<admin_renderer>fee/adminhtml_sales_order_total_fee</admin_renderer>
|
| 44 |
+
<after>subtotal,discount,tax</after>
|
| 45 |
+
<before>grand_total</before>
|
| 46 |
+
</yellow_fee>
|
| 47 |
+
</totals>
|
| 48 |
+
</quote>
|
| 49 |
+
<order_invoice>
|
| 50 |
+
<totals>
|
| 51 |
+
<yellow_fee>
|
| 52 |
+
<class>bitcoin/sales_order_total_invoice_fee</class>
|
| 53 |
+
<renderer>bitcoin/sales_order_fee</renderer>
|
| 54 |
+
<after>subtotal,discount,tax</after>
|
| 55 |
+
<before>grand_total</before>
|
| 56 |
+
</yellow_fee>
|
| 57 |
+
</totals>
|
| 58 |
+
</order_invoice>
|
| 59 |
+
<order_creditmemo>
|
| 60 |
+
<totals>
|
| 61 |
+
<yellow_fee>
|
| 62 |
+
<class>bitcoin/sales_order_total_creditmemo_fee</class>
|
| 63 |
+
<renderer>bitcoin/sales_order_fee</renderer>
|
| 64 |
+
<after>subtotal,discount,tax</after>
|
| 65 |
+
<before>grand_total</before>
|
| 66 |
+
</yellow_fee>
|
| 67 |
+
</totals>
|
| 68 |
+
</order_creditmemo>
|
| 69 |
+
</sales>
|
| 70 |
+
<events>
|
| 71 |
+
<sales_order_invoice_save_after>
|
| 72 |
+
<observers>
|
| 73 |
+
<sales_order_invoice_save_after>
|
| 74 |
+
<class>bitcoin/observer</class>
|
| 75 |
+
<method>invoiceSaveAfter</method>
|
| 76 |
+
</sales_order_invoice_save_after>
|
| 77 |
+
</observers>
|
| 78 |
+
</sales_order_invoice_save_after>
|
| 79 |
+
<sales_order_creditmemo_save_after>
|
| 80 |
+
<observers>
|
| 81 |
+
<sales_order_creditmemo_save_after>
|
| 82 |
+
<class>bitcoin/observer</class>
|
| 83 |
+
<method>creditmemoSaveAfter</method>
|
| 84 |
+
</sales_order_creditmemo_save_after>
|
| 85 |
+
</observers>
|
| 86 |
+
</sales_order_creditmemo_save_after>
|
| 87 |
+
</events>
|
| 88 |
+
<fieldsets>
|
| 89 |
+
<sales_convert_quote_address>
|
| 90 |
+
<yellow_fee>
|
| 91 |
+
<to_order>*</to_order>
|
| 92 |
+
</yellow_fee>
|
| 93 |
+
<base_yellow_fee>
|
| 94 |
+
<to_order>*</to_order>
|
| 95 |
+
</base_yellow_fee>
|
| 96 |
+
</sales_convert_quote_address>
|
| 97 |
+
<sales_convert_quote_item>
|
| 98 |
+
<yellow_fee>
|
| 99 |
+
<to_order>*</to_order>
|
| 100 |
+
</yellow_fee>
|
| 101 |
+
<base_yellow_fee>
|
| 102 |
+
<to_order>*</to_order>
|
| 103 |
+
</base_yellow_fee>
|
| 104 |
+
</sales_convert_quote_item>
|
| 105 |
+
</fieldsets>
|
| 106 |
+
<pdf>
|
| 107 |
+
<totals>
|
| 108 |
+
<yellow_fee translate="title">
|
| 109 |
+
<title>Transaction Fee</title>
|
| 110 |
+
<source_field>yellow_fee</source_field>
|
| 111 |
+
<font_size>7</font_size>
|
| 112 |
+
<display_zero>0</display_zero>
|
| 113 |
+
<sort_order>650</sort_order>
|
| 114 |
+
<amount_prefix></amount_prefix>
|
| 115 |
+
</yellow_fee>
|
| 116 |
+
</totals>
|
| 117 |
+
</pdf>
|
| 118 |
<helpers>
|
| 119 |
<bitcoin>
|
| 120 |
<class>Yellow_Bitcoin_Helper</class>
|
| 264 |
<private_key></private_key>
|
| 265 |
<payment_action>authorize</payment_action>
|
| 266 |
<db_log>0</db_log>
|
| 267 |
+
<transaction_fee>0</transaction_fee>
|
| 268 |
</bitcoin>
|
| 269 |
</payment>
|
| 270 |
</default>
|
app/code/local/Yellow/Bitcoin/etc/system.xml
CHANGED
|
@@ -33,7 +33,7 @@ SOFTWARE.
|
|
| 33 |
<label>Yellow Bitcoin</label>
|
| 34 |
<comment>
|
| 35 |
<