首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析Paypal REST响应

解析Paypal REST响应
EN

Stack Overflow用户
提问于 2013-10-10 21:40:03
回答 1查看 1.4K关注 0票数 0

我有json_decoded我的paypal响应,并得到了以下内容:

代码语言:javascript
复制
["body"]=> object(stdClass)#4 (8) { 

    ["id"]=> string(28) "PAY-66D616332R6551639KJLSMVQ" 
    ["create_time"]=> string(20) "2013-10-10T22:12:38Z" 
    ["update_time"]=> string(20) "2013-10-10T22:12:39Z" 
    ["state"]=> string(7) "created" 
    ["intent"]=> string(4) "sale" 
    ["payer"]=> object(stdClass)#5 (2) { 
        ["payment_method"]=> string(6) "paypal" 
        ["payer_info"]=> object(stdClass)#6 (0) {} 
    } 
    ["transactions"]=> array(1) { 
        [0]=> object(stdClass)#7 (3) { 
            ["amount"]=> object(stdClass)#8 (3) { 
                ["total"]=> string(6) "500.85" 
                ["currency"]=> string(3) "USD" 
                ["details"]=> object(stdClass)#9 (2) { 
                    ["subtotal"]=> string(6) "460.90" 
                    ["shipping"]=> string(5) "39.95" 
                } 
            } 
            ["description"]=> string(43) "Mike and Maureen Photography - Order ID #10" 
            ["item_list"]=> object(stdClass)#10 (1) { 
                ["items"]=> array(2) { 
                    [0]=> object(stdClass)#11 (5) { 
                        ["name"]=> string(48) "The Bean-8" x 10" - floating frame - black frame" 
                        ["sku"]=> string(7) "20 - 13" 
                        ["price"]=> string(6) "160.95" 
                        ["currency"]=> string(3) "USD" 
                        ["quantity"]=> string(1) "1" 
                    } 
                    [1]=> object(stdClass)#12 (5) { 
                        ["name"]=> string(62) "40 Steps and a View-36" x 48" - 0.75" thin gallery wrap canvas" 
                        ["sku"]=> string(5) "7 - 6" 
                        ["price"]=> string(6) "299.95" 
                        ["currency"]=> string(3) "USD" 
                        ["quantity"]=> string(1) "1" 
                    } 
                } 
            } 
        } 
    } 
    ["links"]=> array(3) { 
        [0]=> object(stdClass)#13 (3) { 
            ["href"]=> string(79) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66D616332R6551639KJLSMVQ" 
            ["rel"]=> string(4) "self" 
            ["method"]=> string(3) "GET" 
        } 
        [1]=> object(stdClass)#14 (3) { 
            ["href"]=> string(94) "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1XB37931V5368954G" 
            ["rel"]=> string(12) "approval_url" 
            ["method"]=> string(8) "REDIRECT" 
        } 
        [2]=> object(stdClass)#15 (3) { 
            ["href"]=> string(87) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66D616332R6551639KJLSMVQ/execute" 
            ["rel"]=> string(7) "execute" 
            ["method"]=> string(4) "POST" 
        } 
    } 
} 

我试图检查'state‘的值,但我似乎不知道如何引用该值。我尝试过:($result是数组所在的变量)

代码语言:javascript
复制
$result['body']['state']
$result['state']
$body['state']

这些工作都没有,所以有人能告诉我如何在那里的混乱中引用关键的“状态”吗?我通常对PHP很在行,但出于某种原因,我无法理解这个问题。

谢谢你的帮助。

编辑

我已经格式化了响应,所以更容易准备,但我仍然坚持选择1 href值。如果我以前面的示例为基础,我将使用

$result‘’body‘->链接,但我如何通过该链接到1中的特定href

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-10 21:50:43

格式化没有帮助,但看起来$result['body']->state将为您提供您要寻找的东西。

您的第一次尝试$result['body']['state']最接近,但是$result['body']是一个对象,因此您需要使用->来访问它的属性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19306725

复制
相关文章

相似问题

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