Exemple #1
0
        public ManagerResponse <ServiceProviderResult, string> GetPaymentClientToken()
        {
            var request           = new ServiceProviderRequest();
            var clientTokenResult = this.paymentServiceProvider.RunPipeline <ServiceProviderRequest, PaymentClientTokenResult>("commerce.payments.getClientToken", request);

            return(new ManagerResponse <ServiceProviderResult, string>(clientTokenResult, clientTokenResult.ClientToken));
        }
Exemple #2
0
        public async Task <ServiceProviderResponse> OnRequestAsync(ServiceProviderRequest request)
        {
            var trackingId = request.Headers[Constants.OperationTrackingIdHeader].FirstOrDefault();

            try
            {
                SocialProviderEventSource.Current.Info(trackingId, this, nameof(this.OnRequestAsync), OperationStates.Received, request.Path);

                return(await this.dispatcher.DispatchAsync(
                           request.HttpMethod,
                           request.Path,
                           request.Content,
                           request.Headers,
                           request.QueryNameValuePairs));
            }
            catch (SocialChannelExceptionBase ex)
            {
                ExceptionHandler.ProcessException(this, ex, trackingId);
                throw ex.ToGenericException();
            }
            catch (Exception ex)
            {
                ExceptionHandler.ProcessException(this, ex, trackingId);
                throw;
            }
        }
Exemple #3
0
        public ManagerResponse <PaymentClientTokenResult, string> GetPaymentClientToken()
        {
            var request = new ServiceProviderRequest();
            var result  = PaymentServiceProvider.RunPipeline <ServiceProviderRequest, PaymentClientTokenResult>("commerce.payments.getClientToken", request);

            result.WriteToSitecoreLog();

            return(new ManagerResponse <PaymentClientTokenResult, string>(result, result.ClientToken));
        }
        public ServiceProviderResponse SaveServiceProvider(ServiceProviderRequest request)
        {
            Logger.Current.Verbose("Request to insert communicationlogindetails for specific contact.");

            ServiceProvider serviceProviders = Mapper.Map <ServiceProviderViewModel, ServiceProvider>(request.ServiceProviderViewModel);

            serviceProviderRepository.Insert(serviceProviders);
            unitOfWork.Commit();
            return(new ServiceProviderResponse());
        }
        public ServiceProviderResponse GetServiceProvider(ServiceProviderRequest request)
        {
            Logger.Current.Verbose("Request to fetch communication logindetails for specific contact.");
            ServiceProviderResponse response        = new ServiceProviderResponse();
            ServiceProvider         serviceProvider = serviceProviderRepository.GetServiceProviders(Convert.ToInt16(request.ServiceProviderViewModel.AccountID), request.ServiceProviderViewModel.CommunicationTypeID, request.ServiceProviderViewModel.MailType);

            if (serviceProvider != null)
            {
                ServiceProviderViewModel ServiceProviderViewModel = Mapper.Map <ServiceProvider, ServiceProviderViewModel>(serviceProvider as ServiceProvider);
                response.ServiceProviderViewModel = ServiceProviderViewModel;
            }

            return(response);
        }
Exemple #6
0
        public ActionResult Index()
        {
            var paymentServiceProvider = new PaymentServiceProvider();

            var request = new ServiceProviderRequest();

            request.SetShopName("CommerceEngineDefaultStorefront");
            request.CurrencyCode = "EUR";

            var result =
                paymentServiceProvider.RunPipeline <ServiceProviderRequest, PaymentClientTokenResult>(
                    "commerce.payments.getClientToken", request);

            return(View(result));
        }
        /// <summary>
        /// Gets the payment client token.
        /// </summary>
        /// <returns>The manager response where the payment client token is returned in the Result.</returns>
        public ManagerResponse <PaymentClientTokenResult, string> GetPaymentClientToken()
        {
            var result = new PaymentClientTokenResult {
                Success = false
            };
            var request = new ServiceProviderRequest();

            result = this.PaymentServiceProvider.RunPipeline <ServiceProviderRequest, PaymentClientTokenResult>("commerce.payments.getClientToken", request);

            if (!result.Success)
            {
                Helpers.LogSystemMessages(result.SystemMessages, result);
            }

            return(new ManagerResponse <PaymentClientTokenResult, string>(result, result.ClientToken));
        }
 public async Task <ServiceProviderResponse> OnRequestAsync(ServiceProviderRequest request)
 {
     try
     {
         this.otpRequest = request;
         return(await this.dispatcher.DispatchAsync(
                    request.HttpMethod,
                    request.Path,
                    request.Content,
                    request.Headers,
                    request.QueryNameValuePairs));
     }
     catch (Exception ex)
     {
         ExceptionHandler.ProcessException(this, ex, request.Headers[EngagementFabric.Common.Constants.OperationTrackingIdHeader].FirstOrDefault());
         throw;
     }
 }
