1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -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:
cyprain-okeke
2024-09-27 19:39:44 +01:00
committed by GitHub
parent 8c8956da37
commit c66879eb89
7 changed files with 245 additions and 4 deletions

View File

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