php 接口怎么响应,Stripe PHP API方法响应的结构是什么?
我正在進行Stripe集成,我對從
PHP API獲得的實際響應感到困惑.我開始相信API參考是準確的,并且響應將是每個方法所示的JSON字符串.我很快發現了顯著的差異.大多數情況下,JSON響應中缺少id字段.此外,響應似乎是一個字符串,一個對象,也許還有其他一些結構,所有這些都在同一時間.
這是我的調試代碼.我使用的是最新的Stripe PHP庫,版本為1.7.15.
function var_dump_ret($mixed=null)
{
ob_start();
var_dump($mixed);
$content=ob_get_contents();
ob_end_clean();
return($content);
}
$token=$_POST['stripeToken'];
$customer=Stripe_Customer::create(array(
"card"=>$token,
"plan"=>"agency")
);
$custVarDump=var_dump_ret($customer);
$cDecoded=json_decode($customer);
$Debug="Invidual attributes of JSON decoded customer object:"._EOL;
$Debug.="object:".$cDecoded->object._EOL;
$Debug.="created:".$cDecoded->created._EOL;
$Debug.="id:".$cDecoded->id._EOL;
$Debug.="livemode:".$cDecoded->livemode._EOL;
$Debug.="description:".$cDecoded->description._EOL;
$Debug.="active_card.object:".$cDecoded->active_card->object._EOL;
$Debug.="active_card.last4:".$cDecoded->active_card->last4._EOL;
$Debug.="active_card.type:".$cDecoded->active_card->type._EOL;
$Debug.="active_card.exp_month:".$cDecoded->active_card->exp_month._EOL;
$Debug.="active_card.exp_year:".$cDecoded->active_card->exp_year._EOL;
$Debug.="active_card.fingerprint:".$cDecoded->active_card->fingerprint._EOL;
$Debug.="active_card.country:".$cDecoded->active_card->country._EOL;
$Debug.="active_card.name:".$cDecoded->active_card->name._EOL;
$Debug.="active_card.address_line1:".$cDecoded->active_card->address_line1._EOL;
$Debug.="active_card.address_line2:".$cDecoded->active_card->address_line2._EOL;
$Debug.="active_card.address_city:".$cDecoded->active_card->address_city._EOL;
$Debug.="active_card.address_state:".$cDecoded->active_card->address_state._EOL;
$Debug.="active_card.address_zip:".$cDecoded->active_card->address_zip._EOL;
$Debug.="active_card.address_country:".$cDecoded->active_card->address_country._EOL;
$Debug.="active_card.cvc_check:".$cDecoded->active_card->cvc_check._EOL;
$Debug.="active_card.address_line1_check:".$cDecoded->active_card->address_line1_check._EOL;
$Debug.="active_card.address_zip_check:".$cDecoded->active_card->address_zip_check._EOL;
$Debug.="email:".$cDecoded->email._EOL;
$Debug.="delinquent:".$cDecoded->delinquent._EOL;
//$Debug.="subscription:".$cDecoded->subscription._EOL;
$Debug.="discount:".$cDecoded->discount._EOL;
$Debug.="account_balance:".$cDecoded->account_balance._EOL;
$Debug.="unaltered response from Stripe_Customer::create:"._EOL.$customer._EOL.
"var dump of response:"._EOL.$custVarDump._EOL.
"print_r of json_decode of response:"._EOL.print_r($cDecoded,true)._EOL;
file_put_contents(_LOGFILE,$Debug,FILE_APPEND);
以下是我的調試文件的內容,用于JSON解碼的客戶對象的invidual屬性.執行時,代碼發布了通知.
注意:未定義的屬性:第51行的stripe / subscription.php中的stdClass :: $id
另請注意,由于stdClass的致命錯誤,我必須注釋掉添加’subscription’到調試字符串的行.
object:customer
created:1365951909
id:
livemode:
description:
active_card.object:card
active_card.last4:4242
active_card.type:Visa
active_card.exp_month:7
active_card.exp_year:2013
active_card.fingerprint:WTXPLgKDCXyp9xpD
active_card.country:US
active_card.name:charlie
active_card.address_line1:
active_card.address_line2:
active_card.address_city:
active_card.address_state:
active_card.address_zip:
active_card.address_country:
active_card.cvc_check:pass
active_card.address_line1_check:
active_card.address_zip_check:
email:
delinquent:
discount:
account_balance:0
最值得注意的是客戶ID.它在JSON響應中不存在.但是,如某些Stripe示例程序中所示,可以使用$customer-> id訪問它.此外,var_dump輸出表明在我無法弄清楚的結構中存在更多的屬性.整個調試文件是在http://www.helioza.com/stripe/debug.txt.我只顯示了客戶創建方法,但我遇到了類似的發票問題,并且無法在Stripe_Invoice :: all或Stripe_Invoice ::即將發布的響應中的任何位置找到發票ID.
問題
1)Stripe_Customer :: create返回的值如何同時是字符串和對象?
2)在哪里可以找到描述API方法返回值的文檔,包括如何訪問每個屬性?
總結
以上是生活随笔為你收集整理的php 接口怎么响应,Stripe PHP API方法响应的结构是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言 字符串转结构体,字符串指针转化为
- 下一篇: php注入教程,php注入点构造代码实例