Exemple #1
0
        /// <summary>
        /// Call Stone api to gatter payment information and return it.
        /// </summary>
        public async Task <StoneDTO> GetTransaction(StoneRequestData data)
        {
            var stoneData = new StoneDTO();

            if (this.stonePayments != null)
            {
                var stoneReference = this.stonePayments.Where(x => x.Header.ReferenceDate == data.Date.ToString("yyyyMMdd")).FirstOrDefault();
                if (stoneReference != null)
                {
                    return(stoneReference);
                }
            }
            var tokenInfo = this.GetToken();

            using (var client = new HttpClient())
            {
                var request = new HttpRequestMessage(HttpMethod.Get, $"{ConfigurationManager.AppSettings.Get("STONE_HOST")}{data.Date.ToString("yyyyMMdd")}?affiliationCode={ConfigurationManager.AppSettings.Get("AFILIATION_CODE")}");

                //add headers
                request.Headers.Add("Authorization", tokenInfo["authorization"]);
                request.Headers.Add("X-Authorization-Raw-Data", tokenInfo["x-authorization-raw-data"]);
                request.Headers.Add("X-Authorization-Encrypted-Data", tokenInfo["x-authorization-encrypted-data"]);

                var response = await client.SendAsync(request);

                var body = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var xmlBody = new XmlDocument();
                    xmlBody.LoadXml(body);
                    stoneData.FinancialTransactions.Transaction = this.xmlHandler.ExtractFinancialTransactions(xmlBody).ToArray();
                    stoneData.FinancialTransactionsAccounts     = this.xmlHandler.ExtractFinancialAccount(xmlBody);
                    stoneData.Header   = this.xmlHandler.ExtractHeader(xmlBody);
                    stoneData.Payments = this.xmlHandler.ExtractPayments(xmlBody);

                    this.stonePayments.Add(stoneData);

                    return(stoneData);
                }

                throw new Exception($"erro ao consultar api Stone: {response.StatusCode}: {response.ReasonPhrase}");
            }
        }
Exemple #2
0
        public List <Installment> GetAccountTransactionsByMovement(OFXParser.Entities.Transaction movement, StoneDTO stoneObject)
        {
            var payment = stoneObject.Payments.Payment.Where(x => Convert.ToDouble(x.TotalAmount) == movement.TransactionValue).FirstOrDefault();

            var transactions = stoneObject.FinancialTransactionsAccounts.Transaction.Where(x => x.Installments.Installment.Any(y => y.PaymentId == payment.Id)).ToList();
            var installments = transactions.Select(x => x.Installments.Installment);
            var returnList   = new List <Installment>();

            foreach (Installment[] installment in installments)
            {
                returnList.AddRange(installment);
            }

            return(returnList.Distinct().ToList());
        }