Tweak PayPal Standard for Non-Supported Base Currency
The Issue |
As of July 2009, PayPal supports these currencies.
- Canadian Dollars
- Euros
- British Pounds
- U.S. Dollars
- Yen
- Australian Dollars
- New Zealand Dollars
- Swiss Francs
- Hong Kong Dollars
- Singapore Dollars
- Swedish Kroner
- Danish Kroner
- Polish Zloty
- Norwegian Kroner
- Hungarian Forints
- Czech Koruny
- Israeli Shekels
- Mexican Pesos
If you have set your base currency to one not listed above and have enable the PayPal Standard in Admin>System>Configuration, PayPal Standard payment method will not be listed in the onepage checkout after version 1.3.0.
The tweak describe here enable you to get around this issue by changing two core files:
app/code/core/Mage/Payment/Block/Form/Container.phpapp/code/core/Mage/Paypal/Model/Standard.php
Download |
To make things easy, you can download the zip file (no longer available). Unzip the file in app/code/local/ so that Magento updates will not overwrite the files. You should now have
app/code/local/Mage/Payment/Block/Form/Container.phpapp/code/local/Mage/Paypal/Model/Standard.php
Setup PayPal |
To setup PayPal Standard with IPN, refer this wiki Paypal Standard Payments Setup with IPN
To configure PayPal in Magento:
- Setup the allowed currencies in
Admin>System>Configuration>Currency Setup
Modify Container.php |
Locate the file app/code/core/mage/payment/block/form/Container.php Find function _canUseMethod, line 54 and change to this:
- protected function _canUseMethod($method)
- {
- if (!$method->canUseForCountry($this->getQuote()->getBillingAddress()->getCountry())) {
- return false;
- }
- //if (!$method->canUseForCurrency(Mage::app()->getStore()->getBaseCurrencyCode())) {
- if (!$method->canUseForCurrency(Mage::app()->getStore()->getCurrentCurrencyCode())) {
- return false;
- }
- /**
- * Checking for min/max order total for assigned payment method
- */
- $total = $this->getQuote()->getBaseGrandTotal();
- $minTotal = $method->getConfigData('min_order_total');
- $maxTotal = $method->getConfigData('max_order_total');
- if((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) {
- return false;
- }
- return true;
- }
Modify Standard.php |
Locate app/code/core/mage/paypal/model/Standard.php. Find function validate, line 127 and edit:
- public function validate()
- {
- parent::validate();
- //$currency_code = $this->getQuote()->getBaseCurrencyCode();
- $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
- if (!in_array($currency_code,$this->_allowCurrencyCode)) {
- Mage::throwException(Mage::helper('paypal')->__('Selected currency code ('.$currency_code.') is not compatible with PayPal'));
- }
- return $this;
- }
Find function getStandardCheckoutFormFields, line 158 and edit:
- public function getStandardCheckoutFormFields()
- {
- if ($this->getQuote()->getIsVirtual()) {
- $a = $this->getQuote()->getBillingAddress();
- $b = $this->getQuote()->getShippingAddress();
- } else {
- $a = $this->getQuote()->getShippingAddress();
- $b = $this->getQuote()->getBillingAddress();
- }
- /*tweak version
- init currency conversion
- if currency is not the same as base currency, set convert boolean to true
- */
- $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
- $storeCurrency = Mage::getSingleton('directory/currency')
- ->load($this->getQuote()->getStoreCurrencyCode());
- $bConvert = $currency_code != $this->getQuote()->getBaseCurrencyCode();
- $sArr = array(
- 'charset' => self::DATA_CHARSET,
- 'business' => Mage::getStoreConfig('paypal/wps/business_account'),
- 'return' => Mage::getUrl('paypal/standard/success',array('_secure' => true)),
- 'cancel_return' => Mage::getUrl('paypal/standard/cancel',array('_secure' => false)),
- 'notify_url' => Mage::getUrl('paypal/standard/ipn'),
- 'invoice' => $this->getCheckout()->getLastRealOrderId(),
- 'currency_code' => $currency_code,
- 'address_override' => 1,
- 'first_name' => $a->getFirstname(),
- 'last_name' => $a->getLastname(),
- 'address1' => $a->getStreet(1),
- 'address2' => $a->getStreet(2),
- 'city' => $a->getCity(),
- 'state' => $a->getRegionCode(),
- 'country' => $a->getCountry(),
- 'zip' => $a->getPostcode(),
- 'bn' => 'Varien_Cart_WPS_US'
- );
- $logoUrl = Mage::getStoreConfig('paypal/wps/logo_url');
- if($logoUrl){
- $sArr = array_merge($sArr, array(
- 'cpp_header_image' => $logoUrl
- ));
- }
- if($this->getConfigData('payment_action')==self::PAYMENT_TYPE_AUTH){
- $sArr = array_merge($sArr, array(
- 'paymentaction' => 'authorization'
- ));
- }
- $transaciton_type = $this->getConfigData('transaction_type');
- /*
- O=aggregate cart amount to paypal
- I=individual items to paypal
- */
- if ($transaciton_type=='O') {
- $businessName = Mage::getStoreConfig('paypal/wps/business_name');
- $storeName = Mage::getStoreConfig('store/system/name');
- $amount = ($a->getBaseSubtotal()+$b->getBaseSubtotal())-($a->getBaseDiscountAmount()+$b->getBaseDiscountAmount());
- //convert the amount to the current currency
- if ($bConvert) {
- $amount = $storeCurrency->convert($amount, $currency_code);
- }
- $sArr = array_merge($sArr, array(
- 'cmd' => '_ext-enter',
- 'redirect_cmd' => '_xclick',
- 'item_name' => $businessName ? $businessName : $storeName,
- 'amount' => sprintf('%.2f', $amount),
- ));
- $_shippingTax = $this->getQuote()->getShippingAddress()->getBaseTaxAmount();
- $_billingTax = $this->getQuote()->getBillingAddress()->getBaseTaxAmount();
- $tax = $_shippingTax + $_billingTax;
- //convert the amount to the current currency
- if ($bConvert) {
- $tax = $storeCurrency->convert($tax, $currency_code);
- }
- $tax = sprintf('%.2f', $tax);
- if ($tax>0) {
- $sArr = array_merge($sArr, array(
- 'tax' => $tax
- ));
- }
- } else {
- $sArr = array_merge($sArr, array(
- 'cmd' => '_cart',
- 'upload' => '1',
- ));
- $items = $this->getQuote()->getAllItems();
- if ($items) {
- $i = 1;
- foreach($items as $item){
- if ($item->getParentItem()) {
- continue;
- }
- //echo "<pre>"; print_r($item->getData()); echo"</pre>";
- $amount = ($item->getBaseCalculationPrice() - $item->getBaseDiscountAmount());
- if ($bConvert) {
- $amount = $storeCurrency->convert($amount, $currency_code);
- }
- $sArr = array_merge($sArr, array(
- 'item_name_'.$i => $item->getName(),
- 'item_number_'.$i => $item->getSku(),
- 'quantity_'.$i => $item->getQty(),
- 'amount_'.$i => sprintf('%.2f', $amount),
- ));
- $tax = $item->getBaseTaxAmount();
- if($tax>0){
- //convert the amount to the current currency
- if ($bConvert) {
- $tax = $storeCurrency->convert($tax, $currency_code);
- }
- $sArr = array_merge($sArr, array(
- 'tax_'.$i => sprintf('%.2f',$tax/$item->getQty()),
- ));
- }
- $i++;
- }
- }
- }
- $totalArr = $a->getTotals();
- $shipping = $this->getQuote()->getShippingAddress()->getBaseShippingAmount();
- if ($shipping>0 && !$this->getQuote()->getIsVirtual()) {
- //convert the amount to the current currency
- if ($bConvert) {
- $shipping = $storeCurrency->convert($shipping, $currency_code);
- }
- $shipping = sprintf('%.2f', $shipping);
- if ($transaciton_type=='O') {
- $sArr = array_merge($sArr, array(
- 'shipping' => $shipping
- ));
- } else {
- $shippingTax = $this->getQuote()->getShippingAddress()->getBaseShippingTaxAmount();
- //convert the amount to the current currency
- if ($bConvert) {
- $shippingTax = $storeCurrency->convert($shippingTax, $currency_code);
- }
- $sArr = array_merge($sArr, array(
- 'item_name_'.$i => $totalArr['shipping']->getTitle(),
- 'quantity_'.$i => 1,
- 'amount_'.$i => sprintf('%.2f',$shipping),
- 'tax_'.$i => sprintf('%.2f',$shippingTax),
- ));
- $i++;
- }
- }
- $sReq = '';
- $sReqDebug = '';
- $rArr = array();
- foreach ($sArr as $k=>$v) {
- /*
- replacing & char with and. otherwise it will break the post
- */
- $value = str_replace("&","and",$v);
- $rArr[$k] = $value;
- $sReq .= '&'.$k.'='.$value;
- $sReqDebug .= '&'.$k.'=';
- if (in_array($k, $this->_debugReplacePrivateDataKeys)) {
- $sReqDebug .= '***';
- } else {
- $sReqDebug .= $value;
- }
- }
- if ($this->getDebug() && $sReq) {
- $sReq = substr($sReq, 1);
- $debug = Mage::getModel('paypal/api_debug')
- ->setApiEndpoint($this->getPaypalUrl())
- ->setRequestBody($sReq)
- ->save();
- }
- return $rArr;
- }
Alternative Solution |
Create the file Config.php in /app/code/local/Mage/Paypal/Model/Config.php
Step 1
Copy the file from /app/code/core/Mage/Paypal/Model/Config.php to /app/code/local/Mage/Paypal/Model/Config.php
Step 2
Look for the $_supportedCurrencyCodes
protected $_supportedCurrencyCodes = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB');
and add your currency that needs supporting to the end of the array
protected $_supportedCurrencyCodes = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB', 'PHP');




