PayPal IPN货币和响应

3
我正在使用从此处找到的PayPal IPN脚本 http://coderzone.org/library/PHP-PayPal-Instant-Payment-Notification-IPN_1099.htm 我知道我可以向PayPal发送信息并获得响应。它说明我可以使用$_POST获得返回信息。我的问题是如何指定英镑货币?
另外,我想澄清一个小点。我是否正确地理解了这就是如何确认它是成功的呢?
    if ($_POST['payment_status'] == 'completed')
        // Received Payment!
        // $_POST['custom'] is order id and has been paid for.
    }
3个回答

0

可能有点晚了,抱歉,但以防万一 - 我目前使用 "currencyCode" => "AUD" 并且在沙盒中运行良好。

有一个完整的货币代码列表可在 PayPal 上找到。

对于您的情况,我猜应该是:

$p->add_field('currencyCode', 'GBP');

关于IPN本身的问题,看起来你已经在正确的轨道上了。这将取决于您收到的数据以及您是否对单个交易感兴趣(如果使用自适应付款),或者如果您在出错时将其全部反转。确定需要执行的操作的最简单方法是简单地显示或记录所有后置数据,以便您可以查看其构造方式。
您还需要设置脚本可被PayPal访问。然后,您将传递此脚本的完整URL到“notify_url”参数,并将其发送到PayPal。一旦支付完成,PayPal将向您的脚本发送大量信息,以便您可以处理它。
不幸的是,我不是PHP背景,因此无法为您提供所需的确切代码。还要注意,在进入生产环境之前,您需要研究很多安全问题。不确定您是否已经打算使用那个validateIPN函数进行此操作,但您需要确保您可以告诉它是否来自PayPal而不是恶意用户。一种方法是使用自定义属性传递值,并让PayPal将其传递回给您,但是最好使用API证书等。

如果您还没有这样做,看一下 PayPal 制作的示例应用程序可能是值得的,其中似乎有不少 PHP 应用程序。

如果您需要其他任何帮助,请告诉我。


0

使用这个,对我有效

$p->add_field('currency_code', 'GBP');

-1

你需要使用PayPal自适应支付,IPN无法帮助。

PayPal自适应支付

如果使用PayPal PHP库,则代码可能如下所示:

// Create an instance, you'll make all the necessary requests through this
        // object, if you digged through the code, you'll notice an AdaptivePaymentsProxy class
        // wich has in it all of the classes corresponding to every object mentioned on the
        // documentation of the API
        $ap = new AdaptivePayments();

        // Our request envelope
        $requestEnvelope = new RequestEnvelope();
        $requestEnvelope->detailLevel = 0;
        $requestEnvelope->errorLanguage = 'en_GB';

        // Our base amount, in other words the currency we want to convert to
        // other currency type. It's very straighforward, just have a public
        // prop. to hold de amount and the current code.
        $baseAmountList = new CurrencyList();
        $baseAmountList->currency = array( 'amount' => $this->amount, 'code' => 'GBP' );

        // Our target currency type. Given that I'm from Mexico I would like to
        // see it in mexican pesos. Again, just need to provide the code of the
        // currency. On the docs you'll have access to the complete list of codes
        $convertToCurrencyListUSD = new CurrencyCodeList();
        $convertToCurrencyListUSD->currencyCode = 'USD';

        // Now create a instance of the ConvertCurrencyRequest object, which is
        // the one necessary to handle this request.
        // This object takes as parameters the ones we previously created, which
        // are our base currency, our target currency, and the req. envelop
        $ccReq = new ConvertCurrencyRequest();
        $ccReq->baseAmountList = $baseAmountList;
        $ccReq->convertToCurrencyList = $convertToCurrencyListUSD;
        $ccReq->requestEnvelope = $requestEnvelope;

        // And finally we call the ConvertCurrency method on our AdaptivePayment object,
        // and assign whatever result we get to our variable
        $resultUSD = $ap->ConvertCurrency($ccReq);
        $convertToCurrencyListUSD->currencyCode = 'EUR';
        $resultEUR = $ap->ConvertCurrency($ccReq);

        // Given that our result should be a ConvertCurrencyResponse object, we can
        // look into its properties for further display/processing purposes
        $resultingCurrencyListUSD = $resultUSD->estimatedAmountTable->currencyConversionList;
        $resultingCurrencyListEUR = $resultEUR->estimatedAmountTable->currencyConversionList;

抱歉,您能解释一下为什么您推荐使用自适应支付,而其他人都推荐使用 IPN 吗? - Michael Clarke
我认为IPN不支持货币转换。 - Zdenek Machek
显然,如果我使用 $p->add_field('currency_code', 'GBP');它应该将货币设置为GBP。 - Michael Clarke
对于未来的读者 - IPN 是一个独立于自适应支付 API 的系统,您可以使用经典或 REST API 并从 PayPal 请求 IPN - 您不需要使用特定的 API 来使用 IPN。 - totallyNotLizards

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接