public IPaymentService GetPaymentService(GlobalSettings globalSettings) { if (Gateway == null) { throw new BadRequestException("No gateway."); } IPaymentService paymentService = null; switch (Gateway) { case GatewayType.Stripe: paymentService = new StripePaymentService(); break; case GatewayType.Braintree: paymentService = new BraintreePaymentService(globalSettings); break; default: throw new NotSupportedException("Unsupported gateway."); } return(paymentService); }
public async Task WhenCreatingCustomer_UpdateAppMetadataInAuth0() { //Arrange var stripeCustomerRepositoryMock = new StripeCustomerRepositoryMock(); var stripeCheckoutSessionRepositoryMock = new StripeCheckoutSessionRepositoryMock(); var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock(); var userManagementServiceMock = new UserManagementServiceMock(); var priceNameToIdMapper = new DevPriceNameToIdMapper(); StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock, stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock, userManagementServiceMock, priceNameToIdMapper); var auth0UserId = "google-oauth2|00004"; var name = "Patryk Tester"; var email = "*****@*****.**"; var newCustomer = new CreateCustomerDto(auth0UserId, name, email); //Act var createdCustomer = await stripePaymentService.CreateCustomerAsync(newCustomer); var retrievedCustomer = await stripeCustomerRepositoryMock.GetAsync(createdCustomer.Id); //Assert Assert.NotNull(createdCustomer); Assert.NotNull(retrievedCustomer); Assert.Equal(auth0UserId, retrievedCustomer.Metadata["auth0UserId"]); var auth0User = userManagementServiceMock.Users.First(x => x.UserId == auth0UserId); Assert.Equal(retrievedCustomer.Id, auth0User.AppMetadata.StripeCustomerId); Assert.Null(auth0User.AppMetadata.SubscriptionPlan); }
public async Task WhenFetchingUserWithSubscription_SubscriptionField_ShouldBeInitialized() { //Arrange var stripeCustomerRepositoryMock = new StripeCustomerRepositoryMock(); var stripeCheckoutSessionRepositoryMock = new StripeCheckoutSessionRepositoryMock(); var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock(); var userManagementServiceMock = new UserManagementServiceMock(); var priceNameToIdMapper = new DevPriceNameToIdMapper(); StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock, stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock, userManagementServiceMock, priceNameToIdMapper); var idOfCustomerWithSubscription = "cus_id3"; var subscriptionId = "sub_3"; var subscriptionStatus = "active"; //Act var customer = await stripePaymentService.GetCustomerAsync(idOfCustomerWithSubscription); //Assert Assert.NotNull(customer); Assert.NotNull(customer.Subscription); Assert.Equal(subscriptionId, customer.Subscription.Id); Assert.Equal(subscriptionStatus, customer.Subscription.Status); Assert.Equal(idOfCustomerWithSubscription, customer.Subscription.CustomerId); }
public async Task UpdateCustomerAsync_WhenUpdatingCountryForUserWithNoAddress_OnlyCountryIsUpdated() { //Arrange var stripeCustomerRepositoryMock = new StripeCustomerRepositoryMock(); var stripeCheckoutSessionRepositoryMock = new StripeCheckoutSessionRepositoryMock(); var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock(); var userManagementServiceMock = new UserManagementServiceMock(); var priceNameToIdMapper = new DevPriceNameToIdMapper(); StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock, stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock, userManagementServiceMock, priceNameToIdMapper); string customerId = "cus_id1"; string country = "PL"; var updatedCustomer = new UpdateCustomerDto(customerId, country); //Act var returnedCustomer = await stripePaymentService.UpdateCustomerAsync(updatedCustomer); //Assert Assert.Equal(country, returnedCustomer.Country); Assert.Null(returnedCustomer.City); Assert.Null(returnedCustomer.PostalCode); Assert.Null(returnedCustomer.Line1); Assert.Null(returnedCustomer.Line2); Assert.Null(returnedCustomer.State); }
public async Task <OrganizationBillingResponseModel> GetBilling(string id) { var orgIdGuid = new Guid(id); if (!_currentContext.OrganizationOwner(orgIdGuid)) { throw new NotFoundException(); } var organization = await _organizationRepository.GetByIdAsync(orgIdGuid); if (organization == null) { throw new NotFoundException(); } if (!_globalSettings.SelfHosted && organization.Gateway != null) { var paymentService = new StripePaymentService(); var billingInfo = await paymentService.GetBillingAsync(organization); if (billingInfo == null) { throw new NotFoundException(); } return(new OrganizationBillingResponseModel(organization, billingInfo)); } else { return(new OrganizationBillingResponseModel(organization)); } }
public PaymentsController(JwtToken jwtToken, StripeEventHandlerService stripeEventHandlerService, IUserManagementService userManagementService, StripePaymentService stripePaymentService) { _jwtToken = jwtToken; _stripeEventHandlerService = stripeEventHandlerService; _userManagementService = userManagementService; _stripePaymentService = stripePaymentService; }
public void Setup() { paymentIntentServiceMock = new Mock <PaymentIntentService>(); customerServiceMock = new Mock <CustomerService>(); paymentMethodServiceMock = new Mock <PaymentMethodService>(); setupIntentServiceMock = new Mock <SetupIntentService>(); stripePaymentService = new StripePaymentService(paymentIntentServiceMock.Object, customerServiceMock.Object, paymentMethodServiceMock.Object, setupIntentServiceMock.Object); }
public StripePaymentServiceTests() { _transactionRepository = Substitute.For <ITransactionRepository>(); _globalSettings = new GlobalSettings(); _logger = Substitute.For <ILogger <StripePaymentService> >(); _sut = new StripePaymentService( _transactionRepository, _globalSettings, _logger ); }
public StripePaymentServiceTests() { _transactionRepository = Substitute.For <ITransactionRepository>(); _userRepository = Substitute.For <IUserRepository>(); _appleIapService = Substitute.For <IAppleIapService>(); _globalSettings = new GlobalSettings(); _logger = Substitute.For <ILogger <StripePaymentService> >(); _sut = new StripePaymentService( _transactionRepository, _userRepository, _globalSettings, _appleIapService, _logger, _taxRateRepository ); }
public async Task UpdateCustomerAsync_WhenUpdatingWholeAddress_EveryAddressPropertyIsPopulated() { //Arrange var stripeCustomerRepositoryMock = new StripeCustomerRepositoryMock(); var stripeCheckoutSessionRepositoryMock = new StripeCheckoutSessionRepositoryMock(); var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock(); var userManagementServiceMock = new UserManagementServiceMock(); var priceNameToIdMapper = new DevPriceNameToIdMapper(); StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock, stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock, userManagementServiceMock, priceNameToIdMapper); string customerId = "cus_id1"; string country = "PL"; string city = "Lodz"; string postalCode = "90-608"; string line1 = "Piotrkowska 60/25"; string line2 = ""; string state = ""; var updatedCustomer = new UpdateCustomerDto(customerId, country) { City = city, PostalCode = postalCode, Line1 = line1, Line2 = line2, State = state, }; //Act var returnedCustomer = await stripePaymentService.UpdateCustomerAsync(updatedCustomer); //Assert Assert.Equal(country, returnedCustomer.Country); Assert.Equal(city, returnedCustomer.City); Assert.Equal(postalCode, returnedCustomer.PostalCode); Assert.Equal(line1, returnedCustomer.Line1); Assert.Equal(line2, returnedCustomer.Line2); Assert.Equal(state, returnedCustomer.State); }
public async Task WhenFetchingUserWithoutSubscription_SubscriptionField_ShouldBeNull() { //Arrange var stripeCustomerRepositoryMock = new StripeCustomerRepositoryMock(); var stripeCheckoutSessionRepositoryMock = new StripeCheckoutSessionRepositoryMock(); var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock(); var userManagementServiceMock = new UserManagementServiceMock(); var priceNameToIdMapper = new DevPriceNameToIdMapper(); StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock, stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock, userManagementServiceMock, priceNameToIdMapper); var idOfCustomerWithoutSubscription = "cus_id2"; //Act var customer = await stripePaymentService.GetCustomerAsync(idOfCustomerWithoutSubscription); //Assert Assert.Null(customer.Subscription); }
public async Task ShouldReturnPayments() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var paymentService = new StripePaymentService(dbContext); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); booking.Id = result.Id.Value; booking.AddPayment(100); booking.AddPayment(200); await bookingService.UpdateBooking("tester", booking); var payments = await paymentService.GetPayments(); Assert.NotEmpty(payments); Assert.Equal(2, payments.Count); }
[Fact] public async Task UpdateCustomerAsync_WhenUpdatingCountryForUserWithAddress_OnlyCountryPropertyIsUpdated() { //Arrange var stripeCustomerRepositoryMock = new StripeCustomerRepositoryMock(); var stripeCheckoutSessionRepositoryMock = new StripeCheckoutSessionRepositoryMock(); var stripeBillingPortalSessionRepositoryMock = new StripeBillingPortalSessionRepositoryMock(); var userManagementServiceMock = new UserManagementServiceMock(); var priceNameToIdMapper = new DevPriceNameToIdMapper(); StripePaymentService stripePaymentService = new StripePaymentService(stripeCustomerRepositoryMock, stripeCheckoutSessionRepositoryMock, stripeBillingPortalSessionRepositoryMock, userManagementServiceMock, priceNameToIdMapper); string customerId = "cus_id3"; string newCountry = "UK"; string expectedCity = "Lodz"; string expectedPostalCode = "90-608"; string expectedLine1 = "Piotrkowska 60/25"; string expectedLine2 = null; string expectedState = "lodzkie"; var updatedCustomer = new UpdateCustomerDto(customerId, newCountry); //Act var returnedCustomer = await stripePaymentService.UpdateCustomerAsync(updatedCustomer); //Assert Assert.Equal(newCountry, returnedCustomer.Country); Assert.Equal(expectedCity, returnedCustomer.City); Assert.Equal(expectedPostalCode, returnedCustomer.PostalCode); Assert.Equal(expectedLine1, returnedCustomer.Line1); Assert.Equal(expectedLine2, returnedCustomer.Line2); Assert.Equal(expectedState, returnedCustomer.State); }
private async System.Threading.Tasks.Task saveUserAsync() { // IsBioReadOnly = true; IsBioEditing = false; //Pre save checks if (String.IsNullOrEmpty(name) || name.Trim().IndexOf(' ') == -1) { UserDialogs.Instance.Alert("Save Failed: Please Enter First and Last Name", null, null); return; } else if (isTutor && (ZoomLink == null || ZoomLink == string.Empty || !Uri.IsWellFormedUriString(ZoomLink, UriKind.Absolute) || !ZoomLink.Contains("https://ufl.zoom.us"))) //TODO add more extensive checks for zoom link { UserDialogs.Instance.Alert("Save Failed: Invalid zoom link", null, null); return; } else if (isTutor && requestedPay < 1) { UserDialogs.Instance.Alert("Save Failed: Requested pay must be greater than $1", null, null); return; } else if (isTutor && (Courses == null || Courses.Count < 1)) { UserDialogs.Instance.Alert("Save Failed: You must have at least one course", null, null); return; } try { //save all user properties profileUser.EducationSections = EducationSections.ToList <EducationSection>(); profileUser.Courses = Courses.ToList <Course>(); profileUser.Biography = Biography; profileUser.requestedPay = requestedPay; profileUser.ScheduleSections = ScheduleSections.ToList <ScheduleTile>(); profileUser.name = name; profileUser.shortBio = shortBio; profileUser.isTutor = isTutor; profileUser.zoomLink = ""; profileUser.zoomLink = zoomLink.Trim(); } catch (Exception e) { UserDialogs.Instance.Alert("Save Failed: Receive Payment Set Up Failure", null, null); Console.WriteLine(e.Message); return; } //TRY TO CREATE CONNECTED ACCOUNT IF IT IS NULL IN PROFILE USER if (isTutor && String.IsNullOrEmpty(profileUser.stripeAccountID)) { UserDialogs.Instance.ShowLoading("Saving"); string accountID = StripePaymentService.makeAccount(profileUser, stripeInfo); if (String.IsNullOrEmpty(accountID)) { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.Alert("Save Failed: Incorrect Receive Payment Information!", null, null); return; } profileUser.stripeAccountID = accountID; } bool didSave = false; string userString = JsonSerializer.Serialize(profileUser); //update current user in properties and save try { UserDialogs.Instance.ShowLoading("Saving"); didSave = await WebAPIServices.updateUser(userString); UserDialogs.Instance.HideLoading(); } catch (Exception e) { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.Alert("Saved Failed", null, null); Console.WriteLine(e.Message); return; } if (!didSave) { UserDialogs.Instance.Alert("Saved Failed", null, null); return; } if (App.Current.Properties.ContainsKey("CurrentUser")) { App.Current.Properties["CurrentUser"] = userString; } else { App.Current.Properties.Add("CurrentUser", userString); } //TODO: Add a services call that saves object in database App.Current.SavePropertiesAsync(); UserDialogs.Instance.Alert("Saved Successfully!", null, null); onPropertyChanged(nameof(isRecievePaymentVisible)); }