public bool IsValid(DopplerUserDto dopplerUser, string sapSystem, SapConfig sapConfig, out string error)
        {
            if (!sapConfig.SapServiceConfigsBySystem.ContainsKey(sapSystem))
            {
                _logger.LogInformation($"{dopplerUser.Email} won't be sent to SAP because it's not from {string.Join(", ", sapConfig.SapServiceConfigsBySystem.Select(x => x.Key))}");
                error = "Invalid billing system value.";
                return(false);
            }

            if (string.IsNullOrEmpty(dopplerUser.FirstName) && string.IsNullOrEmpty(dopplerUser.LastName))
            {
                _logger.LogInformation($"{dopplerUser.Email} won't be sent to SAP because it doesn't have a first name or last name");
                error = "Invalid first name or last name.";
                return(false);
            }

            if (string.IsNullOrEmpty(dopplerUser.FederalTaxID))
            {
                _logger.LogInformation($"{dopplerUser.Email} won't be sent to SAP because it doesn't have a cuit value");
                error = "Invalid cuit value.";
                return(false);
            }

            if (!dopplerUser.PlanType.HasValue)
            {
                _logger.LogInformation($"{dopplerUser.Email} won't be sent to SAP because it doesn't have a plan type id");
                error = "Invalid plan type value.";
                return(false);
            }

            error = string.Empty;

            return(true);
        }
示例#2
0
 public SetCurrencyRateHandler(
     IOptions <SapConfig> sapConfig,
     ISapServiceSettingsFactory sapServiceSettingsFactory,
     IHttpClientFactory httpClientFactory)
 {
     _sapConfig = sapConfig.Value;
     _sapServiceSettingsFactory = sapServiceSettingsFactory;
     _httpClientFactory         = httpClientFactory;
 }
        public static SapServiceConfig GetSettings(SapConfig sapConfig, string sapSystem)
        {
            if (!sapConfig.SapServiceConfigsBySystem.TryGetValue(sapSystem, out var serviceSettings))
            {
                throw new ArgumentException($"The sapSystem '{sapSystem}' does not have settings.", sapSystem);
            }

            return(serviceSettings);
        }
示例#4
0
 public CreateOrUpdateBusinessPartnerHandler(
     IOptions <SapConfig> sapConfig,
     IHttpClientFactory httpClientFactory,
     ISapServiceSettingsFactory sapServiceSettingsFactory)
 {
     _sapConfig                 = sapConfig.Value;
     _httpClientFactory         = httpClientFactory;
     _sapServiceSettingsFactory = sapServiceSettingsFactory;
 }
示例#5
0
        public static SapServiceConfig GetSettings(SapConfig sapConfig, string sapSystem)
        {
            if (!sapConfig.SapServiceConfigsBySystem.TryGetValue(sapSystem, out var serviceSettings))
            {
                throw new ArgumentException(nameof(sapSystem), $"The sapSystem '{sapSystem}' is not supported.");
            }

            return(serviceSettings);
        }
 public BusinessPartnerService(
     IQueuingService queuingService,
     ILogger <BusinessPartnerService> logger,
     IOptions <SapConfig> sapConfig,
     IEnumerable <IBusinessPartnerValidation> businessPartnerValidations)
 {
     _queuingService             = queuingService;
     _logger                     = logger;
     _sapConfig                  = sapConfig.Value;
     _businessPartnerValidations = businessPartnerValidations;
 }
示例#7
0
 public SapServiceSettingsFactory(
     IOptions <SapConfig> sapConfig,
     ILogger <SapTaskHandler> logger,
     IHttpClientFactory httpClientFactory,
     IDateTimeProvider dateTimeProvider,
     IEnumerable <IBusinessPartnerMapper> businessPartnerMappers)
 {
     _sapConfig              = sapConfig.Value;
     _logger                 = logger;
     _httpClientFactory      = httpClientFactory;
     _dateTimeProvider       = dateTimeProvider;
     _businessPartnerMappers = businessPartnerMappers;
 }
示例#8
0
 public CreditNoteHandler(
     IOptions <SapConfig> sapConfig,
     ILogger <CreditNoteHandler> logger,
     ISapServiceSettingsFactory sapServiceSettingsFactory,
     IHttpClientFactory httpClientFactory,
     IEnumerable <IBillingMapper> billingMappers)
 {
     _sapConfig = sapConfig.Value;
     _logger    = logger;
     _sapServiceSettingsFactory = sapServiceSettingsFactory;
     _httpClientFactory         = httpClientFactory;
     _billingMappers            = billingMappers;
 }
