Browse Source

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
pull/2946/head
cyprain-okeke 3 years ago committed by GitHub
parent
commit
662ac7f059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/Core/Services/Implementations/StripePaymentService.cs
  2. 6
      test/Core.Test/Services/StripePaymentServiceTests.cs

13
src/Core/Services/Implementations/StripePaymentService.cs

@ -131,7 +131,7 @@ public class StripePaymentService : IPaymentService @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);
}

6
test/Core.Test/Services/StripePaymentServiceTests.cs

@ -110,7 +110,7 @@ public class StripePaymentServiceTests @@ -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 @@ -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 @@ -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 &&

Loading…
Cancel
Save