【问题标题】:Stripe having trouble extracting the json card idStripe 无法提取 json 卡 ID
【发布时间】:2020-06-22 01:03:08
【问题描述】:

使用 Stripe php,我正在使用下面的代码创建一个新的源代码。

  • 然后,当我显示 $response_all 时,它看起来像不错的 json,例如:

{id: "card_xxxxxxxxxx", object: "card", address_city: null, address_country: null, address_line1: null, ...}等......

但是,当我尝试仅使用 $response_id = $response.id;

然后 json 有一个 TEXT 前缀,如 “条纹\卡片 JSON:{ “id”:“card_xxxxxxxxxx”等

问:如何在不获取文本前缀的情况下提取 Card id?

$stripe_customer = $_POST['stripe_customer'];


$stripe = new \Stripe\StripeClient(
'sk_test_xxxxxxxxx'
);

$response = $stripe->customers->createSource(
$stripe_customer,
['source' => $token]
); 


$response_all =  $response;

$response_id = $response.id;

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    您需要在 PHP 中使用箭头符号来获取对象属性:

    $response_id = $response->id
    

    . 是 PHP 中的字符串连接,这意味着在您的代码中,您可能会看到打印的整个 JSON 对象在末尾添加了字符串 id

    【讨论】:

      猜你喜欢
      • 2019-03-16
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 2020-04-23
      • 1970-01-01
      • 2021-08-23
      • 2021-12-16
      相关资源
      最近更新 更多