@ -36,6 +36,56 @@ public class StripePaymentServiceTests
@@ -36,6 +36,56 @@ public class StripePaymentServiceTests
Assert . Equal ( "Payment method is not supported at this time." , exception . Message ) ;
}
[Theory, BitAutoData]
public async void PurchaseOrganizationAsync_Stripe_ProviderOrg_Coupon_Add ( SutProvider < StripePaymentService > sutProvider , Organization organization , string paymentToken , TaxInfo taxInfo , bool provider = true )
{
var plan = StaticStore . Plans . First ( p = > p . Type = = PlanType . EnterpriseAnnually ) ;
var stripeAdapter = sutProvider . GetDependency < IStripeAdapter > ( ) ;
stripeAdapter . CustomerCreateAsync ( default ) . ReturnsForAnyArgs ( new Stripe . Customer
{
Id = "C-1" ,
} ) ;
stripeAdapter . SubscriptionCreateAsync ( default ) . ReturnsForAnyArgs ( new Stripe . Subscription
{
Id = "S-1" ,
CurrentPeriodEnd = DateTime . Today . AddDays ( 1 0 ) ,
} ) ;
var result = await sutProvider . Sut . PurchaseOrganizationAsync ( organization , PaymentMethodType . Card , paymentToken , plan , 0 , 0 , false , taxInfo , provider ) ;
Assert . Null ( result ) ;
Assert . Equal ( GatewayType . Stripe , organization . Gateway ) ;
Assert . Equal ( "C-1" , organization . GatewayCustomerId ) ;
Assert . Equal ( "S-1" , organization . GatewaySubscriptionId ) ;
Assert . True ( organization . Enabled ) ;
Assert . Equal ( DateTime . Today . AddDays ( 1 0 ) , organization . ExpirationDate ) ;
await stripeAdapter . Received ( ) . CustomerCreateAsync ( Arg . Is < Stripe . CustomerCreateOptions > ( c = >
c . Description = = organization . BusinessName & &
c . Email = = organization . BillingEmail & &
c . Source = = paymentToken & &
c . PaymentMethod = = null & &
c . Coupon = = "msp-discount-35" & &
! c . Metadata . Any ( ) & &
c . InvoiceSettings . DefaultPaymentMethod = = null & &
c . Address . Country = = taxInfo . BillingAddressCountry & &
c . Address . PostalCode = = taxInfo . BillingAddressPostalCode & &
c . Address . Line1 = = taxInfo . BillingAddressLine1 & &
c . Address . Line2 = = taxInfo . BillingAddressLine2 & &
c . Address . City = = taxInfo . BillingAddressCity & &
c . Address . State = = taxInfo . BillingAddressState & &
c . TaxIdData = = null
) ) ;
await stripeAdapter . Received ( ) . SubscriptionCreateAsync ( Arg . Is < Stripe . SubscriptionCreateOptions > ( s = >
s . Customer = = "C-1" & &
s . Expand [ 0 ] = = "latest_invoice.payment_intent" & &
s . Metadata [ organization . GatewayIdField ( ) ] = = organization . Id . ToString ( ) & &
s . Items . Count = = 0
) ) ;
}
[Theory, BitAutoData]
public async void PurchaseOrganizationAsync_Stripe ( SutProvider < StripePaymentService > sutProvider , Organization organization , string paymentToken , TaxInfo taxInfo )
{