Пример #1
0
        public async Task Create_a_valid_invoice()
        {
            // Arrange
            InvoiceModel invoice;

            var customVariables = new List <CustomVariables>
            {
                new CustomVariables {
                    name = "TaxaIugu", value = "2,50"
                },
                new CustomVariables {
                    name = "TaxaPlataformaEdux", value = "1,00"
                }
            };

            var invoiceDate = DateTime.Now.AddDays(2);

            var customer = new CustomerRequestMessage
            {
                Email           = "*****@*****.**",
                Name            = "Client Name",
                CustomVariables = customVariables
            };

            // Act
            using (var apiInvoice = new Invoice())
                using (var apiCustomer = new Customer())
                    using (var apiSubscription = new Subscription())
                        using (var apiPlan = new Plans())
                        {
                            var customerResponse = await apiCustomer.CreateAsync(customer, null).ConfigureAwait(false);

                            var radomPlan = Guid.NewGuid().ToString();
                            var plan      = await apiPlan.CreateAsync($"{radomPlan}-12x", $"{radomPlan}-Plan", 1, "months", 0, "BRL", null, null, Constants.PaymentMethod.BANK_SLIP).ConfigureAwait(false);

                            var subscriptionItems = new List <SubscriptionSubitem> {
                                new SubscriptionSubitem {
                                    description = "Mensalidade", price_cents = 65000, quantity = 1, recurrent = true
                                }
                            };
                            var subscription = await apiSubscription.CreateAsync(new SubscriptionRequestMessage(customerResponse.id)
                            {
                                PlanId          = plan.identifier,
                                IsCreditBased   = false,
                                CustomVariables = customVariables,
                                Subitems        = subscriptionItems
                            }).ConfigureAwait(false);

                            var invoiceItems = new[] { new Item {
                                                           description = "Mensalidade", price_cents = 65000, quantity = 1
                                                       } };
                            invoice = await apiInvoice.CreateAsync("*****@*****.**", invoiceDate, invoiceItems, null, null, null, 0,
                                                                   0, null, false, subscription.id, null, null, customVariables, _payer)
                                      .ConfigureAwait(false);
                        };

            // Assert
            Assert.That(invoice, Is.Not.Null);
            Assert.That(invoice.due_date, Does.Contain(invoiceDate.ToString("yyyy-MM-dd")));
        }
Пример #2
0
        public async Task Create_a_customer_with_customer_request_with_success()
        {
            // Arrange
            var custom = new List <CustomVariables>();

            custom.Add(new CustomVariables {
                name = "Tipo", value = "Desmanche"
            });
            custom.Add(new CustomVariables {
                name = "Representante", value = "Fabio Munhoz (RJ)"
            });

            CustomerModel myClient;
            var           customer = new CustomerRequestMessage
            {
                Email = "*****@*****.**",
                Name  = "Daniel Teste 2 C#"
            };

            // Act
            using (var apiClient = new Customer())
            {
                myClient = await apiClient.CreateAsync(customer, null).ConfigureAwait(false);
            };

            // Assert
            Assert.That(myClient.email, Is.EqualTo("*****@*****.**"));
            Assert.That(myClient.id, Is.Not.Empty);
        }
Пример #3
0
        public void AddCustomer(CustomerRequestMessage customerRequestMessage)
        {
            if (customerRequestMessage.Key == System.Configuration.ConfigurationManager.AppSettings["ApiKeyLocalHost"])
            {
                if (String.IsNullOrEmpty(customerRequestMessage.Customer.FirstName) || String.IsNullOrEmpty(customerRequestMessage.Customer.LastName) ||
                    String.IsNullOrEmpty(customerRequestMessage.Customer.PhoneNumber) || String.IsNullOrEmpty(customerRequestMessage.Customer.Email))

                {
                    throw new FaultException("You must fill in all fields above");
                }
                customerRepo.CreateCustomer(customerRequestMessage.Customer);
            }
            else
            {
                throw new FaultException("You have enter wrong key");
            }
        }
