mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PM-8445] Update trial initiation UI (#4712)
* Add the feature flag Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Initial comment Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * changes to subscribe with payment method Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add new objects * Implementation for subscription without payment method Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Remove unused codes and classes Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Rename the flag properly Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * remove implementation that is no longer needed Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * revert the changes on some code removal Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the pr comment Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * format the data annotations line breaks Signed-off-by: Cy Okeke <cokeke@bitwarden.com> --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
This commit is contained in:
@ -15,6 +15,9 @@ public interface IPaymentService
|
||||
string paymentToken, Plan plan, short additionalStorageGb, int additionalSeats,
|
||||
bool premiumAccessAddon, TaxInfo taxInfo, bool provider = false, int additionalSmSeats = 0,
|
||||
int additionalServiceAccount = 0, bool signupIsFromSecretsManagerTrial = false);
|
||||
Task<string> PurchaseOrganizationNoPaymentMethod(Organization org, Plan plan, int additionalSeats,
|
||||
bool premiumAccessAddon, int additionalSmSeats = 0, int additionalServiceAccount = 0,
|
||||
bool signupIsFromSecretsManagerTrial = false);
|
||||
Task SponsorOrganizationAsync(Organization org, OrganizationSponsorship sponsorship);
|
||||
Task RemoveOrganizationSponsorshipAsync(Organization org, OrganizationSponsorship sponsorship);
|
||||
Task<string> UpgradeFreeOrganizationAsync(Organization org, Plan plan, OrganizationUpgrade upgrade);
|
||||
|
@ -207,6 +207,77 @@ public class StripePaymentService : IPaymentService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> PurchaseOrganizationNoPaymentMethod(Organization org, StaticStore.Plan plan, int additionalSeats, bool premiumAccessAddon,
|
||||
int additionalSmSeats = 0, int additionalServiceAccount = 0, bool signupIsFromSecretsManagerTrial = false)
|
||||
{
|
||||
|
||||
var stripeCustomerMetadata = new Dictionary<string, string>
|
||||
{
|
||||
{ "region", _globalSettings.BaseServiceUri.CloudRegion }
|
||||
};
|
||||
var subCreateOptions = new OrganizationPurchaseSubscriptionOptions(org, plan, new TaxInfo(), additionalSeats, 0, premiumAccessAddon
|
||||
, additionalSmSeats, additionalServiceAccount);
|
||||
|
||||
Customer customer = null;
|
||||
Subscription subscription;
|
||||
try
|
||||
{
|
||||
var customerCreateOptions = new CustomerCreateOptions
|
||||
{
|
||||
Description = org.DisplayBusinessName(),
|
||||
Email = org.BillingEmail,
|
||||
Metadata = stripeCustomerMetadata,
|
||||
InvoiceSettings = new CustomerInvoiceSettingsOptions
|
||||
{
|
||||
CustomFields =
|
||||
[
|
||||
new CustomerInvoiceSettingsCustomFieldOptions
|
||||
{
|
||||
Name = org.SubscriberType(),
|
||||
Value = GetFirstThirtyCharacters(org.SubscriberName()),
|
||||
}
|
||||
],
|
||||
},
|
||||
Coupon = signupIsFromSecretsManagerTrial
|
||||
? SecretsManagerStandaloneDiscountId
|
||||
: null,
|
||||
TaxIdData = null,
|
||||
};
|
||||
|
||||
customer = await _stripeAdapter.CustomerCreateAsync(customerCreateOptions);
|
||||
subCreateOptions.AddExpand("latest_invoice.payment_intent");
|
||||
subCreateOptions.Customer = customer.Id;
|
||||
|
||||
subscription = await _stripeAdapter.SubscriptionCreateAsync(subCreateOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error creating customer, walking back operation.");
|
||||
if (customer != null)
|
||||
{
|
||||
await _stripeAdapter.CustomerDeleteAsync(customer.Id);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
org.Gateway = GatewayType.Stripe;
|
||||
org.GatewayCustomerId = customer.Id;
|
||||
org.GatewaySubscriptionId = subscription.Id;
|
||||
|
||||
if (subscription.Status == "incomplete" &&
|
||||
subscription.LatestInvoice?.PaymentIntent?.Status == "requires_action")
|
||||
{
|
||||
org.Enabled = false;
|
||||
return subscription.LatestInvoice.PaymentIntent.ClientSecret;
|
||||
}
|
||||
|
||||
org.Enabled = true;
|
||||
org.ExpirationDate = subscription.CurrentPeriodEnd;
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private async Task ChangeOrganizationSponsorship(
|
||||
Organization org,
|
||||
OrganizationSponsorship sponsorship,
|
||||
|
Reference in New Issue
Block a user