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.

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>>

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>>