沃梦达 / 编程问答 / php问题 / 正文

检索客户来源时的条带化响应

Stripe Response when Retrieving Customer Sources(检索客户来源时的条带化响应)

本文介绍了检索客户来源时的条带化响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过提供客户ID来检索特定客户的所有卡。根据the documentation,我期待得到以下响应:

StripeCollection JSON: {
  "object" => "list",
  "url" => "/v1/customers/cu_16jdAj2eZvKYlo2CbrCP4HRs/sources",
  "has_more" => false,
  "data" => [
    [0] => StripeCard JSON: {
      "id": "card_14bIFkou9GUI42eZvKYlo2Cs",
      "object": "card",
      "last4": "4242",
      "brand": "Visa",
      "funding": "credit",
      "exp_month": 11,
      "exp_year": 2018,
      "country": "US",
      "name": "callingsudhanshu@gmail.com",
      "address_line1": null,
      "address_line2": null,
      "address_city": null,
      "address_state": null,
      "address_zip": null,
      "address_country": null,
      "cvc_check": null,
      "address_line1_check": null,
      "address_zip_check": null,
      "tokenization_method": null,
      "dynamic_last4": null,
      "metadata": {
      },
      "customer": "cus_6Nb0wxYHigk2mX"
    }
    [1] => <StripeCard[...] ...>
    [2] => <StripeCard[...] ...>
  ]
}

这是我对斯利普提出的要求。正在尝试从$card_list中提取data(即,所有卡片的数组):

StripeStripe::setApiKey($this->stripe_sk);
$card_list = StripeCustomer::retrieve($customer_id)->sources->all(array(
    'object' => 'card'
));

// Return a list of all cards.
$card_list = $card_list->data;
return $card_list;

我想知道为什么来自$card_list的条带响应包含额外/意外数据。以下是我实际得到的信息:

array(1) {
  [0]=&gt;
  object(StripeCard)#292 (5) {
    ["_opts":protected]=&gt;
    object(StripeUtilRequestOptions)#294 (2) {
      ["headers"]=&gt;
      array(0) {
      }
      ["apiKey"]=&gt;
      string(32) "sk_test_d3..."
    }
    ["_values":protected]=&gt;
    array(23) {
      ["id"]=&gt;
      string(29) "card_16jLIwLBSNgilYpnoEiPhNhA"
      ["object"]=&gt;
      string(4) "card"
      ["last4"]=&gt;
      string(4) "4242"
      ["brand"]=&gt;
      string(4) "Visa"
      ["funding"]=&gt;
      string(6) "credit"
      ["exp_month"]=&gt;
      int(8)
      ["exp_year"]=&gt;
      int(2016)
      ["fingerprint"]=&gt;
      string(16) "T5RzXLIiXrF0nyqH"
      ["country"]=&gt;
      string(2) "US"
      ["name"]=&gt;
      NULL
      ["address_line1"]=&gt;
      NULL
      ["address_line2"]=&gt;
      NULL
      ["address_city"]=&gt;
      NULL
      ["address_state"]=&gt;
      NULL
      ["address_zip"]=&gt;
      NULL
      ["address_country"]=&gt;
      NULL
      ["cvc_check"]=&gt;
      string(4) "pass"
      ["address_line1_check"]=&gt;
      NULL
      ["address_zip_check"]=&gt;
      NULL
      ["tokenization_method"]=&gt;
      NULL
      ["dynamic_last4"]=&gt;
      NULL
      ["metadata"]=&gt;
      object(StripeAttachedObject)#261 (5) {
        ["_opts":protected]=&gt;
        object(StripeUtilRequestOptions)#294 (2) {
          ["headers"]=&gt;
          array(0) {
          }
          ["apiKey"]=&gt;
          string(32) "sk_test_d..."
        }
        ["_values":protected]=&gt;
        array(0) {
        }
        ["_unsavedValues":protected]=&gt;
        object(StripeUtilSet)#262 (1) {
          ["_elts":"StripeUtilSet":private]=&gt;
          array(0) {
          }
        }
        ["_transientValues":protected]=&gt;
        object(StripeUtilSet)#306 (1) {
          ["_elts":"StripeUtilSet":private]=&gt;
          array(0) {
          }
        }
        ["_retrieveOptions":protected]=&gt;
        array(0) {
        }
      }
      ["customer"]=&gt;
      string(18) "cus_6xCtshHPQiYSdI"
    }
    ["_unsavedValues":protected]=&gt;
    object(StripeUtilSet)#270 (1) {
      ["_elts":"StripeUtilSet":private]=&gt;
      array(0) {
      }
    }
    ["_transientValues":protected]=&gt;
    object(StripeUtilSet)#120 (1) {
      ["_elts":"StripeUtilSet":private]=&gt;
      array(0) {
      }
    }
    ["_retrieveOptions":protected]=&gt;
    array(0) {
    }
  }
}

希望有人能解释一下我在这里得到的回答的"扩展"版本。提前感谢!

api

几天前我遇到了这个问题,我已经设法使用json_encode()推荐答案解决了这个问题(我需要将其作为AJAX返回导出)。

$cards = StripeCustomer::retrieve($_SESSION['stripe_customer_id'])->sources->all(array("object" => "card"));
$list = json_encode($cards->data);
echo($list);

希望这能有所帮助。

btw:您的回复与var_dump()输出类似。

这篇关于检索客户来源时的条带化响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:检索客户来源时的条带化响应

基础教程推荐