diff --git a/iugu.net.IntegratedTests/InvoiceIntegratedTests.cs b/iugu.net.IntegratedTests/InvoiceIntegratedTests.cs index f013f9e..4163c1a 100644 --- a/iugu.net.IntegratedTests/InvoiceIntegratedTests.cs +++ b/iugu.net.IntegratedTests/InvoiceIntegratedTests.cs @@ -29,6 +29,12 @@ public async Task Create_a_valid_invoice() new CustomVariables { name = "TaxaPlataformaEdux", value = "1,00" } }; + var earlyPaymentDiscounts = new List + { + new EarlyPaymentDiscounts { days = 10, percent = "8.2" }, + new EarlyPaymentDiscounts { days = 5, percent = "5" } + }; + var invoiceDate = DateTime.Now.AddDays(2); var customer = new CustomerRequestMessage @@ -58,7 +64,7 @@ public async Task Create_a_valid_invoice() var invoiceItems = new[] { new Item { description = "Mensalidade", price_cents = 65000, quantity = 1 } }; invoice = await apiInvoice.CreateAsync("anyemail@gmail.com.br", invoiceDate, invoiceItems, null, null, null, 0, - 0, null, false, subscription.id, null, null, customVariables, _payer) + 0, null, false, subscription.id, null, null, customVariables, _payer, true, earlyPaymentDiscounts) .ConfigureAwait(false); }; @@ -110,7 +116,7 @@ public async Task Create_a_new_invoice_and_cancel_after() var invoiceItems = new[] { new Item { description = "Mensalidade", price_cents = 65000, quantity = 1 } }; var current = await apiInvoice.CreateAsync("anyemail@gmail.com.br", invoiceDate, invoiceItems, null, null, null, 0, 0, - null, false, subscription.id, null, null, customVariables, _payer).ConfigureAwait(false); + null, false, subscription.id, null, null, customVariables, _payer, false, null).ConfigureAwait(false); invoice = await apiInvoice.DuplicateAsync(current.id, new InvoiceDuplicateRequestMessage(newDate)).ConfigureAwait(false); }; diff --git a/iugu.net/Entity/InvoiceModel.cs b/iugu.net/Entity/InvoiceModel.cs index b8591bb..ca43a66 100644 --- a/iugu.net/Entity/InvoiceModel.cs +++ b/iugu.net/Entity/InvoiceModel.cs @@ -38,6 +38,8 @@ public class InvoiceModel public List items { get; set; } public List variables { get; set; } public List custom_variables { get; set; } + public bool early_payment_discount { get; set; } + public List early_payment_discounts { get; set; } public List logs { get; set; } } @@ -100,4 +102,11 @@ public class Facets { public Status status { get; set; } } + + // TODO: Precisa de refatoração, nomes fora do padrão .Net, sem documentação também + public class EarlyPaymentDiscounts + { + public int days { get; set; } + public string percent { get; set; } + } } diff --git a/iugu.net/Lib/Invoice.cs b/iugu.net/Lib/Invoice.cs index 52c4a1c..4c29c68 100644 --- a/iugu.net/Lib/Invoice.cs +++ b/iugu.net/Lib/Invoice.cs @@ -109,11 +109,11 @@ public async Task GetAsync(string id, string customApiToken) [Obsolete("Sera descontinuado na versão 2.x do client, use a versão assincrona do método que recebe InvoiceRequestMessage como parâmetro")] public InvoiceModel Create(string email, DateTime due_date, Item[] items, string return_url = "", string expired_url = "", string notification_url = "", int tax_cents = 0, int discount_cents = 0, string customer_id = "", bool ignore_due_email = false, - string subscription_id = "", int credits = 0, Logs logs = null, List custom_variables = null, PayerModel payer = null) + string subscription_id = "", int credits = 0, Logs logs = null, List custom_variables = null, PayerModel payer = null, bool early_payment_discount = false, List early_payment_discounts = null) { var retorno = CreateAsync(email, due_date, items, return_url, expired_url, notification_url, tax_cents, discount_cents, customer_id, ignore_due_email, subscription_id, credits, logs, - custom_variables, payer).Result; + custom_variables, payer, early_payment_discount, early_payment_discounts).Result; return retorno; } @@ -139,7 +139,7 @@ public InvoiceModel Create(string email, DateTime due_date, Item[] items, string [Obsolete("Sera descontinuado na versão 2.x do client, use a versão assincrona do método que recebe InvoiceRequestMessage como parâmetro")] public async Task CreateAsync(string email, DateTime due_date, Item[] items, string return_url, string expired_url, string notification_url, int tax_cents = 0, int discount_cents = 0, string customer_id = null, bool ignore_due_email = false, - string subscription_id = null, int? credits = null, Logs logs = null, List custom_variables = null, PayerModel payer = null) + string subscription_id = null, int? credits = null, Logs logs = null, List custom_variables = null, PayerModel payer = null, bool early_payment_discount = false, List early_payment_discounts = null) { var invoice = new { @@ -157,6 +157,8 @@ public async Task CreateAsync(string email, DateTime due_date, Ite logs = logs, custom_variables = custom_variables, notification_url = notification_url, + early_payment_discount = early_payment_discount, + early_payment_discounts = early_payment_discounts, payer = payer }; var retorno = await PostAsync(invoice).ConfigureAwait(false);