Class StripeSubscriptionApiClient
Recurring billing run by the provider: starting a subscription, letting the customer manage it, and reading where it stands.
public class StripeSubscriptionApiClient : IPaymentSubscriptionClient
- Inheritance
-
StripeSubscriptionApiClient
- Implements
- Inherited Members
Remarks
The provider owns the cycle — renewals, retries, invoices, proration — and reports changes by webhook. A caller keeps a copy of what it needs to decide on access and refreshes it from GetSubscriptionAsync(string, CancellationToken) when an event arrives, rather than trusting the order events arrive in.
Both pages are hosted by the provider, so no card reaches the caller.
Constructors
StripeSubscriptionApiClient(IStripeClient, ILogger<StripeSubscriptionApiClient>)
Recurring billing run by the provider: starting a subscription, letting the customer manage it, and reading where it stands.
public StripeSubscriptionApiClient(IStripeClient client, ILogger<StripeSubscriptionApiClient> logger)
Parameters
clientIStripeClientloggerILogger<StripeSubscriptionApiClient>
Remarks
The provider owns the cycle — renewals, retries, invoices, proration — and reports changes by webhook. A caller keeps a copy of what it needs to decide on access and refreshes it from GetSubscriptionAsync(string, CancellationToken) when an event arrives, rather than trusting the order events arrive in.
Both pages are hosted by the provider, so no card reaches the caller.
Methods
CancelSubscriptionAsync(string, CancellationToken)
Ends a subscription at the end of the period already paid for; it renews no more.
public Task<IResult<PaymentSubscriptionDTO>> CancelSubscriptionAsync(string subscriptionId, CancellationToken cancellationToken = default)
Parameters
subscriptionIdstringThe provider's identifier for it.
cancellationTokenCancellationTokenCancels the call.
Returns
CreateCheckoutPageAsync(SubscriptionCheckoutRequest, CancellationToken)
A provider-hosted page that starts a subscription, and the address to send the customer to.
public Task<IResult<string>> CreateCheckoutPageAsync(SubscriptionCheckoutRequest request, CancellationToken cancellationToken = default)
Parameters
requestSubscriptionCheckoutRequestWho pays, for which price, and where to return to.
cancellationTokenCancellationTokenCancels the call.
Returns
Remarks
The subscription is reported by a webhook rather than by the return address, which the customer may never reach.
CreateManagementPageAsync(string, string, CancellationToken)
A provider-hosted page where the customer changes their payment method, reads their invoices and changes or cancels their subscriptions, and the address to send them to.
public Task<IResult<string>> CreateManagementPageAsync(string customerId, string returnUrl, CancellationToken cancellationToken = default)
Parameters
customerIdstringWhose subscriptions.
returnUrlstringWhere the customer returns when they are done.
cancellationTokenCancellationTokenCancels the call.
Returns
CreateSubscriptionAsync(SubscriptionRequest, CancellationToken)
Starts a subscription charged to a payment method the customer already saved — no provider page.
public Task<IResult<PaymentSubscriptionStartDTO>> CreateSubscriptionAsync(SubscriptionRequest request, CancellationToken cancellationToken = default)
Parameters
requestSubscriptionRequestWho pays, for which price, from which saved method.
cancellationTokenCancellationTokenCancels the call.
Returns
Remarks
The first invoice is charged at once. A card that wants its owner to confirm leaves the subscription incomplete, with a client secret for the caller's own page to confirm with; the outcome then arrives by webhook like every later one.
GetSubscriptionAsync(string, CancellationToken)
A subscription as the provider holds it now.
public Task<IResult<PaymentSubscriptionDTO>> GetSubscriptionAsync(string subscriptionId, CancellationToken cancellationToken = default)
Parameters
subscriptionIdstringThe provider's identifier for it.
cancellationTokenCancellationTokenCancels the call.
Returns
ResumeSubscriptionAsync(string, CancellationToken)
Undoes CancelSubscriptionAsync(string, CancellationToken) while the period is still running: it renews again.
public Task<IResult<PaymentSubscriptionDTO>> ResumeSubscriptionAsync(string subscriptionId, CancellationToken cancellationToken = default)
Parameters
subscriptionIdstringThe provider's identifier for it.
cancellationTokenCancellationTokenCancels the call.
Returns
SetItemQuantityAsync(string, string, long, string?, CancellationToken)
Sets how many units of a price a subscription is charged for — the seats of a per-seat price — adding the price when the subscription does not carry it yet and taking it off at zero.
public Task<IResult<PaymentSubscriptionDTO>> SetItemQuantityAsync(string subscriptionId, string priceLookupKey, long quantity, string? idempotencyKey = null, CancellationToken cancellationToken = default)
Parameters
subscriptionIdstringThe provider's identifier for the subscription.
priceLookupKeystringThe lookup key of the price whose quantity is set.
quantitylongThe new quantity; zero takes the price off the subscription.
idempotencyKeystringMakes a retried request apply once.
cancellationTokenCancellationTokenCancels the call.
Returns
Remarks
The quantity is absolute, never a difference, so a call repeated after a failure leaves the same count. The change is prorated over the period already running, and the subscription is returned as it stands afterwards.