public void ConstructorAndFields()
        {
            ListChargesDates obj = new ListChargesDates();

            Assert.IsNotNull(obj);
            Assert.IsNull(obj.BeginDueDate);
            Assert.IsNull(obj.EndDueDate);
            Assert.IsNull(obj.BeginPaymentDate);
            Assert.IsNull(obj.EndPaymentDate);
            Assert.IsNull(obj.BeginPaymentConfirmation);
            Assert.IsNull(obj.EndPaymentConfirmation);

            obj.BeginDueDate             = DateTime.MinValue;
            obj.EndDueDate               = DateTime.MaxValue;
            obj.BeginPaymentDate         = DateTime.MinValue;
            obj.EndPaymentDate           = DateTime.MaxValue;
            obj.BeginPaymentConfirmation = DateTime.MinValue;
            obj.EndPaymentConfirmation   = DateTime.MaxValue;
            Assert.AreEqual(DateTime.MinValue, obj.BeginDueDate);
            Assert.AreEqual(DateTime.MaxValue, obj.EndDueDate);
            Assert.AreEqual(DateTime.MinValue, obj.BeginPaymentDate);
            Assert.AreEqual(DateTime.MaxValue, obj.EndPaymentDate);
            Assert.AreEqual(DateTime.MinValue, obj.BeginPaymentConfirmation);
            Assert.AreEqual(DateTime.MaxValue, obj.EndPaymentConfirmation);
        }
        public ListChargesResponse ListCharges(ListChargesDates dates, ResponseType responseType = ResponseType.JSON)
        {
            StringBuilder requestUri = new StringBuilder($"{EndPoint}/list-charges?");

            AddRequestParameters(requestUri, RequestType.ListCharges, dates);
            return(Request <ListChargesResponse>(requestUri, responseType));
        }
        void ListCharges()
        {
            ListChargesDates dates = new ListChargesDates();

            dates.BeginDueDate = DateTime.Today.AddDays(1);
            dates.EndDueDate   = DateTime.Today.AddDays(5);

            try
            {
                var response = boletoFacil.ListCharges(dates);
                ShowObjectResponseHeader();
                foreach (Charge c in response.Data.Charges)
                {
                    Console.WriteLine("");
                    Console.WriteLine(c);
                }
                ShowResponseSerialized(response);
            }
            catch (BoletoFacilException e)
            {
                HandleException(e);
            }
            finally
            {
                DoneMessage();
            }
        }
Exemple #4
0
#pragma warning disable CS1591 // Comentário XML ausente para tipo publicamente visível ou membro "BoletoFacil.ListCharges(ListChargesDates, ResponseType)"
        public ListChargesResponse ListCharges(ListChargesDates dates, ResponseType responseType = ResponseType.JSON)
#pragma warning restore CS1591 // Comentário XML ausente para tipo publicamente visível ou membro "BoletoFacil.ListCharges(ListChargesDates, ResponseType)"
        {
            StringBuilder requestUri = new StringBuilder($"{EndPoint}/list-charges?");

            AddRequestParameters(requestUri, RequestType.ListCharges, dates);
            return(Request <ListChargesResponse>(requestUri, responseType));
        }
 void AddListChargeParameters(StringBuilder requestUri, ListChargesDates dates)
 {
     AddUriParameter(requestUri, "beginDueDate", $"{dates.BeginDueDate:dd/MM/yyyy}");
     AddUriParameter(requestUri, "endDueDate", $"{dates.EndDueDate:dd/MM/yyyy}");
     AddUriParameter(requestUri, "beginPaymentDate", $"{dates.BeginPaymentDate:dd/MM/yyyy}");
     AddUriParameter(requestUri, "endPaymentDate", $"{dates.EndPaymentDate:dd/MM/yyyy}");
     AddUriParameter(requestUri, "beginPaymentConfirmation", $"{dates.BeginPaymentConfirmation:dd/MM/yyyy}");
     AddUriParameter(requestUri, "endPaymentConfirmation", $"{dates.EndPaymentConfirmation:dd/MM/yyyy}");
 }
