我正在努力将PayPal集成到我的网站,但是我已经达到要求我将ID传递回客户端的程度。我不知道该怎么做。任何帮助都会很棒。
这是我从PayPal服务器获得的最后一个JSON代码。正如我从服务器端代码那样做。
{
"id":"PAY-5VL741754E714161BLHUWCKY",
"intent":"sale",
"state":"created",
"payer":
{
"payment_method":"paypal"
},
"transactions":
[{
"amount":
{
"total":"4.00",
"currency":"USD",
"details":
{
"subtotal":"2.00",
"tax":"2.00",
"shipping":"1.00",
"shipping_discount":"-1.00"
}
},
"description":"The payment transaction description.",
"custom":"PlayerID",
"invoice_number":"merchant invoice",
"item_list":
{
"items":
[{
"name":"item 1",
"description":"item 1 description",
"price":"1.00",
"currency":"USD",
"tax":"1.00",
"quantity":1
},
{
"name":"item 2",
"description":"item 2 description",
"price":"1.00",
"currency":"USD",
"tax":"1.00",
"quantity":1
}]
},
"related_resources":
[]
}],
"create_time":"2017-10-20T02:36:27Z",
"links":
[{
"href":"h.t.t.p.s.:././.a.p.i...s.andbox.paypal.com/v1/payments/payment/PAY-5VL741754E714161BLHUWCKY",
"rel":"self",
"method":"GET"
},
{
"href":"h.t.t.p.s.:././.w.w.w...s.andbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3U757031AX945661J",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"h.t.t.p.s:././.a.p.i...s.a.ndbox.paypal.com/v1/payments/payment/PAY-5VL741754E714161BLHUWCKY/execute",
"rel":"execute",
"method":"POST"
}
]}
答案 0 :(得分:0)
您可以使用json_decode()
函数(function docs)将JSON信息解码为多维数组。
以下脚本将根据需要回显ID(假设$response
是来自PayPal事务的JSON编码响应):
$data = json_decode($response, true);
echo $data['id'];
答案 1 :(得分:0)
我把它解决了,以及以下内容。
$response1 = json_decode($response);
$payment_id = $response1->id;
$payment_id = print_r($payment_id, true);
print ("{
\"id\": \"$payment_id\"
}");