Itfosters_Pallcurrencys - Version 0.1.1

Version Notes

All the currency is not supported by the paypal then use the unsported currency in this exenstion

Download this release

Release Info

Developer Raj kumar
Extension Itfosters_Pallcurrencys
Version 0.1.1
Comparing to
See all releases


Code changes from version 0.1.0 to 0.1.1

app/code/local/Itfosters/Pallcurrencys/.DS_Store ADDED
Binary file
app/code/local/Itfosters/Pallcurrencys/Block/Checkout/Cart/Totals.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Block_Checkout_Cart_Totals extends Mage_Checkout_Block_Cart_Totals
4
+ {
5
+ public function needDisplayBaseGrandtotal()
6
+ {
7
+ $quote = $this->getQuote();
8
+ if ($quote->getPayment()->getMethodInstance()->getCode() == 'paypal_standard') {
9
+ if (Mage::helper('pallcurrencys')->shouldConvert() && ($quote->getQuoteCurrencyCode() != Mage::helper('pallcurrencys')->getToCurrency())) {
10
+ return true;
11
+ } else {
12
+ return false;
13
+ }
14
+ }
15
+ if ($quote->getBaseCurrencyCode() != $quote->getQuoteCurrencyCode()) {
16
+ return true;
17
+ }
18
+ return false;
19
+ }
20
+
21
+ public function displayBaseGrandtotal()
22
+ {
23
+ $firstTotal = reset($this->_totals);
24
+ if (Mage::helper('pallcurrencys')->shouldConvert()) {
25
+ $total = $firstTotal->getAddress()->getBaseGrandTotal();
26
+ $total = Mage::helper('pallcurrencys')->getExchangeRate($total);
27
+ $currency = Mage::getModel('directory/currency')->load(Mage::helper('pallcurrencys')->getToCurrency());
28
+ return $currency->format($total, array(), true);
29
+ }
30
+ if ($firstTotal) {
31
+ $total = $firstTotal->getAddress()->getBaseGrandTotal();
32
+ return Mage::app()->getStore()->getBaseCurrency()->format($total, array(), true);
33
+ }
34
+ return '-';
35
+ }
36
+ }
app/code/local/Itfosters/Pallcurrencys/Helper/Data.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ public static function getBaseCurrency()
6
+ {
7
+ return Mage::app()->getStore()->getBaseCurrencyCode();
8
+ }
9
+
10
+ public function getCurrencyArray()
11
+ {
12
+ return explode(',', self::getConfig('extra_currencies'));
13
+ }
14
+
15
+ public static function getSupportedCurrency()
16
+ {
17
+ return array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
18
+ 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB');
19
+ }
20
+
21
+ public static function shouldConvert()
22
+ {
23
+ //return self::isActive() && !in_array(Mage::app()->getStore()->getCurrentCurrencyCode(), self::getSupportedCurrency()) && !in_array(self::getBaseCurrency(),self::getSupportedCurrency());
24
+ return self::isActive() && !in_array(self::getBaseCurrency(), self::getSupportedCurrency());
25
+ }
26
+
27
+ public static function getConfig($name = '')
28
+ {
29
+ if ($name) {
30
+ return Mage::getStoreConfig('payment/pallcurrencys/' . $name);
31
+ }
32
+ return;
33
+ }
34
+
35
+ public static function getToCurrency()
36
+ {
37
+ $to = self::getConfig('to_currency');
38
+ if (!$to) {
39
+ $to = 'USD';
40
+ }
41
+ return $to;
42
+ }
43
+
44
+ public function getCurrentExchangeRate()
45
+ {
46
+ $auto = self::getConfig('auto_rate');
47
+ if ($auto) {
48
+ $current = Mage::app()->getStore()->getCurrentCurrencyCode();
49
+ $to = self::getToCurrency();
50
+ $rate = Mage::getModel('directory/currency')->getCurrencyRates($current, $to);
51
+ //var_dump($rate);
52
+ if (!empty($rate[$to])) {
53
+ $rate = $rate[$to];
54
+ } else {
55
+ $rate = 1;
56
+ }
57
+ } else {
58
+ $rate = self::getConfig('rate');
59
+ }
60
+ return $rate;
61
+ }
62
+
63
+ public static function isActive()
64
+ {
65
+ $state = self::getConfig('active');
66
+ if (!$state) {
67
+ return;
68
+ }
69
+ return $state;
70
+
71
+ }
72
+
73
+ public function convertAmount($amount = false)
74
+ {
75
+ return self::getExchangeRate($amount);
76
+ }
77
+
78
+ public static function getExchangeRate($amount = false)
79
+ {
80
+ if (!self::shouldConvert()) {
81
+ return $amount;
82
+ }
83
+ if (!$amount) {
84
+ return;
85
+ }
86
+ $auto = self::getConfig('auto_rate');
87
+ if ($auto) {
88
+ $current = Mage::app()->getStore()->getCurrentCurrencyCode();
89
+ $base = Mage::app()->getStore()->getBaseCurrencyCode();
90
+ $to = self::getToCurrency();
91
+ //$rate = Mage::getModel('directory/currency')->getCurrencyRates($current, $to);
92
+ $rate = Mage::getModel('directory/currency')->getCurrencyRates($base, $to);
93
+ //var_dump($rate);
94
+ if (!empty($rate[$to])) {
95
+ $rate = $rate[$to];
96
+ } else {
97
+ $rate = 1;
98
+ }
99
+ } else {
100
+ $rate = self::getConfig('rate');
101
+ }
102
+ if ($rate) {
103
+ return $amount * $rate;
104
+ }
105
+ return;
106
+ }
107
+
108
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Cart.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Model_Cart extends Mage_Paypal_Model_Cart
4
+ {
5
+ /**
6
+ * Add a line item
7
+ *
8
+ * @param string $name
9
+ * @param numeric $qty
10
+ * @param float $amount
11
+ * @param string $identifier
12
+ * @return Varien_Object
13
+ */
14
+ public function addItem($name, $qty, $amount, $identifier = null)
15
+ {
16
+ $this->_shouldRender = true;
17
+ $amount = Mage::helper('pallcurrencys')->getExchangeRate($amount);
18
+ $item = new Varien_Object(array(
19
+ 'name' => $name,
20
+ 'qty' => $qty,
21
+ 'amount' => (float)$amount,
22
+ ));
23
+ if ($identifier) {
24
+ $item->setData('id', $identifier);
25
+ }
26
+ $this->_items[] = $item;
27
+ return $item;
28
+ }
29
+
30
+ /**
31
+ * Check the line items and totals according to PayPal business logic limitations
32
+ */
33
+ protected function _validate()
34
+ {
35
+ $this->_areItemsValid = false;
36
+ $this->_areTotalsValid = false;
37
+
38
+ //$referenceAmount = $this->_salesEntity->getBaseGrandTotal();
39
+ $referenceAmount = Mage::helper('pallcurrencys')->getExchangeRate($this->_salesEntity->getBaseGrandTotal());
40
+
41
+ $itemsSubtotal = 0;
42
+ foreach ($this->_items as $i) {
43
+ $itemsSubtotal = $itemsSubtotal + $i['qty'] * $i['amount'];
44
+ }
45
+ $sum = $itemsSubtotal + $this->_totals[self::TOTAL_TAX];
46
+ if (!$this->_isShippingAsItem) {
47
+ $sum += $this->_totals[self::TOTAL_SHIPPING];
48
+ }
49
+ if (!$this->_isDiscountAsItem) {
50
+ $sum -= $this->_totals[self::TOTAL_DISCOUNT];
51
+ }
52
+ /**
53
+ * numbers are intentionally converted to strings because of possible comparison error
54
+ * see http://php.net/float
55
+ */
56
+ // match sum of all the items and totals to the reference amount
57
+ if (sprintf('%.4F', $sum) == sprintf('%.4F', $referenceAmount)) {
58
+ $this->_areItemsValid = true;
59
+ }
60
+
61
+ // PayPal requires to have discount less than items subtotal
62
+ if (!$this->_isDiscountAsItem) {
63
+ $this->_areTotalsValid = round($this->_totals[self::TOTAL_DISCOUNT], 4) < round($itemsSubtotal, 4);
64
+ } else {
65
+ $this->_areTotalsValid = $itemsSubtotal > 0.00001;
66
+ }
67
+ $this->_areItemsValid = $this->_areItemsValid && $this->_areTotalsValid;
68
+ }
69
+
70
+ protected function _render()
71
+ {
72
+ parent::_render();
73
+ foreach ($this->_totals as $key => $value) {
74
+ $this->_totals[$key] = Mage::helper('pallcurrencys')->getExchangeRate($this->_totals[$key]);
75
+ }
76
+ }
77
+
78
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Config.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Model_Config extends Mage_Paypal_Model_Config
4
+ {
5
+ protected $_supportedCurrencyCodes = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
6
+ 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB');
7
+
8
+ public function __construct($params = array())
9
+ {
10
+ parent::__construct($params);
11
+ $this->_supportedCurrencyCodes = array_merge($this->_supportedCurrencyCodes, Mage::helper('pallcurrencys')->getCurrencyArray());
12
+ }
13
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Express.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Paypal
23
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ *
29
+ * PayPal Express Module
30
+ */
31
+ class Itfosters_Pallcurrencys_Model_Express extends Mage_Paypal_Model_Express
32
+ {
33
+
34
+ /**
35
+ * Place an order with authorization or capture action
36
+ *
37
+ * @param Mage_Sales_Model_Order_Payment $payment
38
+ * @param float $amount
39
+ * @return Mage_Paypal_Model_Express
40
+ */
41
+ protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
42
+ {
43
+ $order = $payment->getOrder();
44
+
45
+ // prepare api call
46
+ $token = $payment->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_TOKEN);
47
+
48
+ $totalamount = ($amount*(Mage::helper('ppfix')->getCurrentExchangeRate()));
49
+
50
+ $api = $this->_pro->getApi()
51
+ ->setToken($token)
52
+ ->setPayerId($payment->
53
+ getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID))
54
+ //->setAmount($amount)
55
+ ->setAmount($totalamount)
56
+ ->setPaymentAction($this->_pro->getConfig()->paymentAction)
57
+ ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
58
+ ->setInvNum($order->getIncrementId())
59
+ //->setCurrencyCode($order->getBaseCurrencyCode())
60
+ ->setCurrencyCode(Mage::helper('pallcurrencys')->getToCurrency())
61
+ ->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
62
+ ->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled);
63
+
64
+ // call api and get details from it
65
+ $api->callDoExpressCheckoutPayment();
66
+
67
+ $this->_importToPayment($api, $payment);
68
+ return $this;
69
+ }
70
+
71
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Express/Checkout.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Paypal
23
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Wrapper that performs Paypal Express and Checkout communication
29
+ * Use current Paypal Express method instance
30
+ */
31
+ class Itfosters_Pallcurrencys_Model_Express_Checkout extends Mage_Paypal_Model_Express_Checkout
32
+ {
33
+ /**
34
+ * Reserve order ID for specified quote and start checkout on PayPal
35
+ *
36
+ * @param string $returnUrl
37
+ * @param string $cancelUrl
38
+ * @param bool|null $button
39
+ * @return mixed
40
+ */
41
+ public function start($returnUrl, $cancelUrl, $button = null)
42
+ {
43
+ $this->_quote->collectTotals();
44
+
45
+ if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
46
+ Mage::throwException(Mage::helper('paypal')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.'));
47
+ }
48
+
49
+ $this->_quote->reserveOrderId()->save();
50
+ // prepare API
51
+ $this->_getApi();
52
+ $solutionType = $this->_config->getMerchantCountry() == 'DE'
53
+ ? Mage_Paypal_Model_Config::EC_SOLUTION_TYPE_MARK : $this->_config->solutionType;
54
+
55
+ $totalamount = ($this->_quote->getBaseGrandTotal()*(Mage::helper('pallcurrencys')->getCurrentExchangeRate()));
56
+ //$this->_api->setAmount($this->_quote->getBaseGrandTotal())
57
+ //->setCurrencyCode($this->_quote->getBaseCurrencyCode())
58
+ $this->_api->setAmount($totalamount)
59
+ ->setCurrencyCode(Mage::helper('pallcurrencys')->getToCurrency())
60
+ ->setInvNum($this->_quote->getReservedOrderId())
61
+ ->setReturnUrl($returnUrl)
62
+ ->setCancelUrl($cancelUrl)
63
+ ->setSolutionType($solutionType)
64
+ ->setPaymentAction($this->_config->paymentAction);
65
+
66
+ if ($this->_giropayUrls) {
67
+ list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls;
68
+ $this->_api->addData(array(
69
+ 'giropay_cancel_url' => $cancelUrl,
70
+ 'giropay_success_url' => $successUrl,
71
+ 'giropay_bank_txn_pending_url' => $pendingUrl,
72
+ ));
73
+ }
74
+
75
+ if ($this->_isBml) {
76
+ $this->_api->setFundingSource('BML');
77
+ }
78
+
79
+ $this->_setBillingAgreementRequest();
80
+
81
+ if ($this->_config->requireBillingAddress == Mage_Paypal_Model_Config::REQUIRE_BILLING_ADDRESS_ALL) {
82
+ $this->_api->setRequireBillingAddress(1);
83
+ }
84
+
85
+ // supress or export shipping address
86
+ if ($this->_quote->getIsVirtual()) {
87
+ if ($this->_config->requireBillingAddress == Mage_Paypal_Model_Config::REQUIRE_BILLING_ADDRESS_VIRTUAL) {
88
+ $this->_api->setRequireBillingAddress(1);
89
+ }
90
+ $this->_api->setSuppressShipping(true);
91
+ } else {
92
+ $address = $this->_quote->getShippingAddress();
93
+ $isOverriden = 0;
94
+ if (true === $address->validate()) {
95
+ $isOverriden = 1;
96
+ $this->_api->setAddress($address);
97
+ }
98
+ $this->_quote->getPayment()->setAdditionalInformation(
99
+ self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden
100
+ );
101
+ $this->_quote->getPayment()->save();
102
+ }
103
+
104
+ // add line items
105
+ $paypalCart = Mage::getModel('paypal/cart', array($this->_quote));
106
+ $this->_api->setPaypalCart($paypalCart)
107
+ ->setIsLineItemsEnabled($this->_config->lineItemsEnabled)
108
+ ;
109
+
110
+ // add shipping options if needed and line items are available
111
+ if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) {
112
+ if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) {
113
+ if ($options = $this->_prepareShippingOptions($address, true)) {
114
+ $this->_api->setShippingOptionsCallbackUrl(
115
+ Mage::getUrl('*/*/shippingOptionsCallback', array('quote_id' => $this->_quote->getId()))
116
+ )->setShippingOptions($options);
117
+ }
118
+ }
119
+ }
120
+
121
+ // add recurring payment profiles information
122
+ if ($profiles = $this->_quote->prepareRecurringPaymentProfiles()) {
123
+ foreach ($profiles as $profile) {
124
+ $profile->setMethodCode(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
125
+ if (!$profile->isValid()) {
126
+ Mage::throwException($profile->getValidationErrors(true, true));
127
+ }
128
+ }
129
+ $this->_api->addRecurringPaymentProfiles($profiles);
130
+ }
131
+
132
+ $this->_config->exportExpressCheckoutStyleSettings($this->_api);
133
+
134
+ // call API and redirect with token
135
+ $this->_api->callSetExpressCheckout();
136
+ $token = $this->_api->getToken();
137
+ $this->_redirectUrl = $button ? $this->_config->getExpressCheckoutStartUrl($token)
138
+ : $this->_config->getPayPalBasicStartUrl($token);
139
+
140
+ $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
141
+
142
+ // Set flag that we came from Express Checkout button
143
+ if (!empty($button)) {
144
+ $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_BUTTON, 1);
145
+ } elseif ($this->_quote->getPayment()->hasAdditionalInformation(self::PAYMENT_INFO_BUTTON)) {
146
+ $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_BUTTON);
147
+ }
148
+
149
+ $this->_quote->getPayment()->save();
150
+ return $token;
151
+ }
152
+
153
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Observer.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Model_Observer
4
+ {
5
+ public function setConfig(Varien_Event_Observer $observer)
6
+ {
7
+ $currentMerchant = Mage::getStoreConfig('paypal/general/business_account');
8
+ $ppMerchant = Mage::helper('pallcurrencys')->getConfig('business_account');
9
+ if ($currentMerchant != $ppMerchant) {
10
+ $config = new Mage_Core_Model_Config();
11
+ $config->saveConfig('paypal/general/business_account', $ppMerchant, 'default', 0);
12
+ }
13
+
14
+ }
15
+
16
+ public function setPaymentInfo(Varien_Event_Observer $observer)
17
+ {
18
+ $order = $observer->getOrder();
19
+ $payment = $order->getPayment();
20
+ $code = $payment->getMethod();
21
+ if (in_array($code, array('paypal_standard'))) {
22
+ $payment->setAdditionalInformation('payment_currency', Mage::helper('pallcurrencys')->getToCurrency());
23
+ $payment->setAdditionalInformation('due_amount', Mage::helper('pallcurrencys')->convertAmount($order->getBaseGrandTotal()));
24
+ $payment->setAdditionalInformation('exchange_rate', Mage::helper('pallcurrencys')->getCurrentExchangeRate());
25
+ }
26
+ $payment->save();
27
+ }
28
+
29
+ public function getPaymentInfo(Varien_Event_Observer $observer)
30
+ {
31
+ $transport = $observer->getTransport();
32
+ $payment = $observer->getPayment();
33
+ if ($payment->getAdditionalInformation('payment_currency')) {
34
+ $transport['Payment Currency'] = $payment->getAdditionalInformation('payment_currency');
35
+ }
36
+ if ($payment->getAdditionalInformation('due_amount')) {
37
+ $transport['Amount Due'] = $payment->getAdditionalInformation('due_amount');
38
+
39
+ }
40
+ if ($payment->getAdditionalInformation('exchange_rate')) {
41
+ $transport['Exchange Rate'] = $payment->getAdditionalInformation('exchange_rate');
42
+
43
+ }
44
+ return;
45
+ }
46
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Payment.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Model_Payment extends Mage_Sales_Model_Order_Payment
4
+ {
5
+
6
+ /**
7
+ * Process a capture notification from a payment gateway for specified amount
8
+ * Creates an invoice automatically if the amount covers the order base grand total completely
9
+ * Updates transactions hierarchy, if required
10
+ * Prevents transaction double processing
11
+ * Updates payment totals, updates order status and adds proper comments
12
+ *
13
+ * TODO: eliminate logic duplication with capture()
14
+ *
15
+ * @param float $amount
16
+ * @param bool $skipFraudDetection
17
+ * @return Mage_Sales_Model_Order_Payment
18
+ */
19
+ public function registerCaptureNotification($amount, $skipFraudDetection = false)
20
+ {
21
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
22
+ $this->getAuthorizationTransaction()
23
+ );
24
+
25
+ $order = $this->getOrder();
26
+ $amount = (float)$amount;
27
+ //DD
28
+ $currency = Mage::getModel('directory/currency')->load(Mage::helper('pallcurrencys')->getToCurrency());
29
+ Mage::log('Currency:' . $currency->getCurrencyCode());
30
+ Mage::log($currency->getCurrencyCode());
31
+ Mage::log('amount:' . strval($amount));
32
+ Mage::log('grand total:' . strval((float)$order->getBaseGrandTotal()));
33
+ if ($currency->getCurrencyCode() != Mage::app()->getStore()->getBaseCurrencyCode()) {
34
+ $amount = (float)$order->getBaseGrandTotal();
35
+ }
36
+
37
+ //--DD
38
+ $invoice = $this->_getInvoiceForTransactionId($this->getTransactionId());
39
+
40
+ // register new capture
41
+ if (!$invoice) {
42
+ if ($this->_isCaptureFinal($amount)) {
43
+ $invoice = $order->prepareInvoice()->register();
44
+ $order->addRelatedObject($invoice);
45
+ $this->setCreatedInvoice($invoice);
46
+ } else {
47
+ if (!$skipFraudDetection) {
48
+ $this->setIsFraudDetected(true);
49
+ }
50
+ $this->_updateTotals(array('base_amount_paid_online' => $amount));
51
+ }
52
+ }
53
+
54
+ $status = true;
55
+ if ($this->getIsTransactionPending()) {
56
+ $message = Mage::helper('sales')->__('Capturing amount of %s is pending approval on gateway.', $this->_formatPrice($amount));
57
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
58
+ if ($this->getIsFraudDetected()) {
59
+ $message = Mage::helper('sales')->__('Order is suspended as its capture amount %s is suspected to be fraudulent.', $this->_formatPrice($amount));
60
+ $status = Mage_Sales_Model_Order::STATUS_FRAUD;
61
+ }
62
+ } else {
63
+ $message = Mage::helper('sales')->__('Registered notification about captured amount of %s.', $this->_formatPrice($amount));
64
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
65
+ if ($this->getIsFraudDetected()) {
66
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
67
+ $message = Mage::helper('sales')->__('Order is suspended as its capture amount %s is suspected to be fraudulent.', $this->_formatPrice($amount));
68
+ $status = Mage_Sales_Model_Order::STATUS_FRAUD;
69
+ }
70
+ // register capture for an existing invoice
71
+ if ($invoice && Mage_Sales_Model_Order_Invoice::STATE_OPEN == $invoice->getState()) {
72
+ $invoice->pay();
73
+ $this->_updateTotals(array('base_amount_paid_online' => $amount));
74
+ $order->addRelatedObject($invoice);
75
+ }
76
+ }
77
+
78
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $invoice, true);
79
+ $message = $this->_prependMessage($message);
80
+ $message = $this->_appendTransactionToMessage($transaction, $message);
81
+ $order->setState($state, $status, $message);
82
+ return $this;
83
+ }
84
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Source/Currency.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Model_Source_Currency extends Mage_Adminhtml_Model_System_Config_Source_Currency
4
+ {
5
+ protected $_options;
6
+
7
+ public function toOptionArray($isMultiselect)
8
+ {
9
+ $_supportedCurrencyCodes = Mage::helper('pallcurrencys')->getSupportedCurrency();
10
+ if (!$this->_options) {
11
+ $this->_options = Mage::app()->getLocale()->getOptionCurrencies();
12
+ }
13
+ $options = array();
14
+ foreach ($this->_options as $option) {
15
+ if (in_array($option['value'], $_supportedCurrencyCodes)) {
16
+ $options[] = $option;
17
+ }
18
+ }
19
+ return $options;
20
+ }
21
+ }
app/code/local/Itfosters/Pallcurrencys/Model/Standard.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itfosters_Pallcurrencys_Model_Standard extends Mage_Paypal_Model_Standard
4
+ {
5
+
6
+ public function canUseForCurrency($currencyCode)
7
+ {
8
+ $result = $this->getConfig()->isCurrencyCodeSupported($currencyCode);
9
+ if ($result == false) {
10
+ $result = strpos(Mage::helper('pallcurrencys')->getConfig('extra_currencies'), Mage::app()->getStore()->getCurrentCurrencyCode());
11
+ }
12
+ return $result;
13
+ }
14
+
15
+ /**
16
+ * Return form field array
17
+ *
18
+ * @return array
19
+ */
20
+ public function getStandardCheckoutFormFields()
21
+ {
22
+ $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
23
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
24
+ /* @var $api Mage_Paypal_Model_Api_Standard */
25
+ $api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
26
+ $api->setOrderId($orderIncrementId)
27
+ ->setCurrencyCode(Mage::helper('pallcurrencys')->getToCurrency())
28
+ //->setPaymentAction()
29
+ ->setOrder($order)
30
+ ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
31
+ ->setReturnUrl(Mage::getUrl('paypal/standard/success'))
32
+ ->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
33
+
34
+ // export address
35
+ $isOrderVirtual = $order->getIsVirtual();
36
+ $address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
37
+ if ($isOrderVirtual) {
38
+ $api->setNoShipping(true);
39
+ } elseif ($address->validate()) {
40
+ $api->setAddress($address);
41
+ }
42
+
43
+ // add cart totals and line items
44
+ $api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
45
+ ->setIsLineItemsEnabled($this->_config->lineItemsEnabled);
46
+ $api->setCartSummary($this->_getAggregatedCartSummary());
47
+ $api->setLocale($api->getLocaleCode());
48
+ $result = $api->getStandardCheckoutRequest();
49
+ return $result;
50
+ }
51
+
52
+ private function _getAggregatedCartSummary()
53
+ {
54
+ if ($this->_config->lineItemsSummary) {
55
+ return $this->_config->lineItemsSummary;
56
+ }
57
+ return Mage::app()->getStore($this->getStore())->getFrontendName();
58
+ }
59
+ }
app/code/local/Itfosters/Pallcurrencys/etc/config.xml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Itfosters_Pallcurrencys>
5
+ <version>0.1.0</version>
6
+ </Itfosters_Pallcurrencys>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <itfosters_pallcurrencys>
11
+ <class>Itfosters_Pallcurrencys_Model</class>
12
+ </itfosters_pallcurrencys>
13
+ <paypal>
14
+ <rewrite>
15
+ <cart>Itfosters_Pallcurrencys_Model_Cart</cart>
16
+ <standard>Itfosters_Pallcurrencys_Model_Standard</standard>
17
+ <config>Itfosters_Pallcurrencys_Model_Config</config>
18
+ <express_checkout>Itfosters_Pallcurrencys_Model_Express_Checkout</express_checkout>
19
+ <express>Itfosters_Pallcurrencys_Model_Express</express>
20
+ </rewrite>
21
+ </paypal>
22
+ <sales>
23
+ <rewrite>
24
+ <order_payment>Itfosters_Pallcurrencys_Model_Payment</order_payment>
25
+ </rewrite>
26
+ </sales>
27
+ </models>
28
+ <blocks>
29
+ <pallcurrencys>
30
+ <class>Itfosters_Pallcurrencys_Block</class>
31
+ </pallcurrencys>
32
+ <checkout>
33
+ <rewrite>
34
+ <cart_totals>Itfosters_Pallcurrencys_Block_Checkout_Cart_Totals</cart_totals>
35
+ </rewrite>
36
+ </checkout>
37
+ </blocks>
38
+ <helpers>
39
+ <pallcurrencys>
40
+ <class>Itfosters_Pallcurrencys_Helper</class>
41
+ </pallcurrencys>
42
+ </helpers>
43
+ <resources>
44
+ <pallcurrencys_setup>
45
+ <setup>
46
+ <module>Itfosters_Pallcurrencys</module>
47
+ </setup>
48
+ </pallcurrencys_setup>
49
+ </resources>
50
+ <events>
51
+ <sales_order_save_after>
52
+ <observers>
53
+ <pbfix_sales_order_observer_payment>
54
+ <class>Itfosters_Pallcurrencys_Model_Observer</class>
55
+ <method>setPaymentInfo</method>
56
+ </pbfix_sales_order_observer_payment>
57
+ </observers>
58
+ </sales_order_save_after>
59
+ </events>
60
+ </global>
61
+ <adminhtml>
62
+ <events>
63
+ <payment_info_block_prepare_specific_information>
64
+ <observers>
65
+ <pallcurrencys_payment_info>
66
+ <class>Itfosters_Pallcurrencys_Model_Observer</class>
67
+ <method>getPaymentInfo</method>
68
+ </pallcurrencys_payment_info>
69
+ </observers>
70
+ </payment_info_block_prepare_specific_information>
71
+ <adminhtml_init_system_config>
72
+ <observers>
73
+ <pallcurrencys>
74
+ <class>Itfosters_Pallcurrencys_Model_Observer</class>
75
+ <method>setConfig</method>
76
+ </pallcurrencys>
77
+ </observers>
78
+ </adminhtml_init_system_config>
79
+
80
+ </events>
81
+ </adminhtml>
82
+ </config>
app/code/local/Itfosters/Pallcurrencys/etc/system.xml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <pallcurrencys translate="label" module="pallcurrencys">
7
+ <label>Paypal Multi Currency</label>
8
+ <sort_order>1000</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>0</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ </active>
22
+ <business_account translate="label">
23
+ <label>Merchant Email</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <validate>validate-email required-entry</validate>
30
+ </business_account>
31
+ <extra_currencies translate="label">
32
+ <label>Extra Currencies</label>
33
+ <comment>extra currency to support for your store</comment>
34
+ <frontend_type>multiselect</frontend_type>
35
+ <source_model>adminhtml/system_config_source_currency</source_model>
36
+ <sort_order>2</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <validate>required-entry</validate>
41
+ </extra_currencies>
42
+ <to_currency translate="label">
43
+ <label>Checkout Currency</label>
44
+ <tooltip>The selected currencies will be converted to this currency and this currency will be used in checkout instead.</tooltip>
45
+ <frontend_type>select</frontend_type>
46
+ <source_model>itfosters_pallcurrencys_model_source_currency</source_model>
47
+ <sort_order>3</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>1</show_in_website>
50
+ <show_in_store>1</show_in_store>
51
+ <validate>required-entry</validate>
52
+ </to_currency>
53
+ <auto_rate translate="label">
54
+ <label>Auto Calculate Exchange Rate</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>adminhtml/system_config_source_yesno</source_model>
57
+ <sort_order>4</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ </auto_rate>
62
+ <rate translate="label">
63
+ <label>Exchange Rate</label>
64
+ <frontend_type>text</frontend_type>
65
+ <sort_order>5</sort_order>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ <depends>
70
+ <auto_rate>0</auto_rate>
71
+ </depends>
72
+ </rate>
73
+ </fields>
74
+ </pallcurrencys>
75
+ </groups>
76
+ </payment>
77
+ </sections>
78
+ </config>
app/code/local/Itfosters/Pallcurrencys/sql/.DS_Store ADDED
Binary file
app/code/local/Itfosters/Pallcurrencys/sql/itfosters_pallcurrencys_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: meabed
5
+ * Date: 11/16/12
6
+ * Time: 1:27 AM
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+ /* @var $installer Mage_Core_Model_Resource_Setup */
10
+ $installer = $this;
11
+
12
+ $installer->startSetup();
13
+
14
+
15
+ $installer->endSetup();
app/etc/modules/Itfosters_Pallcurrencys.xml CHANGED
@@ -3,7 +3,7 @@
3
  <modules>
