Interface IPaymentCustomerClient
The paying side: who is charged, and the payment method they saved.
public interface IPaymentCustomerClient
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.
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.
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.
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.
GetDefaultPaymentMethodAsync(string, CancellationToken)
The customer's default payment method, or a failure when they have none.
Task<IResult<PaymentMethodDTO>> GetDefaultPaymentMethodAsync(string customerId, CancellationToken cancellationToken = default)
Parameters
customerIdstringWhose payment method to read.
cancellationTokenCancellationTokenCancels the call.
Returns
SetDefaultPaymentMethodAsync(string, string, CancellationToken)
Makes a payment method the one later charges are taken from.
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.