Exemple #6
0
        //public PublicKeyResponse GetPublicEncryptionKey(ResponseType responseType = ResponseType.JSON)
        //{
        //    StringBuilder requestUri = new StringBuilder($"{EndPoint}/get-public-encryption-key.json?");
        //    AddRequestParameters(requestUri, RequestType.GetPublicEncryptionKey, null);
        //    return Request<PublicKeyResponse>(requestUri, responseType);
        //}

        //public CardHashResponse GetCreditCardHash(ResponseType responseType = ResponseType.JSON)
        //{
        //    StringBuilder requestUri = new StringBuilder($"{EndPoint}/get-credit-card-hash.json?");
        //    AddRequestParameters(requestUri, RequestType.GetCreditCardHash, null);
        //    return Request<CardHashResponse>(requestUri, responseType);
        //}

        #endregion

        #region AddRequestParameters methods

        void AddRequestParameters(StringBuilder requestUri, RequestType requestType, ModelBase entity)
        {
            AddTokenUriParameter(requestUri);
            switch (requestType)
            {
            case RequestType.IssueCharge:
                Charge chargeToIssue = entity as Charge;
                AddIssueChargeParameters(requestUri, chargeToIssue);
                break;

            case RequestType.RequestTransfer:
                Transfer transfer = entity as Transfer;
                AddRequestTransferParameters(requestUri, transfer);
                break;

            case RequestType.ListCharges:
                ListChargesDates dates = entity as ListChargesDates;
                AddListChargeParameters(requestUri, dates);
                break;

            case RequestType.FetchBalance:
                break;

            case RequestType.CancelCharge:
                Charge chargeToCancel = entity as Charge;
                AddCancelChargeParameters(requestUri, chargeToCancel);
                break;

            case RequestType.CreatePayee:
                Payee payeeToCreate = entity as Payee;
                AddCreatePayeeParameters(requestUri, payeeToCreate);
                break;

            case RequestType.CreatePayeeFeeSchema:
                Split split = entity as Split;
                AddCreatePayeeFeeSchemaParameters(requestUri, split);
                break;

            case RequestType.GetPayeeStatus:
                Payee payeeToGetStatus = entity as Payee;
                AddGetPayeeStatusParameters(requestUri, payeeToGetStatus);
                break;

            case RequestType.CardTokenization:
                Charge creditCardHash = entity as Charge;
                AddCardTokenizationParameters(requestUri, creditCardHash);
                break;
            }
            //AddPublicTokenUriParameter(requestUri);
            //switch (requestType)
            //{

            //}
        }
        public void ListChargesErrorNoDatesInformed()
        {
            BoletoFacil      boletoFacil = GetBoletoFacil();
            ListChargesDates dates       = new ListChargesDates();

            BoletoFacilRequestException response = AssertException <BoletoFacilRequestException>(() => boletoFacil.ListCharges(dates));

            Assert.IsNotNull(response);
            Assert.AreEqual(400, response.HTTPStatusCode);
            Assert.IsFalse(response.Error.Success);
            Assert.AreEqual("Favor informar a data de início de vencimento ou de pagamento", response.Error.ErrorMessage);
        }
        public void ListCharges()
        {
            BoletoFacil      boletoFacil = GetBoletoFacil();
            ListChargesDates dates       = ListChargesDates;

            ListChargesResponse response = boletoFacil.ListCharges(dates);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);

            Assert.AreEqual(3, response.Data.Charges.Length);

            Assert.IsInstanceOfType(response.Data.Charges[0], typeof(Charge));
            Assert.AreEqual("101", response.Data.Charges[0].Code);
            Assert.AreEqual(StartDate.Date, response.Data.Charges[0].DueDate.Date);
            Assert.AreEqual(BaseUrl, response.Data.Charges[0].Link.Substring(0, BaseUrl.Length));
            Assert.AreEqual("03399.63290 64000.001014 00236.601027 8 67150000025000", response.Data.Charges[0].PayNumber);
            Assert.AreEqual(1, response.Data.Charges[0].Payments.Length);
            Assert.IsInstanceOfType(response.Data.Charges[0].Payments[0], typeof(Payment));
            Assert.AreEqual(1113123, response.Data.Charges[0].Payments[0].Id);
            Assert.AreEqual(163.9m, response.Data.Charges[0].Payments[0].Amount);
            Assert.AreEqual(StartDate.Date, response.Data.Charges[0].Payments[0].Date);
            Assert.AreEqual(4.34m, response.Data.Charges[0].Payments[0].Fee);
            Assert.AreEqual(PaymentType.BOLETO, response.Data.Charges[0].Payments[0].Type);
            Assert.AreEqual(PaymentStatus.CONFIRMED, response.Data.Charges[0].Payments[0].Status);

            Assert.IsInstanceOfType(response.Data.Charges[1], typeof(Charge));
            Assert.AreEqual("102", response.Data.Charges[1].Code);
            Assert.AreEqual(StartDate.Date.AddDays(1), response.Data.Charges[1].DueDate);
            Assert.AreEqual(BaseUrl, response.Data.Charges[1].Link.Substring(0, BaseUrl.Length));
            Assert.AreEqual("03399.63290 64000.001024 00236.601027 3 67150000015000", response.Data.Charges[1].PayNumber);
            Assert.AreEqual(2, response.Data.Charges[1].Payments.Length);
            Assert.IsInstanceOfType(response.Data.Charges[1].Payments[0], typeof(Payment));
            Assert.AreEqual(1113124, response.Data.Charges[1].Payments[0].Id);
            Assert.AreEqual(1141.4m, response.Data.Charges[1].Payments[0].Amount);
            Assert.AreEqual(StartDate.Date.AddDays(1), response.Data.Charges[1].Payments[0].Date);
            Assert.AreEqual(27.8m, response.Data.Charges[1].Payments[0].Fee);
            Assert.AreEqual(PaymentType.BOLETO, response.Data.Charges[1].Payments[0].Type);
            Assert.AreEqual(PaymentStatus.CONFIRMED, response.Data.Charges[1].Payments[0].Status);
            Assert.IsInstanceOfType(response.Data.Charges[1].Payments[1], typeof(Payment));
            Assert.AreEqual(1113125, response.Data.Charges[1].Payments[1].Id);
            Assert.AreEqual(1141.5m, response.Data.Charges[1].Payments[1].Amount);
            Assert.AreEqual(StartDate.Date.AddDays(2), response.Data.Charges[1].Payments[1].Date);
            Assert.AreEqual(27.85m, response.Data.Charges[1].Payments[1].Fee);
            Assert.AreEqual(PaymentType.CREDIT_CARD, response.Data.Charges[1].Payments[1].Type);
            Assert.AreEqual(PaymentStatus.CONFIRMED, response.Data.Charges[1].Payments[1].Status);

            Assert.AreEqual("103", response.Data.Charges[2].Code);
            Assert.AreEqual(StartDate.Date.AddDays(1), response.Data.Charges[2].DueDate);
            Assert.AreEqual(BaseUrl, response.Data.Charges[2].Link.Substring(0, BaseUrl.Length));
            Assert.AreEqual("03399.63290 64000.001024 00236.601027 3 67150000014000", response.Data.Charges[2].PayNumber);
            Assert.AreEqual(0, response.Data.Charges[2].Payments.Length);
        }
        void AddRequestParameters(StringBuilder requestUri, RequestType requestType, ModelBase entity)
        {
            AddTokenUriParameter(requestUri);
            switch (requestType)
            {
            case RequestType.IssueCharge:
                Charge chargeToIssue = entity as Charge;
                AddIssueChargeParameters(requestUri, chargeToIssue);
                break;

            case RequestType.RequestTransfer:
                Transfer transfer = entity as Transfer;
                AddRequestTransferParameters(requestUri, transfer);
                break;

            case RequestType.ListCharges:
                ListChargesDates dates = entity as ListChargesDates;
                AddListChargeParameters(requestUri, dates);
                break;

            case RequestType.FetchBalance:
                break;

            case RequestType.CancelCharge:
                Charge chargeToCancel = entity as Charge;
                AddCancelChargeParameters(requestUri, chargeToCancel);
                break;

            case RequestType.CreatePayee:
                Payee payeeToCreate = entity as Payee;
                AddCreatePayeeParameters(requestUri, payeeToCreate);
                break;

            case RequestType.CreatePayeeFeeSchema:
                Split split = entity as Split;
                AddCreatePayeeFeeSchemaParameters(requestUri, split);
                break;

            case RequestType.GetPayeeStatus:
                Payee payeeToGetStatus = entity as Payee;
                AddGetPayeeStatusParameters(requestUri, payeeToGetStatus);
                break;

            case RequestType.FetchPaymentDetails:
                var paymentToGetDetails = entity as Payment;
                AddCreateFetchPaymentDetailsParameters(requestUri, paymentToGetDetails);
                break;
            }
        }