Ejemplo n.º 1
0
        public static ClientRequestResponseBase ThrowError(string error, ClientRequestResponseBase entity)
        {
            ClientRequestResponseBase response = new ClientRequestResponseBase();
            if (entity is PaymentNotificationRequest)
            {
                PaymentNotificationResponse apn = new PaymentNotificationResponse();
                apn.DistributorCostCenterId = entity.DistributorCostCenterId;
                apn.StatusCode = "Error";
                apn.StatusDetail = error;
                response = apn;
            }
            else if (entity is PaymentInstrumentRequest)
            {
                PaymentInstrumentResponse pi = new PaymentInstrumentResponse();
                pi.StatusCode = "Error";
                pi.StatusDetail = error;
                response = pi;
            }
            else if (entity is PaymentRequest)
            {
                PaymentResponse apr = new PaymentResponse();
                apr.StatusCode = "Error";
                apr.StatusDetail = error;
                response = apr;
            }
            else if(entity is DocSMSResponse)
            {
                DocSMSResponse sms = new DocSMSResponse();
                sms.SdpResponseCode = "Error";
                sms.SdpResponseStatus = error;
                response = sms;
            }

            return response;
        }
Ejemplo n.º 2
0
        public bool SaveResponse(DocSMSResponse response)
        {
            tblSms tsms = _ctx.tblSms.FirstOrDefault(n => n.Id == response.Id);
            if(tsms != null)
            {
                tsms.SdpDestinationResponses = JsonConvert.SerializeObject(response.SdpDestinationResponses);
                tsms.SdpRequestId = response.SdpRequestId;
                tsms.SdpStatusCode = response.SdpResponseCode;
                tsms.SdpStatusString = response.SdpResponseStatus;
                tsms.SdpVersion = response.SdpVersion;
                tsms.SmsStatus =  SmsStatuses.Sent.ToString();
                return true;
            }

            return false;
        }
Ejemplo n.º 3
0
        public HttpResponseMessage SendSMS(DocSMS clientSms)
        {
            DocSMSResponse pgresponse = new DocSMSResponse();
            pgresponse.SmsStatus = SmsStatuses.Pending;
            try
            {
                ServiceProvider sp = _resolveMessageService.GetServiceProvider(clientSms.DistributorCostCenterId);
                if (sp == null)
                {
                    pgresponse.SdpResponseStatus = "This service provider is not registered.";
                }
                else
                {
                    ServerRequestBase sdpSms;
                    _resolveMessageService.ProcessClientRequest(clientSms, sp, out sdpSms);
                    SDPSMSResponse sdpResponse = HSenidSend(sdpSms as SDPSMSRequest, clientSms);

                    _docSMSRepository.Save(clientSms);

                    pgresponse.SmsStatus = SmsStatuses.Sent;
                    pgresponse.ClientRequestResponseType = ClientRequestResponseType.SMS;
                    pgresponse.DateCreated = DateTime.Now;
                    pgresponse.DistributorCostCenterId = clientSms.DistributorCostCenterId;
                    pgresponse.TransactionRefId = sdpResponse.requestId;
                    pgresponse.Id = clientSms.Id;
                    pgresponse.SdpVersion = sdpResponse.version;
                    pgresponse.SdpResponseStatus = sdpResponse.statusDetail;
                    pgresponse.SdpResponseCode = sdpResponse.statusCode;
                    pgresponse.SdpDestinationResponses = sdpResponse.destinationResponses;
                    pgresponse.SdpRequestId = sdpResponse.requestId;
                    pgresponse.SmsStatus = SmsStatuses.Sent;

                    _docSMSRepository.SaveResponse(pgresponse);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            return Request.CreateResponse(HttpStatusCode.OK, pgresponse);
        }
Ejemplo n.º 4
0
 public async Task<DocSMSResponse> SendDocSms(DocSMS docSms)
 {
     DocSMSResponse _response = new DocSMSResponse {SmsStatus = SmsStatuses.Pending};
     HttpClient httpClient = setupHttpClient();
     httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     string url = "api/gateway/sms/send";
     try
     {
         var response = await httpClient.PostAsJsonAsync(url, docSms);
         _response = await response.Content.ReadAsAsync<DocSMSResponse>();
     }
     catch (Exception ex)
     {
         string error = "Failed to forward sms for sending.\n" +
                        (ex.InnerException == null ? "" : ex.InnerException.Message);
         _response.SdpResponseCode = "Error";
         _response.SdpResponseStatus = error;
     }
     return _response;
 }