Beispiel #1
0
        private BaseRequest GetRecRequest(BaseEngineStartUpParameter parameter)
        {
            BaseRequest rec = null;

            switch (parameter.EType)
            {
            case EngineType.PARA:
            case EngineType.OPEN:
            {
                var openParameter = (EngineStartUpQsOpenParameter)parameter;
                rec = new recRequest()
                {
                    coreType                  = openParameter.EType,
                    refText                   = openParameter.RefText,
                    keywords                  = openParameter.KeyWords,
                    qClass                    = openParameter.QsClass,
                    qType                     = openParameter.QsType,
                    precision                 = openParameter.Precision,
                    scale                     = parameter.Scale,
                    getParam                  = parameter.getParam,
                    attachAudioUrl            = parameter.attachAudioUrl,
                    paragraph_need_word_score = parameter.paragraph_need_word_score,
                };
            }
            break;

            case EngineType.WORD:
            {
                var openParameter = (EngineStartUpSingleParameter)parameter;
                rec = new commonRequest()
                {
                    coreType       = openParameter.EType,
                    precision      = openParameter.Precision,
                    scale          = parameter.Scale,
                    refText        = openParameter.RefText,
                    attachAudioUrl = parameter.attachAudioUrl,
                    getParam       = parameter.getParam,
                };
            }
            break;

            case EngineType.SENT:
            case EngineType.CHOICE:
            {
                var openParameter = (EngineStartUpSingleParameter)parameter;
                rec = new commonRequest()
                {
                    coreType       = openParameter.EType,
                    precision      = openParameter.Precision,
                    scale          = parameter.Scale,
                    refText        = openParameter.RefText,
                    attachAudioUrl = parameter.attachAudioUrl,
                    getParam       = parameter.getParam,
                };
            }
            break;

            default:
                throw new Exception("Undefined");
            }
            return(rec);
        }
Beispiel #2
0
        /// <summary>
        /// Criação de Pagamento do Pedido
        /// </summary>
        /// <param name="pedido"></param>
        /// <returns>KeyValuePair (TransactionUuid, Message)</returns>
        public static KeyValuePair <string, string> CreatePayment(Pedido pedido)
        {
            #region SoapHeader
            SoapHeader = new PayzenHeader
            {
                ShopId    = ApiShopid,
                RequestId = Guid.NewGuid().ToString(),
                Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"),
                Mode      = ApiMode
            };

            var concatRequestIdTimeStamp = SoapHeader.RequestId + SoapHeader.Timestamp;
            SoapHeader.AuthToken = SecurityHmacSha256.HmacSha256(concatRequestIdTimeStamp, ApiCertificado);
            #endregion

            #region ObjectsRequest
            var common = new commonRequest
            {
                paymentSource           = PaymentSource.EC.ToString(),
                submissionDate          = pedido.DataInsercao,
                submissionDateSpecified = true
            };

            var payment = new paymentRequest
            {
                //transactionId = "0",
                amount            = Convert.ToInt64(pedido.ListaCompra.Total), //não concordo com a conversão
                amountSpecified   = true,
                currency          = 986,                                       //BRL - Real,
                currencySpecified = true
            };
            if (!string.IsNullOrEmpty(pedido?.ListaHistorico?.LastOrDefault(x => !string.IsNullOrEmpty(x.CodigoRetornoTransacao))?.CodigoRetornoTransacao))
            {
                payment.retryUuid = pedido?.ListaHistorico?.LastOrDefault(x => !string.IsNullOrEmpty(x.CodigoRetornoTransacao))?.CodigoRetornoTransacao;
            }

            var order = new orderRequest
            {
                orderId = $"{ApiMode}-{pedido.Id}"
            };

            var card = new cardRequest
            {
                expiryYear           = Convert.ToInt32($"20{pedido.Cartao.Validade.Split('/').LastOrDefault()}"), //2020,
                expiryYearSpecified  = true,
                expiryMonth          = Convert.ToInt32(pedido.Cartao.Validade.Split('/').FirstOrDefault()),       //4,
                expiryMonthSpecified = true,
                cardSecurityCode     = pedido.Cartao.Cvv,                                                         //"123",
                number = pedido.Cartao.NumeroSemMascara,                                                          //"5970100300000018",
                scheme = "MASTERCARD"                                                                             //Core.Resources.Resources.SearchTypeCardByNumber(pedido.Cartao.NumeroSemMascara)
            };
            #endregion

            #region Create - SoapRequest
            var body = Serialization.Serialize(common);
            body += Serialization.Serialize(payment);
            body += Serialization.Serialize(order);
            body += Serialization.Serialize(card);

            var soapEnvelopeXml = CreateSoapEnvelope(UrlHeader, SoapHeader, PayzenMethods.createPayment.ToString(), body);
            var webRequest      = CreateWebRequest(UrlApiWsdl);

            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
            #endregion

            string result;
            using (var response = webRequest.GetResponse())
            {
                using (var rd = new StreamReader(response.GetResponseStream()))
                {
                    result = rd.ReadToEnd();
                }
            }

            //Extraindo o objeto [CreatePaymentResponseCreatePaymentResult]
            if (!result.Contains("createPaymentResult"))
            {
                throw new BusinessRuleException($"Não encontrado [createPaymentResult]: {result}");
            }

            var xml = new XmlDocument();
            xml.LoadXml(result);
            var xmlMethod    = xml.DocumentElement.SelectNodes("//createPaymentResult").Item(0).OuterXml.Replace("createPaymentResult", "createPaymentResponseCreatePaymentResult");
            var methodResult = Serialization.LoadFromXmlString <createPaymentResponseCreatePaymentResult>(xmlMethod);

            TransactionStatus statusPagamento;
            Enum.TryParse(methodResult.commonResponse.transactionStatusLabel, out statusPagamento);

            return(new KeyValuePair <string, string>(methodResult.paymentResponse.transactionUuid,
                                                     $"{(methodResult.commonResponse.responseCode == 0 && statusPagamento == TransactionStatus.AUTHORISED ? "sucesso" : "erro")} - responseCodeDetails [{methodResult.commonResponse.responseCodeDetail}] transactionStatusLabel [{methodResult.commonResponse.transactionStatusLabel}]"));
        }