我正在向Python Stripe API提出所有争议。我当前用于检索所有争议的代码如下。
import stripe
stripe.api_key = "12345"
disputes = stripe.Dispute.list(limit=100)
但是,我只想请求包含status
中的needs_response
的争议。在Stripe API中是否有特定的方法来请求这些争议?
答案 0 :(得分:0)
您最好的选择是从API检索disputes
的完整列表后,在本地进行过滤。使用auto-pagination,这可以很简单:
disputes = stripe.Dispute.list(limit=3)
for dispute in disputes.auto_paging_iter():
if (dispute.status == 'needs_response'):
# Do something with the dispute
作为概括,如果不在arguments list for that resource中,则只想在本地进行任何进一步的过滤。
答案 1 :(得分:0)
import stripe
stripe.api_key = get_stripe()
from datetime import datetime, timedelta
import delorean
dt = datetime.utcnow()
lte = delorean.Delorean(dt, timezone="UTC").epoch
a = datetime.now() + timedelta(days=-2)
gte = delorean.Delorean(a, timezone="UTC").epoch
chuck = stripe.Dispute.list(created={'gte':int(gte),'lte':int(lte)})
print "NUMBER OF DISPUTES:", len(chuck)
ch_lst = []
id_lst = []
name_lst = []
am_lst = []
f_lst = []
for d in chuck.auto_paging_iter():
for d in chuck.auto_paging_iter():
if (d['status'] == 'needs_response' or d['status'] == 'warning_needs_response'):
c = stripe.Charge.retrieve(str(d['charge']))
ch_lst.append(str(d['charge']))
id_lst.append(str(d['id']))
am_lst.append(str(c['amount']))
name_lst.append(str(c['source']['name']))
f_lst.append(str(c['source']['fingerprint']))