Пример #4
0
        public async Task Create_a_new_invoice_with_custom_api_token_and_cancel_after()
        {
            // Arrange
            const string customApiToken = "74c265aedbfaea379bc0148fae9b5526";
            InvoiceModel invoice;
            InvoiceModel cancelInvoice;

            var customVariables = new List <CustomVariables>
            {
                new CustomVariables {
                    name = "TaxaIugu", value = "2,50"
                },
                new CustomVariables {
                    name = "TaxaPlataformaEdux", value = "1,00"
                }
            };

            var invoiceDate = DateTime.Now.AddDays(2);
            var newDate     = invoiceDate.AddDays(3).ToString("dd/MM/yyyy");

            var items = new List <InvoiceItem> {
                new InvoiceItem {
                    Description = "Mensalidade", PriceCents = 100000, Quantity = 1
                }
            };

            var customer = new CustomerRequestMessage
            {
                Email           = "*****@*****.**",
                Name            = "Client Name",
                CustomVariables = customVariables
            };

            // Act
            using (var apiInvoice = new Invoice())
                using (var apiCustomer = new Customer())
                    using (var apiSubscription = new Subscription())
                        using (var apiPlan = new Plans())
                        {
                            var customerResponse = await apiCustomer.CreateAsync(customer, null).ConfigureAwait(false);

                            var radomPlan = Guid.NewGuid().ToString();
                            var plan      = await apiPlan.CreateAsync($"{radomPlan}-12x", $"{radomPlan}-Plan", 1, "months", 0, "BRL", null, null, Constants.PaymentMethod.BANK_SLIP).ConfigureAwait(false);

                            var subscriptionItems = new List <SubscriptionSubitem> {
                                new SubscriptionSubitem {
                                    description = "Mensalidade", price_cents = 65000, quantity = 1, recurrent = true
                                }
                            };
                            var subscription = await apiSubscription.CreateAsync(new SubscriptionRequestMessage(customerResponse.id)
                            {
                                PlanId          = plan.identifier,
                                IsCreditBased   = false,
                                CustomVariables = customVariables,
                                Subitems        = subscriptionItems
                            }, customApiToken).ConfigureAwait(false);

                            var invoiceItems = new[] { new Item {
                                                           description = "Mensalidade", price_cents = 65000, quantity = 1
                                                       } };
                            var request = new InvoiceRequestMessage("*****@*****.**", invoiceDate, invoiceItems)
                            {
                                SubscriptionId             = subscription.id,
                                CustomVariables            = customVariables.ToArray(),
                                Payer                      = PayerModelDataBuilder.CreateValid(),
                                EnableLateFine             = true,
                                LatePaymentFine            = "2%",
                                EnableProportionalDailyTax = true,
                                PaymentMethod              = Constants.PaymentMethod.BANK_SLIP
                            };

                            var current = await apiInvoice.CreateAsync(request, customApiToken).ConfigureAwait(false);

                            invoice = await apiInvoice.DuplicateAsync(current.id, new InvoiceDuplicateRequestMessage(newDate), customApiToken).ConfigureAwait(false);

                            cancelInvoice = await apiInvoice.GetAsync(current.id, customApiToken).ConfigureAwait(false);
                        };

            // Assert
            Assert.That(invoice, Is.Not.Null);
            Assert.That(invoice.status, Is.EqualTo(Constants.InvoiceStatus.PENDING));
            Assert.That(cancelInvoice.status, Is.EqualTo(Constants.InvoiceStatus.CANCELED));
        }
Пример #5
0
        public async Task Create_a_new_invoice_with_custom_api_token()
        {
            // Arrange
            InvoiceModel invoice;

            var customVariables = new List <CustomVariables>
            {
                new CustomVariables {
                    name = "TaxaIugu", value = "2,50"
                },
                new CustomVariables {
                    name = "TaxaPlataformaEdux", value = "1,00"
                }
            };

            var invoiceDate = DateTime.Now.AddDays(2);
            var newDate     = invoiceDate.AddDays(3).ToString("dd/MM/yyyy");

            var items = new List <InvoiceItem> {
                new InvoiceItem {
                    Description = "Mensalidade", PriceCents = 100000, Quantity = 1
                }
            };
            var customer = new CustomerRequestMessage
            {
                Email           = "*****@*****.**",
                Name            = "Client Name",
                CustomVariables = customVariables
            };

            // Act
            using (var apiInvoice = new Invoice())
                using (var apiCustomer = new Customer())
                    using (var apiSubscription = new Subscription())
                        using (var apiPlan = new Plans())
                        {
                            var customerResponse = await apiCustomer.CreateAsync(customer, null).ConfigureAwait(false);

                            var radomPlan = Guid.NewGuid().ToString();
                            var plan      = await apiPlan.CreateAsync($"{radomPlan}-12x", $"{radomPlan}-Plan", 1, "months", 0, "BRL", null, null, Constants.PaymentMethod.BANK_SLIP).ConfigureAwait(false);

                            var subscriptionItems = new List <SubscriptionSubitem> {
                                new SubscriptionSubitem {
                                    description = "Mensalidade", price_cents = 65000, quantity = 1, recurrent = true
                                }
                            };
                            var subscription = await apiSubscription.CreateAsync(new SubscriptionRequestMessage(customerResponse.id)
                            {
                                PlanId          = plan.identifier,
                                IsCreditBased   = false,
                                CustomVariables = customVariables,
                                Subitems        = subscriptionItems
                            }).ConfigureAwait(false);

                            var invoiceItems = new[] { new Item {
                                                           description = "Mensalidade", price_cents = 65000, quantity = 1
                                                       } };
                            var invoiceRequest = new InvoiceRequestMessage("*****@*****.**", invoiceDate, invoiceItems)
                            {
                                SubscriptionId  = subscription.id,
                                CustomVariables = customVariables.ToArray(),
                                Payer           = _payer
                            };

                            invoice = await apiInvoice.CreateAsync(invoiceRequest, "74c265aedbfaea379bc0148fae9b5526").ConfigureAwait(false);
                        };

            // Assert
            Assert.That(invoice, Is.Not.Null);
        }
        /// <summary>
        /// Cria um cliente em uma conta especifica
        /// </summary>
        /// <param name="request"></param>
        /// <param name="customApiToken"></param>
        /// <returns></returns>
        public async Task <CustomerModel> CreateAsync(CustomerRequestMessage request, string customApiToken)
        {
            var retorno = await PostAsync <CustomerModel>(request, null, customApiToken).ConfigureAwait(false);

            return(retorno);
        }