PHP | Stripe API-检查客户是否附有卡
我正在尝试为我的网站设置条带API,但遇到了一个问题。我需要检查客户是否有信用卡,以便处理订阅计划 在他们的文档中,我似乎找不到任何与此相关的内容: 客户的输出如下所示:PHP | Stripe API-检查客户是否附有卡,php,api,stripe-payments,Php,Api,Stripe Payments,我正在尝试为我的网站设置条带API,但遇到了一个问题。我需要检查客户是否有信用卡,以便处理订阅计划 在他们的文档中,我似乎找不到任何与此相关的内容: 客户的输出如下所示: Stripe\Customer JSON: { "id": "CUSTOMER_ID", "object": "customer", "account_balance": 0, "created": 1474620297, "currency": "dkk", "default_source": nul
Stripe\Customer JSON: {
"id": "CUSTOMER_ID",
"object": "customer",
"account_balance": 0,
"created": 1474620297,
"currency": "dkk",
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": "",
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/CUSTOMER_ID/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/CUSTOMER_ID/subscriptions"
}
}
$customer = \Stripe\Customer::retrieve($customerID);
$cardID = $customer->default_source;
if(isset($cardID)){
echo $cardID;
} else {
echo "No card";
//Code for entering card info..
}
那么,如何检查客户是否有信用卡?尝试以下方法:
Stripe\Customer JSON: {
"id": "CUSTOMER_ID",
"object": "customer",
"account_balance": 0,
"created": 1474620297,
"currency": "dkk",
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": "",
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/CUSTOMER_ID/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/CUSTOMER_ID/subscriptions"
}
}
$customer = \Stripe\Customer::retrieve($customerID);
$cardID = $customer->default_source;
if(isset($cardID)){
echo $cardID;
} else {
echo "No card";
//Code for entering card info..
}
在那里你会得到卡片id,然后你可以简单地检查你是否得到了什么。若顾客有一张卡,你们就可以得到卡的id,若顾客并没有卡,你们就什么也得不到
$cards = Customer::retrieve(STRIPE_CUSTOMER_ID)->sources->all([
'object' => 'card'
])->data;
它将返回一个卡对象数组,如果没有卡,则返回一个空数组
if($cards == []) {
// no cards exist for user
}
我如何检查它是否有什么问题?