首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento -使用PayPal在线退款

Magento -使用PayPal在线退款
EN

Stack Overflow用户
提问于 2015-05-21 21:26:55
回答 2查看 2.1K关注 0票数 1

目前我们有一个Magento版本。1.8.1.0已安装的PayPal网站付款标准选项已启用。然而,当我想在线退款时,它不会显示“退款”按钮,而只显示“离线退款”按钮。

是否真的可以使用PayPal标准创建在线退款?

EN

回答 2

Stack Overflow用户

发布于 2015-06-16 00:53:30

使用Paypal标准是不可能的,你必须重载paypal标准模型来实现refund方法,或者你可以安装一个模块。

票数 1
EN

Stack Overflow用户

发布于 2017-07-26 02:48:07

正如luigifab所说,这个功能不是Paypal模块的一部分--我已经为它实现了一个小插件,可以在这里看到:

https://gist.github.com/bubach/ed86611c634b401e5d66392cf32c2f6e

最重要的部分是这个类:

代码语言:javascript
复制
<?php
class Namespace_Modulename_Model_Paypal extends Mage_Paypal_Model_Standard
{

    protected $_canRefund               = true;
    protected $_canRefundInvoicePartial = true;
    protected $_canVoid                 = true;

    /**
     * https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/RefundTransaction_API_Operation_NVP/
     */
    public function tryRefund(Varien_Object $payment, $amount)
    {
        $transactionId = $payment->getLastTransId();

        if ($transactionId) {
            $order          = $payment->getOrder();
            $storeId        = $order->getStoreId();
            $refundType     = "Partial";
            $invoiceFee = $payment->getMethodInstance()->getInfoInstance()->getAdditionalInformation('invoice_fee');
            $remaining  = $order->getTotalInvoiced() - ($order->getTotalOfflineRefunded() + $order->getTotalOnlineRefunded()) - $invoiceFee;

            if (abs($remaining - $amount) < 0.00001) {
                $refundType = "Full";
            }

            $currencyCode   = $order->getBaseCurrencyCode();
            $invoiceId      = $order->getIncrementId();

            $params = array(
                "METHOD"        => "RefundTransaction",
                "VERSION"       => "72.0",
                "TRANSACTIONID" => $transactionId,
                "INVOICEID"     => $invoiceId,
                "REFUNDTYPE"    => $refundType,
                "AMT"           => $amount,
                "CURRENCYCODE"  => $currencyCode,
                "USER"          => Mage::getStoreConfig('paypal/wpp/api_username', $storeId),
                "PWD"           => Mage::getStoreConfig('paypal/wpp/api_password', $storeId),
                "SIGNATURE"     => Mage::getStoreConfig('paypal/wpp/api_signature', $storeId)
            );

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, "https://api-3t.paypal.com/nvp");
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,  http_build_query($params));

            $response = curl_exec($ch);

            if (curl_errno($ch)) {
                curl_close($ch);
                throw new Mage_Core_Exception('Impossible to issue a refund transaction because of cURL error.');
            } else  {
                curl_close($ch);

                $responseArray = array();
                parse_str($response, $responseArray); // Break the NVP string to an array

                if ($responseArray['ACK'] == "Success") {
                    return array(0, "Paypal refunded successfully");
                } else {
                    return array(-1, "Paypal refund failed!");
                }
            }
        } else {
            Mage::throwException(Mage::helper('paypal')->__('Impossible to issue a refund transaction because the capture transaction does not exist.'));
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30375154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档