using Bit.Core.Billing.Models; using Bit.Core.Entities; using Bit.Core.Enums; using Stripe; using PaymentMethod = Bit.Core.Billing.Models.PaymentMethod; namespace Bit.Core.Billing.Services; public interface ISubscriberService { /// /// Cancels a subscriber's subscription while including user-provided feedback via the . /// If the flag is , /// this command sets the subscription's "cancel_at_end_of_period" property to . /// Otherwise, this command cancels the subscription immediately. /// /// The subscriber with the subscription to cancel. /// An DTO containing user-provided feedback on why they are cancelling the subscription. /// A flag indicating whether to cancel the subscription immediately or at the end of the subscription period. Task CancelSubscription( ISubscriber subscriber, OffboardingSurveyResponse offboardingSurveyResponse, bool cancelImmediately); /// /// Creates a Braintree for the provided while attaching the provided . /// /// The subscriber to create a Braintree customer for. /// A nonce representing the PayPal payment method the customer will use for payments. /// The of the created Braintree customer. Task CreateBraintreeCustomer( ISubscriber subscriber, string paymentMethodNonce); /// /// Retrieves a Stripe using the 's property. /// /// The subscriber to retrieve the Stripe customer for. /// Optional parameters that can be passed to Stripe to expand or modify the customer. /// A Stripe . /// Thrown when the is . /// This method opts for returning rather than throwing exceptions, making it ideal for surfacing data from API endpoints. Task GetCustomer( ISubscriber subscriber, CustomerGetOptions customerGetOptions = null); /// /// Retrieves a Stripe using the 's property. /// /// The subscriber to retrieve the Stripe customer for. /// Optional parameters that can be passed to Stripe to expand or modify the customer. /// A Stripe . /// Thrown when the is . /// Thrown when the subscriber's is or empty. /// Thrown when the returned from Stripe's API is null. Task GetCustomerOrThrow( ISubscriber subscriber, CustomerGetOptions customerGetOptions = null); /// /// Retrieves the account credit, a masked representation of the default payment source and the tax information for the /// provided . This is essentially a consolidated invocation of the /// and methods with a response that includes the customer's as account credit in order to cut down on Stripe API calls. /// /// The subscriber to retrieve payment method for. /// A containing the subscriber's account credit, payment source and tax information. Task GetPaymentMethod( ISubscriber subscriber); /// /// Retrieves a masked representation of the subscriber's payment source for presentation to a client. /// /// The subscriber to retrieve the payment source for. /// A containing a non-identifiable description of the subscriber's payment source. Example: VISA, *4242, 10/2026 Task GetPaymentSource( ISubscriber subscriber); /// /// Retrieves a Stripe using the 's property. /// /// The subscriber to retrieve the Stripe subscription for. /// Optional parameters that can be passed to Stripe to expand or modify the subscription. /// A Stripe . /// Thrown when the is . /// This method opts for returning rather than throwing exceptions, making it ideal for surfacing data from API endpoints. Task GetSubscription( ISubscriber subscriber, SubscriptionGetOptions subscriptionGetOptions = null); /// /// Retrieves a Stripe using the 's property. /// /// The subscriber to retrieve the Stripe subscription for. /// Optional parameters that can be passed to Stripe to expand or modify the subscription. /// A Stripe . /// Thrown when the is . /// Thrown when the subscriber's is or empty. /// Thrown when the returned from Stripe's API is null. Task GetSubscriptionOrThrow( ISubscriber subscriber, SubscriptionGetOptions subscriptionGetOptions = null); /// /// Retrieves the 's tax information using their Stripe 's . /// /// The subscriber to retrieve the tax information for. /// A representing the 's tax information. /// Thrown when the is . /// This method opts for returning rather than throwing exceptions, making it ideal for surfacing data from API endpoints. Task GetTaxInformation( ISubscriber subscriber); /// /// Attempts to remove a subscriber's saved payment source. If the Stripe representing the /// contains a valid "btCustomerId" key in its property, /// this command will attempt to remove the Braintree . Otherwise, it will attempt to remove the /// Stripe . /// /// The subscriber to remove the saved payment source for. Task RemovePaymentSource(ISubscriber subscriber); /// /// Updates the payment source for the provided using the . /// The following types are supported: [, , ]. /// For each type, updating the payment source will attempt to establish a new payment source using the token in the . Then, it will /// remove the exising payment source(s) linked to the subscriber's customer. /// /// The subscriber to update the payment method for. /// A DTO representing a tokenized payment method. Task UpdatePaymentSource( ISubscriber subscriber, TokenizedPaymentSource tokenizedPaymentSource); /// /// Updates the tax information for the provided . /// /// The to update the tax information for. /// A representing the 's updated tax information. Task UpdateTaxInformation( ISubscriber subscriber, TaxInformation taxInformation); /// /// Verifies the subscriber's pending bank account using the provided . /// /// The subscriber to verify the bank account for. /// The code attached to a deposit made to the subscriber's bank account in order to ensure they have access to it. /// Learn more. /// Task VerifyBankAccount( ISubscriber subscriber, string descriptorCode); }