我正在尝试获取与转移相关的所有费用 ID。
var json = new StreamReader(context.Request.InputStream).ReadToEnd();
var stripeEvent = StripeEventUtility.ParseEvent(json);
StripeTransfer stripeTransfer;
switch (stripeEvent.Type)
{
case "transfer.created":
stripeTransfer = Stripe.Mapper<StripeTransfer>.MapFromJson(stripeEvent.Data.Object.ToString());
var transferId = stripeTransfer.Id;
stripeTransfer = _stripeManager.GetTransfer(transferId);
foreach (var charge in stripeEvent.Data.Object["transactions"])
{
}
_stripeManager.ProcessTransfer(stripeTransfer);
break;
在 Visual Studio 的即时窗口中,stripeEvent.Data.Object["transactions"]
显示我想要的数据,所以我知道 json 被正确地吸收了。这些交易是收费的集合,它们与我的 .net StripeCharge 对象匹配。我无法弄清楚如何遍历事务......我真正需要的是每个事务的 ID。希望将“事务”视为 C# IEnumerable 对象。
(有问题的 json 链接在这篇文章的顶部)如果需要更多信息,请告诉我。
我发现具体的项目在下面,["transactions"]["data"][0]["id"]
但可能不止一个,仍在研究如何将它们取出并施放它们……我想我已经接近了,但似乎应该有一种更优雅的做事方式它。
编辑,
谢谢安德鲁,所以即使我有所有的收费数据,它也是传入的数据。所以我要做的是使用该事件来获取 id,然后调用以从我自己的一端获取费用对象,以防止任何事件欺骗。所以这意味着我现在不必担心演员阵容。这是我的解决方案,如果有更好的方法,请随时提出建议
for (int i = 0; i < Int32.Parse(stripeEvent.Data.Object["transactions"]["total_count"].ToString()); i++)
{
string chargeId = stripeEvent.Data.Object["transactions"]["data"][i]["id"].ToString();
// do stuff with it
}