Class StripeCustomerApiClient
The paying side: who is charged, and the payment method they saved.
public class StripeCustomerApiClient : IPaymentCustomerClient
- Inheritance
-
StripeCustomerApiClient
- Implements
- Inherited Members
Remarks
Implemented by a provider package. A caller depends on this and registers the provider in its composition root, so which provider takes the money is a deployment decision rather than a reference in its business code.
Constructors
StripeCustomerApiClient(IStripeClient, IOptions<StripeApiClientConfig>, ILogger<StripeCustomerApiClient>)
The paying side: who is charged, and the payment method they saved.
public StripeCustomerApiClient(IStripeClient client, IOptions<StripeApiClientConfig> config, ILogger<StripeCustomerApiClient> logger)
Parameters
clientIStripeClientconfigIOptions<StripeApiClientConfig>loggerILogger<StripeCustomerApiClient>
Remarks
Implemented by a provider package. A caller depends on this and registers the provider in its composition root, so which provider takes the money is a deployment decision rather than a reference in its business code.
Methods
CreateCustomerAsync(string, string?, IDictionary<string, string>?, CancellationToken)
Creates a customer and returns the provider's identifier for it.
public Task<IResult<string>> CreateCustomerAsync(string email, string? name, IDictionary<string, string>? metadata = null, CancellationToken cancellationToken = default)
Parameters
emailstringWhere the provider sends receipts.
namestringThe customer's name as it should appear on them.
metadataIDictionary<string, string>Carried on the provider's object; the caller's own identifiers belong here.
cancellationTokenCancellationTokenCancels the call.
Returns
CreateHostedPaymentMethodPageAsync(HostedPaymentMethodPageRequest, CancellationToken)
A provider-hosted page for saving a payment method, and the address to send the customer to.
public Task<IResult<string>> CreateHostedPaymentMethodPageAsync(HostedPaymentMethodPageRequest request, CancellationToken cancellationToken = default)
Parameters
requestHostedPaymentMethodPageRequestWhose method, where to return to, and the currency it will be charged in.
cancellationTokenCancellationTokenCancels the call.
Returns
Remarks
The saved method is reported by a webhook rather than by the return address, which the customer may never reach.
CreatePaymentMethodIntentAsync(string, CancellationToken)
An attempt at saving a payment method for later, off-session use, for a caller that hosts its own form.
public Task<IResult<PaymentMethodIntentDTO>> CreatePaymentMethodIntentAsync(string customerId, CancellationToken cancellationToken = default)
Parameters
customerIdstringWhose payment method is being saved.
cancellationTokenCancellationTokenCancels the call.
Returns
Remarks
Hosting the form means the card and the provider's script reach the caller's own origin, which is a PCI surface and a content security policy exception. CreateHostedPaymentMethodPageAsync(HostedPaymentMethodPageRequest, CancellationToken) is the alternative that avoids both.
DeleteCustomerAsync(string, CancellationToken)
Deletes the customer at the provider, for a payer who no longer pays there: its saved payment methods go with it, and the provider cancels any subscription it still had. The provider keeps the charges and invoices the law requires it to.
public Task<IResult> DeleteCustomerAsync(string customerId, CancellationToken cancellationToken = default)
Parameters
customerIdstringThe customer to delete.
cancellationTokenCancellationTokenCancels the call.
Returns
GetDefaultPaymentMethodAsync(string, CancellationToken)
The customer's default payment method, or a failure when they have none.
public Task<IResult<PaymentMethodDTO>> GetDefaultPaymentMethodAsync(string customerId, CancellationToken cancellationToken = default)
Parameters
customerIdstringWhose payment method to read.
cancellationTokenCancellationTokenCancels the call.
Returns
ListPaymentMethodsAsync(string, CancellationToken)
Every card the customer saved, the default one marked, newest first.
public Task<IResult<IReadOnlyList<PaymentMethodDTO>>> ListPaymentMethodsAsync(string customerId, CancellationToken cancellationToken = default)
Parameters
customerIdstringWhose payment methods to list.
cancellationTokenCancellationTokenCancels the call.
Returns
RemovePaymentMethodAsync(string, CancellationToken)
Removes a saved payment method from its customer; it can no longer be charged.
public Task<IResult> RemovePaymentMethodAsync(string paymentMethodId, CancellationToken cancellationToken = default)
Parameters
paymentMethodIdstringThe method to remove.
cancellationTokenCancellationTokenCancels the call.
Returns
SetDefaultPaymentMethodAsync(string, string, CancellationToken)
Makes a payment method the one later charges are taken from.
public Task<IResult<PaymentMethodDTO>> SetDefaultPaymentMethodAsync(string customerId, string paymentMethodId, CancellationToken cancellationToken = default)
Parameters
customerIdstringWhose default is being set.
paymentMethodIdstringThe method to charge from now on.
cancellationTokenCancellationTokenCancels the call.
Returns
UpdateCustomerAsync(string, string, string?, CancellationToken)
Changes the customer's e-mail and name, which is where the provider sends receipts and what it prints on them from the next document on; documents already issued keep what they were issued with.
public Task<IResult> UpdateCustomerAsync(string customerId, string email, string? name, CancellationToken cancellationToken = default)
Parameters
customerIdstringThe customer to change.
emailstringWhere the provider sends receipts from now on.
namestringThe customer's name as it should appear on them.
cancellationTokenCancellationTokenCancels the call.