magento paypal付款实现前台切换货币付款

magento默认的付款机制是不管前台切换什么货币付款,跳转到paypal付款界面时,都会是以基货币来付款的 需要修改几个文件 app\code\core\Mage\Paypal\Model\Standard.php
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->getOrderCurrencyCode())//---修改   当前订单的货币
            //->setPaymentAction()
            ->setOrder($order)
            ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))//---ipn验证
         ...
}
app\code\core\Mage\Paypal\Model\Cart.php
protected function _render()
{
...
   if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
      $shippingDescription = $this->_salesEntity->getShippingDescription();
      $this->_totals = array(
          self::TOTAL_SUBTOTAL => $this->_salesEntity->getSubtotal(),//---修改
          self::TOTAL_TAX      => $this->_salesEntity->getTaxAmount(),//---修改
          self::TOTAL_SHIPPING => $this->_salesEntity->getShippingAmount(),//---修改
          self::TOTAL_DISCOUNT => abs($this->_salesEntity->getDiscountAmount()),//---修改
      );
...
}
protected function _addRegularItem(Varien_Object $salesItem)
{
	if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
		$qty = (int) $salesItem->getQtyOrdered();
		$amount = (float) $salesItem->getPrice();// 修改
		// TODO: nominal item for order
	} else {
		$qty = (int) $salesItem->getTotalQty();
		$amount = $salesItem->isNominal() ? 0 : (float) $salesItem->getBaseCalculationPrice();
	}
	// workaround in case if item subtotal precision is not compatible with PayPal (.2)
	$subAggregatedLabel = '';
	if ($amount - round($amount, 2)) {
		$amount = $amount * $qty;
		$subAggregatedLabel = ' x' . $qty;
		$qty = 1;
	}

	// aggregate item price if item qty * price does not match row total
	if (($amount * $qty) != $salesItem->getRowTotal()) {// 修改
		$amount = (float) $salesItem->getRowTotal();// 修改
		$subAggregatedLabel = ' x' . $qty;
		$qty = 1;
	}

	return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
}
 这样改过后,跳转到paypal付款界面已经实现了是当前的货币,也可以正常付款,但是付款成功后,上面那个ipn验证不能通过,到后台去看订单状态,发现是Suspected Fraud,是不能进行后续的操作的,如果解决这个问题,看下面 app\core\Mage\Sales\Model\Order\Payment.php
protected function _isCaptureFinal($amountToCapture)
    {
        $amountToCapture = $this->_formatAmount($amountToCapture, true);
        $orderGrandTotal = $this->_formatAmount($this->getOrder()->getGrandTotal(), true);//---修改
        if ($orderGrandTotal == $this->_formatAmount($this->getAmountPaid(), true) + $amountToCapture) {//---修改
            if (false !== $this->getShouldCloseParentTransaction()) {
                $this->setShouldCloseParentTransaction(true);
            }
            return true;
        }
        return false;
    }
protected function _isSameCurrency()
{
    return !$this->getCurrencyCode() || $this->getCurrencyCode() == $this->getOrder()->getOrderCurrencyCode();// 修改
}
 现在就可以正常付款了

转载于:https://my.oschina.net/liufeng815/blog/353486

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值