Skip to content

Commit

Permalink
Merge pull request iugu#65 from EduBem/feature/desconto_pontualidade
Browse files Browse the repository at this point in the history
Ajusta invoicemodel com early_payment_discounts
  • Loading branch information
rscouto authored Sep 5, 2017
2 parents dfaf4c9 + 3b67817 commit 2b82ec5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 8 additions & 2 deletions iugu.net.IntegratedTests/InvoiceIntegratedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public async Task Create_a_valid_invoice()
new CustomVariables { name = "TaxaPlataformaEdux", value = "1,00" }
};

var earlyPaymentDiscounts = new List<EarlyPaymentDiscounts>
{
new EarlyPaymentDiscounts { days = 10, percent = "8.2" },
new EarlyPaymentDiscounts { days = 5, percent = "5" }
};

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

var customer = new CustomerRequestMessage
Expand Down Expand Up @@ -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("[email protected]", 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);
};

Expand Down Expand Up @@ -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("[email protected]", 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);
};
Expand Down
9 changes: 9 additions & 0 deletions iugu.net/Entity/InvoiceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class InvoiceModel
public List<Item> items { get; set; }
public List<Variable> variables { get; set; }
public List<CustomVariables> custom_variables { get; set; }
public bool early_payment_discount { get; set; }
public List<EarlyPaymentDiscounts> early_payment_discounts { get; set; }
public List<Logs> logs { get; set; }
}

Expand Down Expand Up @@ -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; }
}
}
8 changes: 5 additions & 3 deletions iugu.net/Lib/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public async Task<InvoiceModel> 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<CustomVariables> custom_variables = null, PayerModel payer = null)
string subscription_id = "", int credits = 0, Logs logs = null, List<CustomVariables> custom_variables = null, PayerModel payer = null, bool early_payment_discount = false, List<EarlyPaymentDiscounts> 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;
}

Expand All @@ -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<InvoiceModel> 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<CustomVariables> custom_variables = null, PayerModel payer = null)
string subscription_id = null, int? credits = null, Logs logs = null, List<CustomVariables> custom_variables = null, PayerModel payer = null, bool early_payment_discount = false, List<EarlyPaymentDiscounts> early_payment_discounts = null)
{
var invoice = new
{
Expand All @@ -157,6 +157,8 @@ public async Task<InvoiceModel> 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<InvoiceModel>(invoice).ConfigureAwait(false);
Expand Down

0 comments on commit 2b82ec5

Please sign in to comment.