public IHttpActionResult DeleteSubscriber(int subscriberId)
        {
            SubscriberRequest request = new SubscriberRequest
            {
                SubscriberDto = new SubscriberDto {
                    SubscriberId = subscriberId
                }
            };
            List <string>     errors  = ValidateDeleteSubscriber(request);
            SubscriberMessage message = new SubscriberMessage();

            if (errors != null && errors.Any())
            {
                message.ErrorMessage     = SubscriberMessageResource.ValidationErrors;
                message.ErrorType        = ErrorType.ValidationError;
                message.Errors           = new List <string>();
                message.OperationSuccess = false;
                message.Errors.AddRange(errors);
            }
            else
            {
                message = _serviceSubscriberClient.DeleteSubscriber(request);
            }
            return(Json(message));
        }
Example #2
0
        /// <summary>
        /// Atualizar Cartão do Assinante - Update Subscriber Card
        /// </summary>
        /// <param name="body"></param>
        /// <param name="code"> Código do Assinante </param>
        /// <returns></returns>
        public async Task <SubscriberResponse> UpdateSubscriberCard(SubscriberRequest body, string code)
        {
            string json;

            try
            {
                json = JsonConvert.SerializeObject(body);
                JObject jObject = JObject.Parse(json);
                json = jObject["billing_info"].ToString();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            StringContent       stringContent = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await Http_Client.HttpClient.PutAsync($"assinaturas/v1/customers/{code}/billing_infos", stringContent);

            if (!response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content);
                throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode);
            }
            try
            {
                return(JsonConvert.DeserializeObject <SubscriberResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public static SubscriberResponse GetUserSubscriber(SubscriberRequest request)
        {
            Service            client   = new Service();
            SubscriberResponse response = client.GetUserSubscriber(request);

            return(response);
        }
Example #4
0
        private static void Subscribe(IWebHost host)
        {
            var channel = GrpcChannel.ForAddress(EndpointsConstants.BrokerAddres);
            var client  = new Subscriber.SubscriberClient(channel);

            Console.Write("Enter the topic: ");
            var topic = Console.ReadLine().ToLower();

            var address = host.ServerFeatures.Get <IServerAddressesFeature>().Addresses.First();

            Console.WriteLine($"Subscriber listening at: {address}");

            var request = new SubscriberRequest()
            {
                Topic = topic, Address = address
            };

            try
            {
                var reply = client.Subscribe(request);
                Console.WriteLine($"Subscriber repl: {reply.IsSuccess}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error subscribing: {e.Message}");
            }
        }
Example #5
0
        /// <summary>
        /// Alterar Assinante - Change Subscriber
        /// </summary>
        /// <param name="body"></param>
        /// <param name="code"> Código do Assinante </param>
        /// <returns></returns>
        public async Task <HttpStatusCode> ChangeSubscriber(SubscriberRequest body, string code)
        {
            string json;

            try
            {
                json = JsonConvert.SerializeObject(body);
                JObject jObject = JObject.Parse(json);
                jObject["address"]["streetNumber"].Rename("number");
                jObject["address"]["zipCode"].Rename("zipcode");
                json = jObject.ToString();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            StringContent       stringContent = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await Http_Client.HttpClient.PutAsync($"assinaturas/v1/customers/{code}", stringContent);

            if (!response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content);
                throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode);
            }
            return(response.StatusCode);
        }
Example #6
0
        public override Task <SubscriberReply> Subscribe(SubscriberRequest request, ServerCallContext context)
        {
            Console.WriteLine($"New client trying to subscribe: {request.Address} {request.Topic}");

            try
            {
                var connect = new Connection(request.Address, request.Topic);
                _connectionStorageService.Add(connect);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Could not add the new connection {request.Address} {request}. {e.Message}");
            }

            var connection = new Connection(request.Address, request.Topic);

            _connectionStorageService.Add(connection);

            Console.WriteLine($"New client subscribed: {request.Address} {request.Topic}");

            return(Task.FromResult(new SubscriberReply()
            {
                IsSuccess = true
            }));
        }
 /// <summary>
 ///    From Subscriber Request to Subscriber Request pivot.
 /// </summary>
 /// <param name="request"></param>
 /// <returns>Subscriber Request pivot result.</returns>
 public static SubscriberRequestPivot ToPivot(this SubscriberRequest request)
 {
     return(new SubscriberRequestPivot()
     {
         SubscriberPivot = request.SubscriberDto?.ToPivot(),
         FindSubscriberPivot = Utility.EnumToEnum <FindSubscriberDto, FindSubscriberPivot>(request.FindSubscriberDto)
     });
 }
        private void Subscribe()
        {
            Client <SubscriptionServiceClient> c = null;
            SubscriptionRequest subRequest       = null;

            try
            {
                if ((null != this._systemName) && (null != this._systemUri))
                {
                    c = ExternalClientFactory.ConstructSubscriptionServiceClient(ExternalLib.Endpoint.SubscriptionEndpointName, ExternalLib.Endpoint.ExternalUserName, ExternalLib.Endpoint.ExternalUserPassword);

                    subRequest               = new SubscriptionRequest();
                    subRequest.SystemName    = this._systemName;
                    subRequest.UriCollection = new Uri[] { this._systemUri };

                    SubscribeToEndpointEventsRequest request = new SubscribeToEndpointEventsRequest();
                    request.SubscriptionRequest = subRequest;

                    c.ServiceClient.SubscribeToEndpointEvents(request);
                    c.ServiceClient.Close();
                }
            }
            catch (FaultException <Itron.Ami.Facade.WebServices.Subscriptions.V200908.ClientProxy.DuplicateSubscriberFault> )
            {
                bool duplicate = false;

                // Subscription already exists (i.e. a data subscription with the same system name already exists)
                // we need to determine whether or not we're going to add this endpoint to the subscription.
                try
                {
                    SubscriberRequest req = new SubscriberRequest();
                    req.SystemName = this._systemName;
                    req.Uri        = this._systemUri;

                    c.ServiceClient.AddEventSubscriberEndpointAddress(req);
                    c.ServiceClient.Close();
                }
                catch (FaultException <Itron.Ami.Facade.WebServices.Subscriptions.V200908.ClientProxy.DuplicateSubscriberEndpointFault> )
                {
                    // Ok, it's clear now that the subscription already exists and that this endpoint address is already a part of that
                    // subscription.  So, we're good to go.
                    duplicate = true;
                }

                if (!duplicate)
                {
                    throw;
                }
            }
            finally
            {
                if ((null != c) && (null != c.ServiceClient) &&
                    (c.ServiceClient.State != CommunicationState.Closed))
                {
                    c.ServiceClient.Close();
                }
            }
        }
        /// <summary>
        /// Validation delete subscriber.
        /// </summary>
        /// <param name="request">the request to validate.</param>
        /// <returns>errors validation</returns>
        private List <string> ValidateFindSubscribers(SubscriberRequest request)
        {
            var errors = new List <string>();

            if (request?.SubscriberDto == null)
            {
                errors.Add(SubscriberMessageResource.NullRequest);
            }
            else
            {
                errors.AddRange(GenericValidationAttribute <SubscriberDto> .ValidateAttributes("SubscriberId", request.SubscriberDto.SubscriberId.ToString()));
            }
            return(errors);
        }
Example #10
0
        public static SubscriberResponse GetUserSubscriber(SubscriberRequest request)
        {
            SubscriberResponse response = new SubscriberResponse();

            using (SqlConnection con = new SqlConnection(Variables.PaymentSystemDBConnection))
            {
                try
                {
                    con.Open();
                    using (SqlCommand cmd = new SqlCommand(SQLConstants.SP_GET_USER_SUBSCRIBER, con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@IDENTIFICATION_TAX_NUMBER", request.IdentificationTaxNumber);

                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = cmd;
                        DataTable table = new DataTable();
                        adapter.Fill(table);

                        if (table.Rows.Count > 0)
                        {
                            response.SubscriberId            = Convert.ToInt32(table.Rows[0]["SUBSCRIBER_ID"]);
                            response.Name                    = table.Rows[0]["NAME"].ToString();
                            response.Surname                 = table.Rows[0]["SURNAME"].ToString();
                            response.SubscriberTypeId        = Convert.ToInt32(table.Rows[0]["SUBSCRIBER_TYPE_ID"]);
                            response.SubscriberTypeName      = table.Rows[0]["SUBSCRIBER_TYPE_NAME"].ToString();
                            response.IdentificationTaxNumber = table.Rows[0]["IDENTIFICATION_TAX_NUMBER"].ToString();
                            response.SubscriptionId          = Convert.ToInt32(table.Rows[0]["SUBSCRIPTION_ID"]);
                            response.SubscriptionType        = table.Rows[0]["SUBSCRIPTION_TYPE"].ToString();
                            response.Active                  = Convert.ToBoolean(table.Rows[0]["ACTIVE"]);
                            response.InsertUser              = table.Rows[0]["INSERT_USER"].ToString();
                            response.InsertDate              = Convert.ToDateTime(table.Rows[0]["INSERT_DATE"].ToString());
                            response.UpdateUser              = table.Rows[0]["UPDATE_USER"].ToString();
                            if (!String.IsNullOrEmpty(table.Rows[0]["UPDATE_DATE"].ToString()))
                            {
                                response.UpdateDate = Convert.ToDateTime(table.Rows[0]["UPDATE_DATE"].ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            return(response);
        }
        /// <summary>
        /// Delete Subscriber
        /// </summary>
        /// <param name="request">subscriber request.</param>
        /// <returns>Subscriber message.</returns>
        public SubscriberMessage DeleteSubscriber(SubscriberRequest request)
        {
            SubscriberMessage message = new SubscriberMessage();

            try
            {
                _serviceSubscriber.DeleteSubscriber(request.ToPivot());
                message.OperationSuccess = true;
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
        /// <summary>
        /// Validation update subscriber.
        /// </summary>
        /// <param name="request">the request to validate.</param>
        /// <returns>errors validation</returns>
        private List <string> ValidateUpdateSubscriber(SubscriberRequest request)
        {
            var errors = new List <string>();

            if (request?.SubscriberDto == null)
            {
                errors.Add(SubscriberMessageResource.NullRequest);
            }
            else
            {
                errors.AddRange(GenericValidationAttribute <SubscriberDto> .ValidateAttributes("SubscriberEmail", request.SubscriberDto.SubscriberEmail));
                errors.AddRange(GenericValidationAttribute <SubscriberDto> .ValidateAttributes("SubscriberLastName", request.SubscriberDto.SubscriberLastName));
                errors.AddRange(GenericValidationAttribute <SubscriberDto> .ValidateAttributes("SubscriberFirstName", request.SubscriberDto.SubscriberFirstName));
            }
            return(errors);
        }
Example #13
0
        //https://mcqtvlg3hv4lyvz2nhqb0-r5jspq.soap.marketingcloudapis.com/Service.asmx
        public async Task <string> FindSubscriber(SubscriberRequest request)
        {
            var soapString = ConstructSoapRequest(request.Email, request.Access_Token);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("SOAPAction", "Retrieve");
                var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
                using (var response = await client.PostAsync(request.URI, content))
                {
                    var soapResponse = await response.Content.ReadAsStringAsync();

                    return(ParseSoapResponse(soapResponse));
                }
            }
        }
        public IHttpActionResult FindSubscribers(SubscriberRequest request)
        {
            List <string>     errors  = ValidateFindSubscribers(request);
            SubscriberMessage message = new SubscriberMessage();

            if (errors != null && errors.Any())
            {
                message.ErrorMessage     = SubscriberMessageResource.ValidationErrors;
                message.ErrorType        = ErrorType.ValidationError;
                message.Errors           = new List <string>();
                message.OperationSuccess = false;
                message.Errors.AddRange(errors);
            }
            else
            {
                message = _serviceSubscriberClient.FindSubscribers(request);
            }
            return(Json(message));
        }
        private void Unsubscribe()
        {
            Client <SubscriptionServiceClient> c = null;

            try
            {
                if ((null != this._systemName) && (null != this._systemUri))
                {
                    c = ExternalClientFactory.ConstructSubscriptionServiceClient(ExternalLib.Endpoint.SubscriptionEndpointName, ExternalLib.Endpoint.ExternalUserName, ExternalLib.Endpoint.ExternalUserPassword);

                    SubscriberRequest req = new SubscriberRequest();
                    req.SystemName = this._systemName;
                    req.Uri        = this._systemUri;

                    c.ServiceClient.DeleteEventSubscriberEndpointAddress(req);
                    c.ServiceClient.Close();
                }
            }
            catch (FaultException <Itron.Ami.Facade.WebServices.Subscriptions.V200908.ClientProxy.ArgumentFault> )
            {
                // Looks like this is the last endpoint for the service.  So, we'll simply cancel the subscription at this point.

                CancelEventSubscriptionRequest request = new CancelEventSubscriptionRequest();
                request.SystemName = this._systemName;
                c.ServiceClient.CancelEventSubscription(request);
                c.ServiceClient.Close();
            }
            catch (FaultException <Itron.Ami.Facade.WebServices.Subscriptions.V200908.ClientProxy.SubscriberEndpointNotFoundFault> )
            {
            }
            catch (FaultException <Itron.Ami.Facade.WebServices.Subscriptions.V200908.ClientProxy.SubscriberNotFoundFault> )
            {
            }
            finally
            {
                if ((null != c) && (null != c.ServiceClient) &&
                    (c.ServiceClient.State != CommunicationState.Closed))
                {
                    c.ServiceClient.Close();
                }
            }
        }
Example #16
0
 public SubscriberResponse GetUserSubscriber(SubscriberRequest request)
 {
     return(DBLayer.GetUserSubscriber(request));
 }