示例#9
0
 public SapTaskHandler(
     SapConfig sapConfig,
     ILogger <SapTaskHandler> logger,
     IHttpClientFactory httpClientFactory,
     IDateTimeProvider dateTimeProvider,
     SapServiceConfig sapServiceConfig,
     IBusinessPartnerMapper businessPartnerMapper)
 {
     _sapConfig             = sapConfig;
     _logger                = logger;
     _httpClientFactory     = httpClientFactory;
     _dateTimeProvider      = dateTimeProvider;
     _sapServiceConfig      = sapServiceConfig;
     _businessPartnerMapper = businessPartnerMapper;
 }
示例#10
0
 public BillingRequestHandler(
     IOptions <SapConfig> sapConfig,
     ILogger <BillingRequestHandler> logger,
     ISapServiceSettingsFactory sapServiceSettingsFactory,
     IHttpClientFactory httpClientFactory,
     IEnumerable <IBillingValidation> billingValidations,
     IEnumerable <IBillingMapper> billingMappers)
 {
     _sapConfig = sapConfig.Value;
     _logger    = logger;
     _sapServiceSettingsFactory = sapServiceSettingsFactory;
     _httpClientFactory         = httpClientFactory;
     _billingMappers            = billingMappers;
     _billingValidations        = billingValidations;
 }
示例#11
0
 public TestSapService(ILogger <TestSapService> logger, IOptions <SapConfig> sapConfig)
 {
     _logger    = logger;
     _sapConfig = sapConfig.Value;
 }
        public async Task CreditNoteHandler_AR_ShouldBeSendCreditNoteInSap_WhenCreditNoteHasNotReasonValid()
        {
            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            dateTimeProviderMock.Setup(x => x.GetDateByTimezoneId(It.IsAny <DateTime>(), It.IsAny <string>()))
            .Returns(new DateTime(2051, 2, 3));

            var timeZoneConfigurations = new TimeZoneConfigurations
            {
                InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time")
            };

            var billingMappers = new List <IBillingMapper>
            {
                new BillingForArMapper(Mock.Of <ISapBillingItemsService>(), dateTimeProviderMock.Object, timeZoneConfigurations)
            };

            var sapTaskHandlerMock = new Mock <ISapTaskHandler>();

            sapTaskHandlerMock.Setup(x => x.StartSession())
            .ReturnsAsync(new SapLoginCookies
            {
                B1Session = "session",
                RouteId   = "route"
            });

            sapTaskHandlerMock.Setup(x => x.TryGetInvoiceByInvoiceIdAndOrigin(It.IsAny <int>(), It.IsAny <string>()))
            .ReturnsAsync(new SapSaleOrderInvoiceResponse
            {
                BillingSystemId = 9,
                CardCode        = "CD001",
                DocumentLines   = new List <SapDocumentLineResponse>
                {
                    new SapDocumentLineResponse
                    {
                        FreeText = "1"
                    },
                    new SapDocumentLineResponse
                    {
                        FreeText = "2"
                    }
                }
            });

            var sapServiceSettingsFactoryMock = new Mock <ISapServiceSettingsFactory>();

            sapServiceSettingsFactoryMock.Setup(x => x.CreateHandler("AR"))
            .Returns(sapTaskHandlerMock.Object);

            var sapConfig = new SapConfig
            {
                SapServiceConfigsBySystem = new Dictionary <string, SapServiceConfig>
                {
                    {
                        "AR", new SapServiceConfig
                        {
                            CompanyDB             = "CompanyDb",
                            Password              = "******",
                            UserName              = "******",
                            BaseServerUrl         = "http://123.123.123/",
                            BusinessPartnerConfig = new BusinessPartnerConfig
                            {
                                Endpoint = "BusinessPartners"
                            },
                            BillingConfig = new BillingConfig
                            {
                                CreditNotesEndpoint = "CreditNotes"
                            }
                        }
                    }
                }
            };

            var sapConfigMock = new Mock <IOptions <SapConfig> >();

            sapConfigMock.Setup(x => x.Value)
            .Returns(sapConfig);

            var httpMessageHandlerMock = new Mock <HttpMessageHandler>();
            var handler = new CreditNoteHandler(
                sapConfigMock.Object,
                Mock.Of <ILogger <CreditNoteHandler> >(),
                sapServiceSettingsFactoryMock.Object,
                HttpHelperExtension.GetHttpClientMock("", HttpStatusCode.OK, httpMessageHandlerMock),
                billingMappers);

            var sapTask = new SapTask
            {
                CreditNoteRequest = new CreditNoteRequest
                {
                    BillingSystemId = 9,
                    CreditNoteId    = 1,
                    Amount          = 20
                },
                TaskType = Enums.SapTaskEnum.CreateCreditNote
            };

            // Act
            await handler.Handle(sapTask);


            // Assert
            var uriForCreateCreditNote = sapConfig.SapServiceConfigsBySystem["AR"].BaseServerUrl + sapConfig.SapServiceConfigsBySystem["AR"].BillingConfig.CreditNotesEndpoint;

            httpMessageHandlerMock.Protected().Verify("SendAsync", Times.Once(),
                                                      ItExpr.Is <HttpRequestMessage>(
                                                          req => req.Method == HttpMethod.Post &&
                                                          req.RequestUri == new Uri(uriForCreateCreditNote) &&
                                                          req.Content.ReadAsStringAsync().Result.Contains("\"ReturnReason\":-1")),
                                                      ItExpr.IsAny <CancellationToken>());
        }