4
  <Itfosters_Pallcurrencys>
5
  <active>true</active>
6
- <codePool>community</codePool>
7
  <depends>
8
  <Mage_Paypal/>
9
  </depends>
3
  <modules>
4
  <Itfosters_Pallcurrencys>
5
  <active>true</active>
6
+ <codePool>local</codePool>
7
  <depends>
8
  <Mage_Paypal/>
9
  </depends>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Itfosters_Pallcurrencys</name>
4
- <version>0.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Paypal standard support the all the currency with INR</summary>
10
- <description>Paypal standard support the all the currency with INR</description>
11
- <notes>Paypal standard support the all the currency with INR</notes>
12
- <authors><author><name>Raj kumar</name><user>Raj</user><email>rajwebsoft@gmail.com</email></author></authors>
13
- <date>2016-07-28</date>
14
- <time>11:23:24</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="Itfosters_Pallcurrencys.xml" hash="b0c6f8fabf5c4b51379f892244d95c24"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Itfosters_Pallcurrencys</name>
4
+ <version>0.1.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>All the currency is not supported by the paypal then use the unsported currency in this exenstion</summary>
10
+ <description>All the currency is not supported by the paypal then use the unsported currency in this exenstion</description>
11
+ <notes>All the currency is not supported by the paypal then use the unsported currency in this exenstion</notes>
12
+ <authors><author><name>Raj kumar</name><user>rajwebsoft</user><email>rajwebsoft@gmail.com</email></author></authors>
13
+ <date>2016-09-11</date>
14
+ <time>11:52:15</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Itfosters_Pallcurrencys.xml" hash="7713be147d87a64688d5f4c3cb045162"/></dir></target><target name="magelocal"><dir name="Itfosters"><dir name="Pallcurrencys"><dir name="Block"><dir name="Checkout"><dir name="Cart"><file name="Totals.php" hash="18062b9facbef7fa0b5ab03e663a88af"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="7b98e264470a78002d7cae8f0f93cb48"/></dir><dir name="Model"><file name="Cart.php" hash="87fcb53b8fc2bfb361db856112eef581"/><file name="Config.php" hash="744763f3e2e117a4a24d4faf473ad0a1"/><dir name="Express"><file name="Checkout.php" hash="b3397a2dfa9f7a5926f54d3f013b8559"/></dir><file name="Express.php" hash="a03cd8db99ebe8786272558ff584bc4d"/><file name="Observer.php" hash="30dd037b72690401685c4d18998a6b3e"/><file name="Payment.php" hash="1f3a1dd6f76e050dfac727a08a0cb6e0"/><dir name="Source"><file name="Currency.php" hash="590646fe8397f90809ea6be8cbee185d"/></dir><file name="Standard.php" hash="9d5d8a30b6bed3fd2214d5194d940fe4"/></dir><dir name="etc"><file name="config.xml" hash="5af6e96e02efc2dec5688a6cd03f5546"/><file name="system.xml" hash="b883645bdb51d7c6ba3dd54d7d1dd727"/></dir><dir name="sql"><dir name="itfosters_pallcurrencys_setup"><file name="mysql4-install-0.1.0.php" hash="69e5c1cee8fa980eede6d37d9d4b4ab4"/></dir><file name=".DS_Store" hash="a4ebc0f8acd6d4c0c1fff6099a92599e"/></dir><file name=".DS_Store" hash="e7cd9bd9195ab59c9bdeb45c59eade58"/></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>