1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

Signups Fail for Organization & User Names >30 Characters (#2923)

* Add a length limit to include only the LEFT 30

* Resolving PR comment

* Fix the failing test

* Add a comment to stripepayment

* Refactoring the code
This commit is contained in:
cyprain-okeke 2023-05-19 18:45:47 +01:00 committed by GitHub
parent 04e18ee8e7
commit 662ac7f059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -131,7 +131,7 @@ public class StripePaymentService : IPaymentService
new Stripe.CustomerInvoiceSettingsCustomFieldOptions()
{
Name = org.SubscriberType(),
Value = org.SubscriberName(),
Value = GetFirstThirtyCharacters(org.SubscriberName()),
},
},
},
@ -443,7 +443,7 @@ public class StripePaymentService : IPaymentService
new Stripe.CustomerInvoiceSettingsCustomFieldOptions()
{
Name = user.SubscriberType(),
Value = user.SubscriberName(),
Value = GetFirstThirtyCharacters(user.SubscriberName()),
},
}
},
@ -1358,7 +1358,7 @@ public class StripePaymentService : IPaymentService
new Stripe.CustomerInvoiceSettingsCustomFieldOptions()
{
Name = subscriber.SubscriberType(),
Value = subscriber.SubscriberName(),
Value = GetFirstThirtyCharacters(subscriber.SubscriberName()),
},
}
},
@ -1438,7 +1438,7 @@ public class StripePaymentService : IPaymentService
new Stripe.CustomerInvoiceSettingsCustomFieldOptions()
{
Name = subscriber.SubscriberType(),
Value = subscriber.SubscriberName(),
Value = GetFirstThirtyCharacters(subscriber.SubscriberName())
},
}
},
@ -1817,4 +1817,9 @@ public class StripePaymentService : IPaymentService
.OrderByDescending(i => i.Created).Select(i => new BillingInfo.BillingInvoice(i));
}
// We are taking only first 30 characters of the SubscriberName because stripe provide
// for 30 characters for custom_fields,see the link: https://stripe.com/docs/api/invoices/create
private static string GetFirstThirtyCharacters(string subscriberName) => string.IsNullOrWhiteSpace(subscriberName) ? "" : subscriberName.Substring(0, 30);
}

View File

@ -110,7 +110,7 @@ public class StripePaymentServiceTests
Assert.Equal("S-1", organization.GatewaySubscriptionId);
Assert.True(organization.Enabled);
Assert.Equal(DateTime.Today.AddDays(10), organization.ExpirationDate);
var res = organization.SubscriberName();
await stripeAdapter.Received().CustomerCreateAsync(Arg.Is<Stripe.CustomerCreateOptions>(c =>
c.Description == organization.BusinessName &&
c.Email == organization.BillingEmail &&
@ -120,7 +120,7 @@ public class StripePaymentServiceTests
c.InvoiceSettings.DefaultPaymentMethod == null &&
c.InvoiceSettings.CustomFields != null &&
c.InvoiceSettings.CustomFields[0].Name == "Organization" &&
c.InvoiceSettings.CustomFields[0].Value == organization.SubscriberName() &&
c.InvoiceSettings.CustomFields[0].Value == organization.SubscriberName().Substring(0, 30) &&
c.Address.Country == taxInfo.BillingAddressCountry &&
c.Address.PostalCode == taxInfo.BillingAddressPostalCode &&
c.Address.Line1 == taxInfo.BillingAddressLine1 &&
@ -173,7 +173,7 @@ public class StripePaymentServiceTests
c.InvoiceSettings.DefaultPaymentMethod == paymentToken &&
c.InvoiceSettings.CustomFields != null &&
c.InvoiceSettings.CustomFields[0].Name == "Organization" &&
c.InvoiceSettings.CustomFields[0].Value == organization.SubscriberName() &&
c.InvoiceSettings.CustomFields[0].Value == organization.SubscriberName().Substring(0, 30) &&
c.Address.Country == taxInfo.BillingAddressCountry &&
c.Address.PostalCode == taxInfo.BillingAddressPostalCode &&
c.Address.Line1 == taxInfo.BillingAddressLine1 &&