/// <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}]")); }
public static SimulateOrderWebServiceRequest ToWmSimulateOrderRequest(this StorefrontSimulateOrderRequest clientRequest) { SimulateOrderWebServiceRequest result = new SimulateOrderWebServiceRequest(); const string sapOrderType = "ZWEB"; var header = new Header2() { Version = new Version2() { value = SAP_HEADER_VERSION }, Sender = new Sender2 { Component = sapOrderType, Task = TASK_SIMULATE_REQUEST } }; var requestDetails = new OrderRequestDetail[clientRequest.OrderItems.Count]; for (var i = 0; i < clientRequest.OrderItems.Count; i++) { var lineNum = i + 1; var requestDetail = new OrderRequestDetail { OrderLineNumber = lineNum.ToString(), ProductID = clientRequest.OrderItems[i].ProductID, Quantity = clientRequest.OrderItems[i].Quantity.ToString(), RequestedDate = clientRequest.OrderItems[i].RequestedDate }; requestDetails[i] = requestDetail; } var partners = new Partner3[clientRequest.Partners.Count]; for (var i = 0; i < clientRequest.Partners.Count; i++) { var partner = new Partner3 { id = clientRequest.Partners[i].PartnerType.ToString(), PartnerID = clientRequest.Partners[i].PartnerId, PartnerType = clientRequest.Partners[i].PartnerType.ToString() }; partners[i] = partner; } var orderRequestHeader = new OrderRequestHeader() { SalesOrgID = clientRequest.SalesAreaInfo.SalesOrgId, DistChannelID = clientRequest.SalesAreaInfo.DistChannelId, DivisionID = clientRequest.SalesAreaInfo.DivisionId, language = clientRequest.Language, NumberOfItems = clientRequest.OrderItems.Count.ToString(), PromoCode = clientRequest.PromoCode, Partner = partners }; var bodies = new Body2[1]; bodies[0] = new Body2() { OrderRequestHeader = orderRequestHeader, OrderRequestDetail = requestDetails };; var request = new OrderRequest() { Header = header, Body = bodies }; var payload = new orderRequest() { OrderRequest = request }; result.OrderRequest = payload; return(result); }