![](/img/trans.png)
[英]Implement stripe subscriptions with .net framework 4.7.2 and not .net core
[英]How to retrieve all the Subscriptions of a customer by Email from Stripe in .NET Core
我正在使用帶有.NET 核心的 Stripe Payment 並希望在他的儀表板上顯示用戶的所有訂閱,我遵循了一些 Stripe 文檔,因為要么我沒有得到那個,要么我找不到我需要的東西。 這是我在 Stripe Docs Here上引用的鏈接
我認為,這是為了從 Stripe 檢索 Email 的客戶的所有訂閱而需要做的。
步驟 1.創建此方法,該方法接受 email 作為參數並返回所請求用戶的訂閱。
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.