Stripe API-C#/.NET列出所有客户的分页问题
这可能是一个简单的答案,因为我对C#和.NET缺乏经验。我有两个条纹测试帐户。TL:DR;我基本上是在寻找一个客户。所有的解决方案 源帐户包含所有客户、卡和费用数据 目标帐户具有由Stripe Support复制的卡和客户数据 我有一段代码,可以循环通过源帐户获取所有数据。然后,它使用从源帐户收集的客户/卡数据从目标帐户查找客户数据。然后,它将费用从源帐户重新创建到目标帐户 我能够使用源帐户中的信息成功地将前100笔费用复制到目标帐户中,但我最难获得其余的客户 这就是我到目前为止所做的:Stripe API-C#/.NET列出所有客户的分页问题,c#,.net,stripe.net,C#,.net,Stripe.net,这可能是一个简单的答案,因为我对C#和.NET缺乏经验。我有两个条纹测试帐户。TL:DR;我基本上是在寻找一个客户。所有的解决方案 源帐户包含所有客户、卡和费用数据 目标帐户具有由Stripe Support复制的卡和客户数据 我有一段代码,可以循环通过源帐户获取所有数据。然后,它使用从源帐户收集的客户/卡数据从目标帐户查找客户数据。然后,它将费用从源帐户重新创建到目标帐户 我能够使用源帐户中的信息成功地将前100笔费用复制到目标帐户中,但我最难获得其余的客户 这就是我到目前为止所做的: pub
public static void GenerateDestinationChargeData()
{
// code to get collection of customer data from destination account
StripeConfiguration.SetApiKey(destinationTestKey);
var customerService = new StripeCustomerService();
IEnumerable<StripeCustomer> customerItems = customerService.List(
new StripeCustomerListOptions()
{
Limit = 100,
//this is what I cannot figure out, eventually to get all of the customers from the destination account
StartingAfter = customerItems.LastOrDefault().Id
}
);
// loop through collection of customers from destination acct to fetch customer charge data from source account
foreach (var i in customerItems)
{
bool isError = false;
var liveChargeService = new StripeChargeService();
StripeConfiguration.SetApiKey(sourceTestKey);
StripeList<StripeCharge> chargeItems = new StripeList<StripeCharge>();
chargeItems = liveChargeService.List(
new StripeChargeListOptions()
{
Limit = 100,
CustomerId = i.Id
}
);
// loop through customer charge data from source and re-create charge data on destination Acct
foreach (var c in chargeItems.Data)
{
StripeConfiguration.SetApiKey(sourceTestKey);
var emailReceipt = "";
Dictionary<string, string> chargeMetaData = new Dictionary<string, string>();
var onBehalfOf = "";
var transferGroup = "";
var chargeDescription = "";
var chargeCaptured = "";
var chargeCurrency = "";
var chargeStatementDescriptor = "";
if (c.ReceiptEmail != null)
{
emailReceipt = c.ReceiptEmail;
}
if (c.Metadata != null)
{
chargeMetaData = c.Metadata;
}
if (c.OnBehalfOf != null)
{
onBehalfOf = c.OnBehalfOf.ToString();
}
if (c.TransferGroup != null)
{
transferGroup = c.TransferGroup;
}
if (c.Description != null)
{
chargeDescription = c.Description;
}
if (c.Captured != null)
{
chargeCaptured = c.Captured.ToString();
}
if (c.Currency != null)
{
chargeCurrency = c.Currency;
}
if (c.StatementDescriptor != null)
{
chargeStatementDescriptor = c.StatementDescriptor;
}
try
{
var chargeOptions = new StripeChargeCreateOptions();
chargeOptions.CustomerId = i.Id;
chargeOptions.ReceiptEmail = emailReceipt;
chargeOptions.Metadata = chargeMetaData;
chargeOptions.Description = chargeDescription;
chargeOptions.Capture = c.Captured;
chargeOptions.Currency = chargeCurrency;
chargeOptions.Amount = c.Amount;
chargeOptions.StatementDescriptor = chargeStatementDescriptor;
StripeChargeService chargeService = new StripeChargeService(destinationTestKey);
StripeCharge stripeCharge = chargeService.Create(chargeOptions);
}
catch (Exception ex)
{
Utility.NotifyDevAdminException("test", ex);
isError = true;
}
if (isError) continue;
}
}
}
public static void generated目的计费数据()
{
//从目标帐户获取客户数据集合的代码
StripeConfiguration.SetApiKey(destinationTestKey);
var customerService=new StripeCustomerService();
IEnumerable customerItems=customerService.List(
新的StripeCustomerListOptions()
{
限值=100,
//这是我无法理解的,最终从目的地帐户获得所有客户
StartingAfter=customerItems.LastOrDefault().Id
}
);
//循环从目标帐户收集客户,以从源帐户获取客户费用数据
foreach(客户项中的var i)
{
bool-isError=false;
var liveChargeService=new StripeChargeService();
SetApiKey(sourceTestKey);
StripeList chargeItems=新的StripeList();
chargeItems=liveChargeService.List(
新的StripeChargeListOptions()
{
限值=100,
CustomerId=i.Id
}
);
//从源循环查看客户费用数据,并在目标帐户上重新创建费用数据
foreach(chargeItems.Data中的var c)
{
SetApiKey(sourceTestKey);
var=”;
Dictionary chargeMetaData=新字典();
var onBehalfOf=“”;
var transferGroup=“”;
var chargeDescription=“”;
var=”;
var chargeCurrency=“”;
var chargeStatementDescriptor=“”;
如果(c.ReceiptEmail!=null)
{
emailReceipt=c.ReceiptEmail;
}
如果(c.Metadata!=null)
{
chargeMetaData=c.元数据;
}
如果(c.OnBehalfOf!=null)
{
onBehalfOf=c.onBehalfOf.ToString();
}
if(c.TransferGroup!=null)
{
transferGroup=c.transferGroup;
}
如果(c.Description!=null)
{
chargeDescription=c.描述;
}
如果(c.Captured!=null)
{
chargeCaptured=c.Captured.ToString();
}
如果(c.货币!=null)
{
chargeCurrency=c.货币;
}
if(c.StatementDescriptor!=null)
{
chargeStatementDescriptor=c.StatementDescriptor;
}
尝试
{
var chargeOptions=new StripeChargeCreateOptions();
chargeOptions.CustomerId=i.Id;
chargeOptions.ReceiptEmail=emailReceipt;
chargeOptions.Metadata=chargeMetaData;
chargeOptions.Description=chargeDescription;
chargeOptions.Capture=c.Capture;
chargeOptions.Currency=chargeCurrency;
费用选项。金额=c.金额;
chargeOptions.StatementDescriptor=chargeStatementDescriptor;
StripeChargeService chargeService=新的StripeChargeService(destinationTestKey);
StripeCharge StripeCharge=chargeService.Create(chargeOptions);
}
捕获(例外情况除外)
{
实用程序.NotifyDevAdminException(“测试”,ex);
isError=真;
}
如果(isError)继续;
}
}
}
非常感谢:)因为我们无法处理客户。使用当前的条带API,解决方案是设置一个空变量,并为其分配第一组100中的最后一个客户ID,然后从最后分配的值继续查询
var lastId = String.Empty;
if (String.IsNullOrEmpty(lastId))
{
StripeConfiguration.SetApiKey(sourceCustomerAccountAPIKey);
customerItems = customerService.List(
new StripeCustomerListOptions(){ Limit = 100 });
}
else
{
StripeConfiguration.SetApiKey(sourceCustomerAccountAPIKey);
customerItems = customerService.List(
new StripeCustomerListOptions() {
Limit = 100,
StartingAfter = lastId });
}
lastId = customerItems.LastOrDefault().Id;
这个解决方案非常简单,我觉得我在这个解决方案上花了很多时间。我将customerservice代码块包装在一个while循环中,将客户推到一个数组中,然后迭代该数组以最终重新创建费用。你能编辑答案吗,你是如何实现的?我也陷入了同样的困境problem@AmmarAhmed帖子已更新感谢您的帮助:)