Php 将PayPal支付的Magento中不可接受的货币兑换为美元
简介:如果您的基础货币不是此处列出的货币,则Magento的PayPal支付模块将不会将货币转换为美元或任何PayPal接受的货币 我安装了Magento,安装了3种货币 我使用PayPal标准支付作为支付选项,但问题是,用户收取的费用相同,但以美元计。例如,如果我有100罗恩,并选择支付贝宝我将收取100美元,而不是 我检查了paypal模块,该模块使重定向在中可用 app/code/core/Mage/Paypal/Block/Standard/Redirect.php 与货币和金额相关的变量被正确设置并发送到paypal 我不知道如何准确地解决这个问题,这是非常令人沮丧的,因为我猜Magento中的标准PayPal模块是由PayPal(需要确认)设计的,并针对这种情况进行了验证 Info#1:PayPal不接受交易中的某些货币(例如罗马尼亚雷亚尔,它恰好是本店的基础货币)(此处列出了允许的货币),因此在您单击提交时,他们将只转换货币符号(转换为美元),而不转换金额。您必须自己更改的金额,但是Magento(v1.5)中的默认PayPal模块没有这样做,这就是我打开此问题的原因 编辑#1 我尝试了下面提出的解决方案,但它不起作用,因为事实上它替换了一些变量,但不是以期望的方式 我在这里看到两种选择: 选项#1:“查找并替换”选项是我查找最终形式的所有浮动值,并将其替换为转换为美元的值。但是,这不是一个可行的选项,因为未正确转换值,可能会发生错误 选项2: 我找到了在表单中弹出值的函数,它位于spp/code/core/Mage/Paypal/Model/Api/Abstract.php中Php 将PayPal支付的Magento中不可接受的货币兑换为美元,php,api,magento,paypal,currency,Php,Api,Magento,Paypal,Currency,简介:如果您的基础货币不是此处列出的货币,则Magento的PayPal支付模块将不会将货币转换为美元或任何PayPal接受的货币 我安装了Magento,安装了3种货币 我使用PayPal标准支付作为支付选项,但问题是,用户收取的费用相同,但以美元计。例如,如果我有100罗恩,并选择支付贝宝我将收取100美元,而不是 我检查了paypal模块,该模块使重定向在中可用 app/code/core/Mage/Paypal/Block/Standard/Redirect.php 与货币和金额相关的变
protected function _exportLineItems(array &$request, $i = 0)
{
if (!$this->_cart) {
return;
}
// always add cart totals, even if line items are not requested
if ($this->_lineItemTotalExportMap) {
foreach ($this->_cart->getTotals() as $key => $total) {
if (isset($this->_lineItemTotalExportMap[$key])) { // !empty($total)
$privateKey = $this->_lineItemTotalExportMap[$key];
$request[$privateKey] = $this->_filterAmount($total);
}
}
}
// add cart line items
$items = $this->_cart->getItems();
if (empty($items) || !$this->getIsLineItemsEnabled()) {
return;
}
$result = null;
foreach ($items as $item) {
foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
$result = true;
$value = $item->getDataUsingMethod($publicKey);
if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
$callback = $this->_lineItemExportItemsFilters[$publicKey];
$value = call_user_func(array($this, $callback), $value);
}
if (is_float($value)) {
$value = $this->_filterAmount($value);
}
$request[sprintf($privateFormat, $i)] = $value;
}
$i++;
}
return $result;
}
这两条线:
$request[$privateKey] = $this->_filterAmount($total);
$value = $this->_filterAmount($value);
打印变量列表中的金额,因此我编写了以下函数,该函数应根据后端定义的汇率将金额从任何基础货币转换为美元,而不是函数_filterAmount:
protected function _convertAmounttoUSD($value)
{
$baseCode = Mage::app()->getBaseCurrencyCode();
$fromCur = Mage::app()->getStore()->getCurrentCurrencyCode();
$toCur = 'USD';
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies));
$output = ( $value * $rates[$toCur] ) / $rates[$fromCur];
return sprintf('%.2F', $output);
}
我已将上述行替换为以下内容:
$request[$privateKey] = $this->_convertAmounttoUSD($total);
$value = $this->_convertAmounttoUSD($value);
问题是这些值没有被转换。在magento中,当用户被重定向到paypal it时,magento会发送存储货币进行收费,但paypal使用paypal帐户中关联的货币,因此我们需要将其转换为paypal帐户货币 它将收取100罗恩,但将其转换为美元货币 您需要使用以下功能在以下文件中进行更改: app\code\core\Mage\Paypal\Model\Standard.php 将getStandardCheckoutFormFields函数替换为以下函数:
public function getStandardCheckoutFormFields()
{
$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
$api->setOrderId($orderIncrementId)
->setCurrencyCode($order->getBaseCurrencyCode())
//->setPaymentAction()
->setOrder($order)
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
->setReturnUrl(Mage::getUrl('paypal/standard/success'))
->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
// export address
$isOrderVirtual = $order->getIsVirtual();
$address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
if ($isOrderVirtual) {
$api->setNoShipping(true);
} elseif ($address->validate()) {
$api->setAddress($address);
}
// add cart totals and line items
$api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
->setIsLineItemsEnabled($this->_config->lineItemsEnabled)
;
$api->setCartSummary($this->_getAggregatedCartSummary());
$result = $api->getStandardCheckoutRequest();
$baseCode = Mage::app()->getBaseCurrencyCode();
$fromCur = Mage::app()->getStore()->getCurrentCurrencyCode();
$toCur = 'USD';
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies));
$result['amount'] = round((($order->getGrandTotal() * $rates[$toCur])/$rates[$fromCur]),2);
$result['currency_code'] = $toCur;
$j = 0;
$items = $order->getAllItems();
foreach ($items as $itemId => $item)
{
if ($item->getParentItem()) {
continue;
}
$j ++;
$result['amount_'.$j] = round((($item->getPrice() * $rates[$toCur])/$rates[$fromCur]),2);
}
$j++;
$result['country'] = $order->getBillingAddress()->getCountryId();
$shippingSpo = $order->getBaseShippingAmount();
$result['shipping'] = round((($shippingSpo * $rates[$toCur])/$rates[$fromCur]),2);
$result['discount_amount'] = -1*round((($order->getDiscountAmount() * $rates[$toCur])/$rates[$fromCur]),2);
$result['discount_amount_cart'] = $result['discount_amount'];
$result['amount_'.$j] = $result['shipping'];
unset($result['discount_amount']);
unset($result['shipping']);
unset($result['discount_amount_cart']);
unset($result['amount_'.$j]);
return $result;
}
你好!谢谢你的回答!它可以工作,但是在paypal checkout中,它也不转换税收,但它保留原始货币的价值,并将其添加到最终价格。您能否至少提供获得此代码的来源?您的问题解决了吗?你能帮我吗@