示例#13
0
 public SlackService(IOptions <SapConfig> sapConfig, IHttpClientFactory httpClientFactory)
 {
     _sapConfig         = sapConfig.Value;
     _httpClientFactory = httpClientFactory;
 }
示例#14
0
        public async Task BillingRequestHandler_ShouldSendDateOfPaymentNow_WhenPaymentProcessIsExecuted()
        {
            var sapTask = new SapTask
            {
                BillingRequest = new SapSaleOrderModel
                {
                    InvoiceId           = 1,
                    TransactionApproved = true,
                    BillingSystemId     = 2
                },
                TaskType = Enums.SapTaskEnum.BillingRequest
            };

            var sapTaskHandlerMock = new Mock <ISapTaskHandler>();

            sapTaskHandlerMock.Setup(x => x.TryGetBusinessPartner(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync(new SapBusinessPartner
            {
                FederalTaxID = string.Empty,
                CardCode     = "2323423"
            });

            sapTaskHandlerMock.Setup(x => x.TryGetInvoiceByInvoiceIdAndOrigin(It.IsAny <int>(), It.IsAny <string>()))
            .ReturnsAsync((SapSaleOrderInvoiceResponse)null);

            sapTaskHandlerMock.Setup(x => x.StartSession())
            .ReturnsAsync(new SapLoginCookies
            {
                B1Session = "session",
                RouteId   = "route"
            });

            var sapServiceSettingsFactoryMock = new Mock <ISapServiceSettingsFactory>();

            sapServiceSettingsFactoryMock.Setup(x => x.CreateHandler(It.IsAny <string>()))
            .Returns(sapTaskHandlerMock.Object);

            var billingValidations = new List <IBillingValidation>
            {
                new BillingForUsValidation(Mock.Of <ILogger <BillingForUsValidation> >())
            };

            var timeZoneConfigurations = new TimeZoneConfigurations
            {
                InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time")
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            dateTimeProviderMock.Setup(x => x.GetDateByTimezoneId(It.IsAny <DateTime>(), It.IsAny <string>()))
            .Returns(new DateTime(2051, 2, 3));

            var billingMappers = new List <IBillingMapper>
            {
                new BillingForUsMapper(Mock.Of <ISapBillingItemsService>(), dateTimeProviderMock.Object, timeZoneConfigurations)
            };

            var sapConfig = new SapConfig
            {
                SapServiceConfigsBySystem = new Dictionary <string, SapServiceConfig>
                {
                    {
                        "US", new SapServiceConfig
                        {
                            CompanyDB             = "CompanyDb",
                            Password              = "******",
                            UserName              = "******",
                            BaseServerUrl         = "http://123.123.123/",
                            BusinessPartnerConfig = new BusinessPartnerConfig
                            {
                                Endpoint = "BusinessPartners"
                            },
                            BillingConfig = new BillingConfig
                            {
                                Endpoint = "Orders",
                                NeedCreateIncomingPayments = true
                            }
                        }
                    }
                }
            };

            var sapConfigMock = new Mock <IOptions <SapConfig> >();

            sapConfigMock.Setup(x => x.Value)
            .Returns(sapConfig);

            var httpMessageHandlerMock = new Mock <HttpMessageHandler>();
            var handler = new BillingRequestHandler(
                sapConfigMock.Object,
                Mock.Of <ILogger <BillingRequestHandler> >(),
                sapServiceSettingsFactoryMock.Object,
                HttpHelperExtension.GetHttpClientMock("{\"DocEntry\":3783,\"CardCode\":\"345\"}", HttpStatusCode.OK, httpMessageHandlerMock),
                billingValidations,
                billingMappers);

            await handler.Handle(sapTask);

            var uriForIncomingPayment = sapConfig.SapServiceConfigsBySystem["US"].BaseServerUrl + sapConfig.SapServiceConfigsBySystem["US"].BillingConfig.IncomingPaymentsEndpoint;

            httpMessageHandlerMock.Protected().Verify("SendAsync", Times.Once(),
                                                      ItExpr.Is <HttpRequestMessage>(
                                                          req => req.Method == HttpMethod.Post && req.RequestUri == new Uri(uriForIncomingPayment) && req.Content.ReadAsStringAsync().Result.Contains("\"DocDate\":\"2051-02-03\"")),
                                                      ItExpr.IsAny <CancellationToken>());
        }
示例#15
0
        public async Task BillingRequestHandler_ShouldBeUpdatedBillingInSapAndCreateThePayment_WhenQueueHasOneValidElementAndTransactionApproved()
        {
            var billingValidations = new List <IBillingValidation>
            {
                new BillingForArValidation(Mock.Of <ILogger <BillingForArValidation> >()),
                new BillingForUsValidation(Mock.Of <ILogger <BillingForUsValidation> >())
            };

            var sapConfig = new SapConfig
            {
                SapServiceConfigsBySystem = new Dictionary <string, SapServiceConfig>
                {
                    { "US", new SapServiceConfig {
                          CompanyDB             = "CompanyDb",
                          Password              = "******",
                          UserName              = "******",
                          BaseServerUrl         = "http://123.123.123/",
                          BusinessPartnerConfig = new BusinessPartnerConfig
                          {
                              Endpoint = "BusinessPartners"
                          },
                          BillingConfig = new BillingConfig
                          {
                              Endpoint = "Invoices",
                              NeedCreateIncomingPayments = true,
                              IncomingPaymentsEndpoint   = "IncomingPayments"
                          }
                      } }
                }
            };

            var uriForIncomingPayment = sapConfig.SapServiceConfigsBySystem["US"].BaseServerUrl + sapConfig.SapServiceConfigsBySystem["US"].BillingConfig.IncomingPaymentsEndpoint;

            var sapConfigMock = new Mock <IOptions <SapConfig> >();

            sapConfigMock.Setup(x => x.Value)
            .Returns(sapConfig);

            var timeZoneConfigurations = new TimeZoneConfigurations
            {
                InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time")
            };
            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            var billingMappers = new List <IBillingMapper>
            {
                new BillingForArMapper(Mock.Of <ISapBillingItemsService>(), dateTimeProviderMock.Object, timeZoneConfigurations),
                new BillingForUsMapper(Mock.Of <ISapBillingItemsService>(), dateTimeProviderMock.Object, timeZoneConfigurations)
            };

            var httpMessageHandlerMock = new Mock <HttpMessageHandler>();
            var httpClientFactory      = HttpHelperExtension.GetHttpClientMock(string.Empty, HttpStatusCode.OK, httpMessageHandlerMock);

            var sapTaskHandlerMock = new Mock <ISapTaskHandler>();

            sapTaskHandlerMock.Setup(x => x.TryGetInvoiceByInvoiceIdAndOrigin(It.IsAny <int>(), It.IsAny <string>()))
            .ReturnsAsync(new SapSaleOrderInvoiceResponse {
                CardCode = "0001", DocEntry = 1, DocTotal = 50
            });

            sapTaskHandlerMock.Setup(x => x.StartSession())
            .ReturnsAsync(new SapLoginCookies
            {
                B1Session = "session",
                RouteId   = "route"
            });

            var sapServiceSettingsFactoryMock = new Mock <ISapServiceSettingsFactory>();

            sapServiceSettingsFactoryMock.Setup(x => x.CreateHandler(It.IsAny <string>())).Returns(sapTaskHandlerMock.Object);

            var handler = new BillingRequestHandler(
                sapConfigMock.Object,
                Mock.Of <ILogger <BillingRequestHandler> >(),
                sapServiceSettingsFactoryMock.Object,
                httpClientFactory,
                billingValidations,
                billingMappers);

            var sapTask = new SapTask
            {
                BillingRequest = new SapSaleOrderModel {
                    InvoiceId = 1, TransactionApproved = true, BillingSystemId = 2
                },
                TaskType = Enums.SapTaskEnum.UpdateBilling
            };

            var result = await handler.Handle(sapTask);

            Assert.True(result.IsSuccessful);
            Assert.Equal("Creating/Updating Billing with Payment Request", result.TaskName);

            sapServiceSettingsFactoryMock.Verify(x => x.CreateHandler(It.IsAny <string>()), Times.Exactly(3));
            sapTaskHandlerMock.Verify(x => x.TryGetInvoiceByInvoiceIdAndOrigin(It.IsAny <int>(), It.IsAny <string>()), Times.Once);
            httpMessageHandlerMock.Protected().Verify("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Patch), ItExpr.IsAny <CancellationToken>());
            httpMessageHandlerMock.Protected().Verify("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri == new Uri(uriForIncomingPayment)), ItExpr.IsAny <CancellationToken>());
        }