我正在使用带有.NET Core的Stripe Payment,并且想要在用户的仪表板上显示该用户的所有订阅,我已经关注了一些Stripe Docs,要么我不明白,要么找不到我需要的东西。这是我在这里的Stripe Docs上引用的链接
我认为,这是您需要执行的操作,以便通过Stripe的电子邮件检索客户的所有订阅。
步骤1.创建此方法,该方法接受电子邮件作为参数并返回所请求用户的订阅。
public async Task<List<Subscription>> GetSubscriptionsByEmail(string customerEmail)
{
var customerService = new CustomerService();
var customerOptions = new CustomerListOptions()
{
Email = customerEmail
};
var customers = await customerService.ListAsync(customerOptions);
var customer = customers.FirstOrDefault();
//Check if customer exists with the given Email.
if (customer == null)
{
throw new Exception(message: $"No customer exists with Email = {customerEmail}.");
}
return customer.Subscriptions.Data.ToList();
}
步骤2:从任何需要的地方调用在步骤1中创建的方法。
List<Subscription> subscriptions = await GetSubscriptionsByEmail("CUSTOMER_EMAIL");
如果给定CUSTOMER_EMAIL的客户存在,则您将获得订阅列表。
注意:我正在考虑您已经设置 StripeConfiguration.ApiKey=YOUR_STRIPE_KEY.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句