打印PayPal回复

时间:2015-07-22 11:22:10

标签: api paypal

我正在编写此代码以获得响应

$PayPalResult = $PayPal->GetTransactionDetails($PayPalRequestData);
echo '<pre />';
print_r($PayPalResult);

使用 print_r 命令后,我得到以下结果。

Array
(
[RECEIVERBUSINESS] => rdaa.org
[RECEIVEREMAIL] => rdudeja.org
[RECEIVERID] => RS2THGDSKDKG6
[EMAIL] => bEGIN@denim.com
[PAYERID] => RPXDF4PDMRQD6
[PAYERSTATUS] => verified
[COUNTRYCODE] => US
[SHIPTONAME] => Kamal  Sudeja
[PROTECTIONELIGIBILITY] => Eligible
[PROTECTIONELIGIBILITYTYPE] => ItemNotReceivedEligible,UnauthorizedPaymentEligible
[L_NAME0] => denim
[L_NUMBER0] => 1234
[L_QTY0] => 1
[L_TAXAMT0] => 0.00
[L_CURRENCYCODE0] => USD
[L_TAXABLE0] => false
[ERRORS] => Array
    (
    )

[ORDERITEMS] => Array
    (
        [0] => Array
            (
                [L_NAME] => denim
                [L_DESC] => 
                [L_NUMBER] => 1234
                [L_QTY] => 1
                [L_AMT] => 
                [L_TAXAMT] => 0.00
                [L_EBAYITEMTXNID] => 
                [L_EBAYITEMORDERID] => 
            )

    )   

我正在编写以下代码以将其打印为关联数组。

foreach($PayPalResult as $k=>$v)
{
   echo $k.'='.$v.'<br>';
} 

但它显示错误

  

&#34;数组到字符串转换&#34;

帮助我,我想要打印回复。

1 个答案:

答案 0 :(得分:0)

您不需要循环$ PayPalResult。它包含的参数已经解析并可供您使用,因此您可以使用$ PayPalResult [&#39; EMAIL&#39;]来提取该值,例如。

您可能想要循环的唯一内容是$ PayPalResult [&#39; ORDERITEMS&#39;]或$ PayPalResult [&#39; ERRORS&#39;]这些数组本身就像@Daniel A. White在他的评论中提到。

在这种情况下,它会是这样的......

foreach($PayPalResult['ORDERITEMS'] as $OrderItem)
{
    $ItemName = $OrderItem['L_NAME'];   
}