我有這個:
const customers = await stripe.customers.list({
email: '[email protected]',
});
var customerID = customers.data[0].id;
const subscriptions = await stripe.subscriptions.list({
customer: customerID
});
console.log(subscriptions)
console.log(subscriptions.data[0].status)
它應該做的是檢索customerid訂閱者的 ,然后我嘗試轉到下一個函式并status根據客戶 ID檢索訂閱的 。這不起作用。它說 2 件事。
它只是輸出:
{ 物件:'串列',資料:[],has_more:假,網址:'/v1/subscriptions'}
(node:30746) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'status' of undefined
我知道這是錯誤的,因為當我像這樣記錄它時:
console.log(subscriptions)
它回傳 30 多行訂閱者資料,包括活動狀態。像這樣:
{
id: 'sub_id',
object: 'subscription',
application_fee_percent: null,
automatic_tax: [Object],
billing_cycle_anchor: 1617410065,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
collection_method: 'charge_automatically',
created: 1617410065,
current_period_end: 1635899665,
current_period_start: 1633221265,
customer: 'cus_JEQIfxhiRu7qJh',
days_until_due: null,
default_payment_method: 'pm_1IbxRUIPT89VeZtCxyEA8SMu',
default_source: null,
default_tax_rates: [],
discount: null,
ended_at: null,
items: [Object],
latest_invoice: 'in_1JgIfuIPT89VeZtC2jsKCHRp',
livemode: false,
metadata: {},
next_pending_invoice_item_invoice: null,
pause_collection: null,
payment_settings: [Object],
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: [Object],
quantity: 1,
schedule: null,
start_date: 1617410065,
status: 'active',
tax_percent: null,
transfer_data: null,
trial_end: null,
trial_start: null
},
我如何從中訪問狀態或任何其他引數?
編輯 以使其更清楚,我將展示這一點:
當我這樣做時:
const subscriptions = await stripe.subscriptions.list({
});
console.log(subscriptions)
它回傳整個大輸出(上面顯示了一個)。
當我這樣做時:
const subscriptions = await stripe.subscriptions.list({
customer: customerID
});
console.log(subscriptions)
它只顯示這個:
{ object: 'list', data: [], has_more: false, url: '/v1/subscriptions' }
and when i try to log the subscription status of the one that compares the customerid, i get it saying that status is not a part of the returned data.
uj5u.com熱心網友回復:
因此,如果您發布的輸出是從條帶 API 獲得的所有輸出,那么訪問狀態欄位的正確方法就是使用
console.log(subscriptions[0].status);
uj5u.com熱心網友回復:
該錯誤訊息與您所說的輸出一致。如果串列呼叫不回傳任何訂閱,subscriptions.data[0]則將是未定義的,因此沒有要獲取的物件status。因為沒有customer過濾器的呼叫會正確回傳訂閱,所以只要您傳入的客戶具有尚未取消的subscriptions.list訂閱(默認情況下僅回傳未取消的訂閱 [1]),帶有過濾器的呼叫就應該有效。
聽起來這可能是因為您正在過濾的特定客戶 ID。如果您嘗試列出沒有過濾器的訂閱時看到的客戶 ID 之一(例如cus_JEQIfxhiRu7qJh),您的代碼是否有效?對于您在第一個示例中列出的客戶,我會在您的儀表板中仔細檢查該客戶的頁面,以查看他們是否有應由該串列呼叫回傳的未取消訂閱。
[1] https://stripe.com/docs/api/subscriptions/list
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/339490.html
標籤:javascript node.js stripe-payments
上一篇:如何計算node.js中的值
