magento 显示paypal不支持的货币

通过清心醉

magento 显示paypal不支持的货币

修改文件
app/code/core/mage/payment/block/form/Container.php
app/code/core/mage/paypal/model/Standard.php

1.app/code/core/mage/payment/block/form/Container.php
找到函数_canUseMethod 大概在第54行,换成如下代码

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;
}

2.app/code/core/mage/paypal/model/Standard.php
找到函数validate,大概在127行,换成如下代码

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;

}

找到函数getStandardCheckoutFormFields,大概在158行,改成如下代码

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 “”; print_r($item->getData()); echo””;
$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;

 

关于作者

清心醉 administrator

发表评论

如果喜欢作者的文章,您可以打赏给作者:

TRC20(虚拟货币):


ERC20(虚拟货币):


Bitcoin(BTC):