Table of Contents

Class StripeCustomerApiClient

Namespace
NuvTools.Payment.Stripe.ApiClient.Services
Assembly
NuvTools.Payment.Stripe.ApiClient.dll

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

client IStripeClient
config IOptions<StripeApiClientConfig>
logger ILogger<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

email string

Where the provider sends receipts.

name string

The customer's name as it should appear on them.

metadata IDictionary<string, string>

Carried on the provider's object; the caller's own identifiers belong here.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult<string>>

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

request HostedPaymentMethodPageRequest

Whose method, where to return to, and the currency it will be charged in.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult<string>>

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

customerId string

Whose payment method is being saved.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult<PaymentMethodIntentDTO>>

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

customerId string

The customer to delete.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult>

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

customerId string

Whose payment method to read.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult<PaymentMethodDTO>>

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

customerId string

Whose payment methods to list.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult<IReadOnlyList<PaymentMethodDTO>>>

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

paymentMethodId string

The method to remove.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult>

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

customerId string

Whose default is being set.

paymentMethodId string

The method to charge from now on.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult<PaymentMethodDTO>>

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

customerId string

The customer to change.

email string

Where the provider sends receipts from now on.

name string

The customer's name as it should appear on them.

cancellationToken CancellationToken

Cancels the call.

Returns

Task<IResult>