mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 09:02:48 -05:00
[AC-2965] Use OrganizationBillingService to purchase org when FF is on (#4737)
* Add PurchaseSubscription to OrganizationBillingService and call from OrganizationService.SignUpAsync when FF is on * Run dotnet format * Missed billing service DI for SCIM which uses the OrganizationService
This commit is contained in:
@ -102,6 +102,37 @@ public class SubscriberService(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> CreateBraintreeCustomer(
|
||||
ISubscriber subscriber,
|
||||
string paymentMethodNonce)
|
||||
{
|
||||
var braintreeCustomerId =
|
||||
subscriber.BraintreeCustomerIdPrefix() +
|
||||
subscriber.Id.ToString("N").ToLower() +
|
||||
CoreHelpers.RandomString(3, upper: false, numeric: false);
|
||||
|
||||
var customerResult = await braintreeGateway.Customer.CreateAsync(new CustomerRequest
|
||||
{
|
||||
Id = braintreeCustomerId,
|
||||
CustomFields = new Dictionary<string, string>
|
||||
{
|
||||
[subscriber.BraintreeIdField()] = subscriber.Id.ToString(),
|
||||
[subscriber.BraintreeCloudRegionField()] = globalSettings.BaseServiceUri.CloudRegion
|
||||
},
|
||||
Email = subscriber.BillingEmailAddress(),
|
||||
PaymentMethodNonce = paymentMethodNonce,
|
||||
});
|
||||
|
||||
if (customerResult.IsSuccess())
|
||||
{
|
||||
return customerResult.Target.Id;
|
||||
}
|
||||
|
||||
logger.LogError("Failed to create Braintree customer for subscriber ({ID})", subscriber.Id);
|
||||
|
||||
throw new BillingException();
|
||||
}
|
||||
|
||||
public async Task<Customer> GetCustomer(
|
||||
ISubscriber subscriber,
|
||||
CustomerGetOptions customerGetOptions = null)
|
||||
@ -530,7 +561,7 @@ public class SubscriberService(
|
||||
}
|
||||
}
|
||||
|
||||
braintreeCustomerId = await CreateBraintreeCustomerAsync(subscriber, token);
|
||||
braintreeCustomerId = await CreateBraintreeCustomer(subscriber, token);
|
||||
|
||||
await AddBraintreeCustomerIdAsync(customer, braintreeCustomerId);
|
||||
|
||||
@ -648,37 +679,6 @@ public class SubscriberService(
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<string> CreateBraintreeCustomerAsync(
|
||||
ISubscriber subscriber,
|
||||
string paymentMethodNonce)
|
||||
{
|
||||
var braintreeCustomerId =
|
||||
subscriber.BraintreeCustomerIdPrefix() +
|
||||
subscriber.Id.ToString("N").ToLower() +
|
||||
CoreHelpers.RandomString(3, upper: false, numeric: false);
|
||||
|
||||
var customerResult = await braintreeGateway.Customer.CreateAsync(new CustomerRequest
|
||||
{
|
||||
Id = braintreeCustomerId,
|
||||
CustomFields = new Dictionary<string, string>
|
||||
{
|
||||
[subscriber.BraintreeIdField()] = subscriber.Id.ToString(),
|
||||
[subscriber.BraintreeCloudRegionField()] = globalSettings.BaseServiceUri.CloudRegion
|
||||
},
|
||||
Email = subscriber.BillingEmailAddress(),
|
||||
PaymentMethodNonce = paymentMethodNonce,
|
||||
});
|
||||
|
||||
if (customerResult.IsSuccess())
|
||||
{
|
||||
return customerResult.Target.Id;
|
||||
}
|
||||
|
||||
logger.LogError("Failed to create Braintree customer for subscriber ({ID})", subscriber.Id);
|
||||
|
||||
throw new BillingException();
|
||||
}
|
||||
|
||||
private async Task<PaymentSource> GetPaymentSourceAsync(
|
||||
Guid subscriberId,
|
||||
Customer customer)
|
||||
|
Reference in New Issue
Block a user