Exemple #9
0
        protected async Task <HttpResponseMessage> OnRequestAsync(string providerType)
        {
            var account        = RequestHelper.ParseAccount(this.Request);
            var subscriptionId = await RequestHelper.GetSubscriptionId(account);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                // Get provider
                var provider = ProviderManager.GetServiceProvider(providerType);
                Validator.IsTrue <ArgumentException>(provider != null, nameof(providerType), "The provider type '{0}' is invalid.", providerType);

                var path = ParseServicePath(this.Request.RequestUri, providerType);

                // Build request
                var request = new ServiceProviderRequest
                {
                    HttpMethod          = this.Request.Method.Method,
                    Path                = path,
                    Content             = await this.Request.Content.ReadAsStringAsync(),
                    Headers             = this.Request.Headers.ToDictionary(pair => pair.Key, pair => pair.Value),
                    QueryNameValuePairs = this.Request.GetQueryNameValuePairs(),
                    // comment by jin: this is where apiVersion is validated
                    ApiVersion = ApiVersionHelper.GetApiVersion(this.Request.RequestUri)
                };

                // Dispatch
                var result = await provider.OnRequestAsync(request);

                // Build response
                var response = new HttpResponseMessage(result.StatusCode)
                {
                    Content = result.Content != null && result.MediaType != null
                        ? new StringContent(result.Content, Encoding.UTF8, result.MediaType)
                        : null
                };

                if (result.Headers != null && result.Headers.Count >= 0)
                {
                    foreach (var header in result.Headers)
                    {
                        response.Headers.Add(header.Key, header.Value);
                    }
                }

                if (response.IsSuccessStatusCode)
                {
                    MetricManager.Instance.LogRequestSuccess(1, account, subscriptionId, providerType);
                }

                return(response);
            }
            catch
            {
                throw;
            }
            finally
            {
                stopwatch.Stop();
                MetricManager.Instance.LogRequestLatency(stopwatch.ElapsedMilliseconds, account, subscriptionId, providerType);
            }
        }
Exemple #10
0
        public async Task <ServiceProviderResponse> OtpPushAsync(string account, OtpPushDescription description, ServiceProviderRequest request, string requestId, CancellationToken cancellationToken)
        {
            var channel     = OtpChannelHelper.Format(description.Channel);
            var smsProvider = ProviderManager.GetSmsServiceProvider();

            // Check if templete type is 2
            var smsGetRequest = new ServiceProviderRequest
            {
                HttpMethod          = "GET",
                Path                = "templates/" + description.TemplateName,
                Content             = string.Empty,
                Headers             = request.Headers,
                QueryNameValuePairs = request.QueryNameValuePairs,
            };
            var subscriptionId = await RequestHelper.GetSubscriptionId(account);

            try
            {
                var result = await smsProvider.OnRequestAsync(smsGetRequest);

                var    projson = JObject.Parse(result.Content);
                JToken tpltype;
                if (projson.TryGetValue("tplType", out tpltype) && ((int)tpltype != 2))
                {
                    throw new ArgumentException($"Invalid template type.");
                }

                // generate otpCode
                var code = GetOtpCode((int)description.CodeLength);

                // prepare messageSendRequest for sending request to sms provider
                MessageSendRequest messageSendRequest = new MessageSendRequest()
                {
                    Targets = new List <string>()
                    {
                        description.PhoneNumber
                    },
                    MessageBody = new MessageTemplateBody()
                    {
                        TemplateName       = description.TemplateName,
                        TemplateParameters = new PropertyCollection <string>()
                    }
                };
                messageSendRequest.MessageBody.TemplateParameters.Add("otpcode", code);
                var content = JsonConvert.SerializeObject(messageSendRequest);

                // create request for sms provider
                var smsRequest = new ServiceProviderRequest
                {
                    HttpMethod          = "POST",
                    Path                = "messages",
                    Content             = content,
                    Headers             = request.Headers,
                    QueryNameValuePairs = request.QueryNameValuePairs
                };

                // send push request to sms provider
                result = await smsProvider.OnRequestAsync(smsRequest);

                if (result.StatusCode != HttpStatusCode.OK)
                {
                    return(result);
                }

                // Create otp record in db
                var otpcode = await this.otpStore.CreateorUpdateOtpCodeAsync(account, description.PhoneNumber, code, (int)description.ExpireTime);

                // Create otp check history in otp storage table
                await this.otpStorage.CreateOtpCodeHistoryRecord(account, description.PhoneNumber, ActionType.Start.ToString(), DateTime.UtcNow);

                this.metricManager.LogOtpSendSuccess(1, account, subscriptionId, description.Channel);
                OtpProviderEventSource.Current.Info(requestId, this, nameof(this.OtpPushAsync), OperationStates.Succeeded, $"account: {account}, channel: {channel}, phoneNumber: {description.PhoneNumber}");
                return(new ServiceProviderResponse
                {
                    StatusCode = HttpStatusCode.OK,
                    JsonContent = new OtpStartOperationResult
                    {
                        ExpireTime = (int)description.ExpireTime
                    }
                });
            }
            catch (Exception ex)
            {
                this.metricManager.LogOtpSendFailed(1, account, subscriptionId, description.Channel);
                while (ex is AggregateException)
                {
                    ex = ex.InnerException;
                }

                OtpProviderEventSource.Current.ErrorException(requestId, this, nameof(this.OtpPushAsync), OperationStates.Failed, $"Failed to send OTP code for account: {account}, channel: {channel}, phoneNumber: {description.PhoneNumber}", ex);

                if ((ex is ArgumentException) || (ex is QuotaExceededException))
                {
                    throw ex;
                }

                throw new Exception(string.Format($"Failed to send OTP code for account: {account}, channel: {channel}, phoneNumber: {description.PhoneNumber}"));
            }
        }