【问题标题】:How to get the ID out of Braintree's JSON response?如何从 Braintree 的 JSON 响应中获取 ID?
【发布时间】:2018-11-12 18:07:24
【问题描述】:

我正在尝试使用 Braintree SDK 集成 PayPal Express Checkout。

到目前为止,我可以收取从客户端返回的 Nonce 并收到此响应。但是,我需要取出 ID 才能将其保存在表格中。

我的问题是如何解析 id??

Successful {#315
  +success: true
  -_returnObjectNames: array:1 [
    0 => "transaction"
  ]
  #_attributes: []
  +"transaction": Transaction {#324
    #_attributes: array:63 [
      "id" => "xxx"// How do I parse this out?
      "status" => "settling"
      "type" => "sale"
      "currencyIsoCode" => "USD"
      "amount" => "6.00"

保存这个 JSON 的变量是 $success。因此,我尝试了以下几种方法:

$success->transaction->id
$success->id

如果我执行$success->success,我得到true,如果我执行$success->transaction,我得到Transaction 对象。

【问题讨论】:

  • 试试这个 $res = json_decode($response, true); echo $response['success']['transaction']['id'];

标签: php json laravel-5 paypal braintree


【解决方案1】:

全面披露:我在 Braintree 工作。如果您还有其他问题,请随时联系 support.

如果运行$success->successreturns True$success->transaction返回Transaction对象,那么你应该可以使用query the transaction IDquery the transaction ID,我们也演示了这个in our developer documentation

$result = $gateway->transaction()->sale([
  'amount' => '10.00',
  'paymentMethodNonce' => nonceFromTheClient,
  'options' => [
    'submitForSettlement' => True
  ]
]);

if ($result->success) {
  // See $result->transaction for details
} else {
 // Handle errors
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-27
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 2018-08-27
    相关资源
    最近更新 更多