如何通过电子邮件从 .NET Core 中的 Stripe 检索客户的所有订阅

kc-*_*dev 3 c# stripe-payments asp.net-core

我正在使用带有.NET Core 的Stripe Payment并希望在他的仪表板上显示用户的所有订阅,我已经关注了一些 Stripe 文档,要么我没有得到它要么我找不到我需要的东西。这是我在 Stripe Docs Here上引用的链接

Cha*_*mar 6

我认为,这就是您需要做的,以便通过来自 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();
        }
Run Code Online (Sandbox Code Playgroud)

第 2 步:从您需要的任何位置调用在第 1 步中创建的方法。

List<Subscription> subscriptions = await GetSubscriptionsByEmail("CUSTOMER_EMAIL");
Run Code Online (Sandbox Code Playgroud)

如果给定 CUSTOMER_EMAIL 的客户存在,您将获得订阅列表

注意:我正在考虑您已经设置 StripeConfiguration.ApiKey=YOUR_STRIPE_KEY.