2017-10-20 61 views
0

我正在將PayPal集成到我的網站,但是我已經到了要求我將ID傳回給客戶端的地步。我不知道如何做到這一點。任何幫助都會很棒。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

可以使用json_decode()功能(function docs)到JSON信息成多維數組進行解碼。


下面的腳本將根據需要回聲出ID(提供$response是從PayPal交易的JSON編碼的響應):

$data = json_decode($response, true); 
echo $data['id']; 
+0

是的,我得到那個,但我怎麼傳遞迴客戶端,以便它可以用嗎? – Hodds

0

我的工作了,而其以下。

$response1 = json_decode($response); 
$payment_id = $response1->id; 
$payment_id = print_r($payment_id, true); 

print ("{ 
    \"id\": \"$payment_id\" 
}"); 
相關問題