PayPal自适应支付货币API的PHP示例

PayPal自适应支付货币API的PHP示例,php,paypal,paypal-adaptive-payments,Php,Paypal,Paypal Adaptive Payments,我一直在想新的PayPal自适应支付API,特别是ConvertCurrency功能。有人在PHP中有过这样的运气吗 文档:转换为dif非常容易。货币使用贝宝的自适应支付SDK。假设你有必要的信息。(API用户名/passwd等)要向API发出请求,可以按以下方式执行: <?php //First we need to include the class file of the Adaptive Payments include 'AdaptivePayments.php'; // C

我一直在想新的PayPal自适应支付API,特别是ConvertCurrency功能。有人在PHP中有过这样的运气吗


文档:

转换为dif非常容易。货币使用贝宝的自适应支付SDK。假设你有必要的信息。(API用户名/passwd等)要向API发出请求,可以按以下方式执行:

<?php

//First we need to include the class file of the Adaptive Payments
include 'AdaptivePayments.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_US';

// 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' => 15, 'code' => 'USD' );

// 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
$convertToCurrencyList = new CurrencyCodeList();
$convertToCurrencyList->currencyCode = 'MXN';

// 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 = $convertToCurrencyList;
$ccReq->requestEnvelope = $requestEnvelope;

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

// Given that our result should be a ConvertCurrencyResponse object, we can
// look into its properties for further display/processing purposes
$resultingCurrencyList = $result->estimatedAmountTable->currencyConversionList;
$baseAmount = $resultingCurrencyList->baseAmount->amount;
$baseAmountCode = $resultingCurrencyList->baseAmount->code;
$convertedAmount = $resultingCurrencyList->currencyList->currency->amount;
$convertedAmountCode = $resultingCurrencyList->currencyList->currency->code;

echo '<br /> $' . $baseAmount . ' ' . $baseAmountCode . ' is $' . $convertedAmount . ' ' . $convertedAmountCode;

// And here just for the sake of knowing how we get the result from Paypal's API
echo '<pre>';
print_r($result);
echo '</pre>';

如您所见,使用ConvertCurrency API非常简单,只需下载SDK并开始使用它;)

看起来是您列出的文档的正式版本。(然而,据我所知,它们是相同的)谢谢你的精彩回答。我只是想知道如何获得多种货币的结果。我尝试了类似$convertToCurrencyList->currencyCode[]='MXN'$convertToCurrencyList->currencyCode[]=“日元”;但它说试图获得非对象的属性。谢谢
$15 USD is $159.75 MXN

ConvertCurrencyResponse Object
(
    [responseEnvelope] => ResponseEnvelope Object
        (
            [timestamp] => 2010-04-20T13:27:40.278-07:00
            [ack] => Success
            [correlationId] => b940006680f6a
            [build] => 1238639
        )

    [estimatedAmountTable] => stdClass Object
        (
            [currencyConversionList] => CurrencyConversionList Object
                (
                    [baseAmount] => stdClass Object
                        (
                            [code] => USD
                            [amount] => 15
                        )

                    [currencyList] => CurrencyList Object
                        (
                            [currency] => currency Object
                                (
                                    [code] => MXN
                                    [amount] => 159.75
                                )

                        )

                )

        )

)