最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to predefine subscription prices and trial period? - Stack Overflow

programmeradmin0浏览0评论

I am creating subscriptions for each new customer with an initial 1-month trial.

// Create subscription
SubscriptionCreateOptions options = new()
{
    Customer = customerId,
    Items = [],
    TrialEnd = DateTime.UtcNow.AddMonths(1)
};

// Add subscription items
foreach (string price in Settings.ParsePriceIds())
    options.Items.Add(new() { Price = price });

// Create subscription
var service = new SubscriptionService();
await service.CreateAsync(options);

The documentation for TrailEnd states:

If set, trial_end will override the default trial period of the plan the customer is being subscribed to.

My question is: How can I specify a plan that specifies a trial period, as mentioned in the documentation, and then reference that plan when creating a subscription?

In the code above, ParsePriceId() parses any number of price IDs from the configuration file and adds them to the subscription. But if I could define a plan within Stripe that specifies all pricing and any trials, that seems like it would be easier.

I am creating subscriptions for each new customer with an initial 1-month trial.

// Create subscription
SubscriptionCreateOptions options = new()
{
    Customer = customerId,
    Items = [],
    TrialEnd = DateTime.UtcNow.AddMonths(1)
};

// Add subscription items
foreach (string price in Settings.ParsePriceIds())
    options.Items.Add(new() { Price = price });

// Create subscription
var service = new SubscriptionService();
await service.CreateAsync(options);

The documentation for TrailEnd states:

If set, trial_end will override the default trial period of the plan the customer is being subscribed to.

My question is: How can I specify a plan that specifies a trial period, as mentioned in the documentation, and then reference that plan when creating a subscription?

In the code above, ParsePriceId() parses any number of price IDs from the configuration file and adds them to the subscription. But if I could define a plan within Stripe that specifies all pricing and any trials, that seems like it would be easier.

Share Improve this question edited Nov 19, 2024 at 22:56 Jonathan Wood asked Nov 19, 2024 at 22:30 Jonathan WoodJonathan Wood 67.4k82 gold badges303 silver badges529 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Specifying a trial on a Plan is a legacy feature and is not recommended. It's mentioned in the documentation for people using a legacy approach, but you should not build something new that sets a trial period on a Plan.

Indeed, Plans themselves are legacy and have been replaced by Prices, as mentioned in Stripe's documentation:

You can now model subscriptions more flexibly using the Prices API. It replaces the Plans API and is backwards compatible to simplify your migration.

That said, it is still technically possible to create a Plan and specify trial_period_days, but again, this is not recommended.

发布评论

评论列表(0)

  1. 暂无评论