From fa35b11552dbe083b70d6dd983263399380afcdf Mon Sep 17 00:00:00 2001 From: "Matheus B. Nakaya" Date: Fri, 27 Apr 2018 14:40:28 -0300 Subject: [PATCH 1/3] feat: multipayment --- Moip.Tests/Api/MultipaymentsAPITest.cs | 69 +++++ Moip.Tests/Api/PaymentsAPITest.cs | 3 - Moip.Tests/Helpers/RequestsCreator.cs | 96 +++++++ Moip/Client.cs | 8 + Moip/Controllers/MultipaymentsController.cs | 238 ++++++++++++++++++ Moip/Controllers/PaymentsController.cs | 7 - .../MultipaymentBoletoOrDebitRequest.cs | 28 +++ Moip/Models/MultipaymentRequest.cs | 90 +++++++ Moip/Models/MultipaymentResponse.cs | 103 ++++++++ 9 files changed, 632 insertions(+), 10 deletions(-) create mode 100644 Moip.Tests/Api/MultipaymentsAPITest.cs create mode 100644 Moip/Controllers/MultipaymentsController.cs create mode 100644 Moip/Models/MultipaymentBoletoOrDebitRequest.cs create mode 100644 Moip/Models/MultipaymentRequest.cs create mode 100644 Moip/Models/MultipaymentResponse.cs diff --git a/Moip.Tests/Api/MultipaymentsAPITest.cs b/Moip.Tests/Api/MultipaymentsAPITest.cs new file mode 100644 index 0000000..763af4c --- /dev/null +++ b/Moip.Tests/Api/MultipaymentsAPITest.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Moip.Controllers; +using NUnit.Framework; +using System.Threading; + +namespace Moip.Tests.Api +{ + [TestFixture] + class MultipaymentsAPITest : ControllerTestBase + { + private static MultipaymentsController controller; + + [SetUp] + public static void SetUpClass() + { + controller = GetClient().Multipayments; + } + + [Test] + public void TestCreateMultipaymentWithCreditCard() + { + Moip.Models.MultipaymentRequest multipaymentRequest = Helpers.RequestsCreator.CreateMultipaymetWithCCRequest(); + + Moip.Models.MultipaymentResponse multipaymentResponse = controller.CreateCreditCard(GetClient().MultiOrders.CreateMultiorder(Helpers.RequestsCreator.CreateMultiorderRequest()).Id, multipaymentRequest); + + Assert.NotNull(multipaymentResponse.Id, "Id should not be null"); + Assert.AreEqual(1, multipaymentResponse.InstallmentCount, "Should match exactly (integer number match)"); + Assert.AreEqual("MyStore", multipaymentResponse.Payments[0].StatementDescriptor, "Should match exactly (string literal match)"); + Assert.AreEqual("CREDIT_CARD", multipaymentResponse.Payments[0].FundingInstrument.Method, "Should match exactly (string literal match)"); + Assert.AreEqual("Jose Goku da Silva", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.Fullname, "Should match exactly (string literal match)"); + Assert.AreEqual("1988-12-30", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.Birthdate, "Should match exactly (string literal match)"); + Assert.AreEqual("CPF", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.TaxDocument.Type, "Should match exactly (string literal match)"); + Assert.AreEqual("33333333333", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.TaxDocument.Number, "Should match exactly (string literal match)"); + } + + [Test] + public void TestCreateMultipaymentWithBoleto() + { + Moip.Models.MultipaymentBoletoOrDebitRequest multipaymentRequest = Helpers.RequestsCreator.CreateMultipaymentWithBoletoRequest(); + + Moip.Models.MultipaymentResponse multipaymentResponse = controller.CreateBoletoOrDebit(GetClient().MultiOrders.CreateMultiorder(Helpers.RequestsCreator.CreateMultiorderRequest()).Id, multipaymentRequest); + + Assert.NotNull(multipaymentResponse.Id, "Id should not be null"); + Assert.AreEqual("BOLETO", multipaymentResponse.Payments[0].FundingInstrument.Method, "Should match exactly (string literal match)"); + Assert.AreEqual("2020-09-30", multipaymentResponse.Payments[0].FundingInstrument.Boleto.ExpirationDate, "Should match exactly (string literal match)"); + Assert.AreEqual("TESTETETSTTTST", multipaymentResponse.Payments[0].FundingInstrument.Boleto.InstructionLines.First, "Should match exactly (string literal match)"); + Assert.AreEqual("tfcsddlksjsd", multipaymentResponse.Payments[0].FundingInstrument.Boleto.InstructionLines.Second, "Should match exactly (string literal match)"); + Assert.AreEqual("lkshglashiuahgha", multipaymentResponse.Payments[0].FundingInstrument.Boleto.InstructionLines.Third, "Should match exactly (string literal match)"); + Assert.AreEqual("http://", multipaymentResponse.Payments[0].FundingInstrument.Boleto.LogoUri, "Should match exactly (string literal match)"); + } + + [Test] + public void TestCreateMultipaymentWithOnlineDebit() + { + Moip.Models.MultipaymentBoletoOrDebitRequest multipaymentRequest = Helpers.RequestsCreator.CreateMultipaymentWithOnlineDebitRequest(); + + Moip.Models.MultipaymentResponse multipaymentResponse = controller.CreateBoletoOrDebit(GetClient().MultiOrders.CreateMultiorder(Helpers.RequestsCreator.CreateMultiorderRequest()).Id, multipaymentRequest); + + Assert.NotNull(multipaymentResponse.Id, "Id should not be null"); + Assert.AreEqual("ONLINE_BANK_DEBIT", multipaymentResponse.Payments[0].FundingInstrument.Method, "Should match exactly(string literal match)"); + Assert.AreEqual("341", multipaymentResponse.Payments[0].FundingInstrument.OnlineBankDebit.BankNumber, "Should match exactly (string literal match)"); + Assert.AreEqual("2020-09-30", multipaymentResponse.Payments[0].FundingInstrument.OnlineBankDebit.ExpirationDate, "Should match exactly (string literal match)"); + } + } +} diff --git a/Moip.Tests/Api/PaymentsAPITest.cs b/Moip.Tests/Api/PaymentsAPITest.cs index 146d71c..b4d6287 100644 --- a/Moip.Tests/Api/PaymentsAPITest.cs +++ b/Moip.Tests/Api/PaymentsAPITest.cs @@ -68,9 +68,6 @@ public void TestCreatePaymentWithBoleto() Assert.AreEqual("tfcsddlksjsd", paymentResponse.FundingInstrument.Boleto.InstructionLines.Second, "Should match exactly (string literal match)"); Assert.AreEqual("lkshglashiuahgha", paymentResponse.FundingInstrument.Boleto.InstructionLines.Third, "Should match exactly (string literal match)"); Assert.AreEqual("http://", paymentResponse.FundingInstrument.Boleto.LogoUri, "Should match exactly (string literal match)"); - Assert.AreEqual("https://checkout-sandbox.moip.com.br/boleto/" + paymentResponse.Id + "/print", paymentResponse.Links.PayBoleto.PrintHref, "Should match exactly (string literal match)"); - Assert.AreEqual("https://checkout-sandbox.moip.com.br/boleto/" + paymentResponse.Id, paymentResponse.Links.PayBoleto.RedirectHref, "Should match exactly (string literal match)"); - } [Test] diff --git a/Moip.Tests/Helpers/RequestsCreator.cs b/Moip.Tests/Helpers/RequestsCreator.cs index 57b90cc..6842034 100644 --- a/Moip.Tests/Helpers/RequestsCreator.cs +++ b/Moip.Tests/Helpers/RequestsCreator.cs @@ -1155,8 +1155,104 @@ public static Moip.Models.MultiorderRequest CreateMultiorderRequest() return multiOrderRequest; } + public static Moip.Models.MultipaymentRequest CreateMultipaymetWithCCRequest() + { + Moip.Models.TaxDocument taxDocumentRequest = new Moip.Models.TaxDocument + { + Type = "CPF", + Number = "33333333333" + }; + + Moip.Models.Phone phoneRequest = new Moip.Models.Phone + { + CountryCode = "55", + AreaCode = "11", + Number = "66778899" + }; + + Moip.Models.HolderRequest holderRequest = new Moip.Models.HolderRequest + { + Fullname = "Jose Goku da Silva", + Birthdate = "1988-12-30", + TaxDocument = taxDocumentRequest, + Phone = phoneRequest + }; + + Moip.Models.CreditCardRequest creditCardRequest = new Moip.Models.CreditCardRequest + { + ExpirationMonth = "02", + ExpirationYear = "20", + Number = "5555666677778884", + Cvc = "123", + Holder = holderRequest + }; + + Moip.Models.FundingInstrumentRequest fundingInstrumentRequest = new Moip.Models.FundingInstrumentRequest + { + Method = "CREDIT_CARD", + CreditCard = creditCardRequest + }; + Moip.Models.MultipaymentRequest multipaymentRequest = new Moip.Models.MultipaymentRequest + { + InstallmentCount = 1, + StatementDescriptor = "MyStore", + FundingInstrument = fundingInstrumentRequest + }; + return multipaymentRequest; + } + public static Moip.Models.MultipaymentBoletoOrDebitRequest CreateMultipaymentWithBoletoRequest() + { + Moip.Models.BoletoInstructionLines boletoInstructionLines = new Moip.Models.BoletoInstructionLines() + { + First = "TESTETETSTTTST", + Second = "tfcsddlksjsd", + Third = "lkshglashiuahgha" + }; + + Moip.Models.BoletoRequest boletoRequest = new Moip.Models.BoletoRequest() + { + ExpirationDate = "2020-09-30", + InstructionLines = boletoInstructionLines, + LogoUri = "http://" + }; + + Moip.Models.FundingInstrumentRequest fundingInstrumentRequest = new Moip.Models.FundingInstrumentRequest + { + Method = "BOLETO", + Boleto = boletoRequest + }; + + Moip.Models.MultipaymentBoletoOrDebitRequest multipaymentRequest = new Moip.Models.MultipaymentBoletoOrDebitRequest + { + FundingInstrument = fundingInstrumentRequest + }; + + return multipaymentRequest; + } + + public static Moip.Models.MultipaymentBoletoOrDebitRequest CreateMultipaymentWithOnlineDebitRequest() + { + Moip.Models.OnlineBankDebitRequest onlineBankDebitRequest = new Moip.Models.OnlineBankDebitRequest() + { + BankNumber = 341, + ExpirationDate = "2020-09-30" + }; + + Moip.Models.FundingInstrumentRequest fundingInstrumentRequest = new Moip.Models.FundingInstrumentRequest + { + Method = "ONLINE_BANK_DEBIT", + OnlineBankDebit = onlineBankDebitRequest + }; + + Moip.Models.MultipaymentBoletoOrDebitRequest multipaymentRequest = new Moip.Models.MultipaymentBoletoOrDebitRequest + { + FundingInstrument = fundingInstrumentRequest + }; + + return multipaymentRequest; + } } } diff --git a/Moip/Client.cs b/Moip/Client.cs index 08736dc..86c0ac3 100644 --- a/Moip/Client.cs +++ b/Moip/Client.cs @@ -56,6 +56,14 @@ public MultiOrdersController MultiOrders } } + public MultipaymentsController Multipayments + { + get + { + return MultipaymentsController.Instance; + } + } + public AccountsController Accounts { get diff --git a/Moip/Controllers/MultipaymentsController.cs b/Moip/Controllers/MultipaymentsController.cs new file mode 100644 index 0000000..c99907e --- /dev/null +++ b/Moip/Controllers/MultipaymentsController.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Moip.Utilities; +using Moip.Http.Request; +using Moip.Http.Response; +using Moip.Http.Client; +using Moip.Exceptions; + +namespace Moip.Controllers +{ + public partial class MultipaymentsController : BaseController + { + #region Singleton Pattern + + private static object syncObject = new object(); + private static MultipaymentsController instance = null; + + internal static MultipaymentsController Instance + { + get + { + lock (syncObject) + { + if (null == instance) + { + instance = new MultipaymentsController(); + } + } + return instance; + } + } + + #endregion Singleton Pattern + + public dynamic GetMultipayment(string multipaymentId) + { + Task t = GetMultipaymentAsync(multipaymentId); + APIHelper.RunTaskSynchronously(t); + return t.Result; + } + + public async Task GetMultipaymentAsync(string multipaymentId) + { + string _queryUrl = Utilities.APIHelper.GetBuiltUrl("multipayment", multipaymentId); + + var _headers = Utilities.APIHelper.GetHeader(); + + HttpRequest _request = ClientInstance.Get(_queryUrl, _headers); + + HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); + HttpContext _context = new HttpContext(_request, _response); + + base.ValidateResponse(_response, _context); + + try + { + return APIHelper.JsonDeserialize(_response.Body); + } + catch (Exception _ex) + { + throw new APIException("Failed to parse the response: " + _ex.Message, _context); + } + } + + public Models.MultipaymentResponse CreateCreditCard(string multiorderId, Models.MultipaymentRequest body = null) + { + Task t = CreateCreditCardAsync(multiorderId, body); + APIHelper.RunTaskSynchronously(t); + return t.Result; + } + + public async Task CreateCreditCardAsync(string multiorderId, Models.MultipaymentRequest body = null) + { + string _baseUri = Configuration.GetBaseURI(); + + StringBuilder _queryBuilder = new StringBuilder(_baseUri); + _queryBuilder.Append("/multiorders/{multiorder-id}/multipayments"); + + APIHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary() + { + { "multiorder-id", multiorderId } + }); + + string _queryUrl = APIHelper.CleanUrl(_queryBuilder); + + var _headers = Utilities.APIHelper.GetHeader(); + + var _body = APIHelper.JsonSerialize(body); + + HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body); + + HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); + HttpContext _context = new HttpContext(_request, _response); + + base.ValidateResponse(_response, _context); + + try + { + return APIHelper.JsonDeserialize(_response.Body); + } + catch (Exception _ex) + { + throw new APIException("Failed to parse the response: " + _ex.Message, _context); + } + } + + public Models.MultipaymentResponse CreateBoletoOrDebit(string multiorderId, Models.MultipaymentBoletoOrDebitRequest body) + { + Task t = CreateBoletoOrDebitAsync(body, multiorderId); + APIHelper.RunTaskSynchronously(t); + return t.Result; + } + + public async Task CreateBoletoOrDebitAsync(Models.MultipaymentBoletoOrDebitRequest body, string multiorderId) + { + string _baseUri = Configuration.GetBaseURI(); + + StringBuilder _queryBuilder = new StringBuilder(_baseUri); + _queryBuilder.Append("/multiorders/{multiorder-id}/multipayments"); + + APIHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary() + { + { "multiorder-id", multiorderId } + }); + + string _queryUrl = APIHelper.CleanUrl(_queryBuilder); + + var _headers = Utilities.APIHelper.GetHeader(); + + var _body = APIHelper.JsonSerialize(body); + + HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body); + + HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); + HttpContext _context = new HttpContext(_request, _response); + + base.ValidateResponse(_response, _context); + + try + { + return APIHelper.JsonDeserialize(_response.Body); + } + catch (Exception _ex) + { + throw new APIException("Failed to parse the response: " + _ex.Message, _context); + } + } + public Models.MultipaymentResponse CapturePreAuthorized(string multipaymentId) + { + Task t = CapturePreAuthorizedAsync(multipaymentId); + APIHelper.RunTaskSynchronously(t); + return t.Result; + } + + public async Task CapturePreAuthorizedAsync(string multipaymentId) + { + string _baseUri = Configuration.GetBaseURI(); + + StringBuilder _queryBuilder = new StringBuilder(_baseUri); + _queryBuilder.Append("/multiorders/{multiorder-id}/multipayments"); + + APIHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary() + { + { "multipayment-id", multipaymentId } + }); + + dynamic body = ""; + + var _body = APIHelper.JsonSerialize(body); + + string _queryUrl = APIHelper.CleanUrl(_queryBuilder); + + var _headers = Utilities.APIHelper.GetHeader(); + + HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body); + + HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); + HttpContext _context = new HttpContext(_request, _response); + + base.ValidateResponse(_response, _context); + + try + { + return APIHelper.JsonDeserialize(_response.Body); + } + catch (Exception _ex) + { + throw new APIException("Failed to parse the response: " + _ex.Message, _context); + } + } + + public Models.EscrowResponse ReleaseEscrow(string escrowId) + { + Task t = ReleaseEscrowAsync(escrowId); + APIHelper.RunTaskSynchronously(t); + return t.Result; + } + + public async Task ReleaseEscrowAsync(string escrowId) + { + string _baseUri = Configuration.GetBaseURI(); + + StringBuilder _queryBuilder = new StringBuilder(_baseUri); + _queryBuilder.Append("/escrows/{escrow-id}/release"); + + APIHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary() + { + { "escrow-id", escrowId } + }); + + dynamic body = ""; + + var _body = APIHelper.JsonSerialize(body); + + string _queryUrl = APIHelper.CleanUrl(_queryBuilder); + + var _headers = Utilities.APIHelper.GetHeader(); + + HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body); + + HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); + HttpContext _context = new HttpContext(_request, _response); + + base.ValidateResponse(_response, _context); + + try + { + return APIHelper.JsonDeserialize(_response.Body); + } + catch (Exception _ex) + { + throw new APIException("Failed to parse the response: " + _ex.Message, _context); + } + } + } +} \ No newline at end of file diff --git a/Moip/Controllers/PaymentsController.cs b/Moip/Controllers/PaymentsController.cs index 4cfb2fb..fb80a7d 100644 --- a/Moip/Controllers/PaymentsController.cs +++ b/Moip/Controllers/PaymentsController.cs @@ -1,13 +1,7 @@ using System; using System.Collections.Generic; -using System.Dynamic; -using System.Globalization; -using System.IO; -using System.Linq; using System.Text; using System.Threading.Tasks; -using Newtonsoft.Json.Converters; -using Moip; using Moip.Utilities; using Moip.Http.Request; using Moip.Http.Response; @@ -49,7 +43,6 @@ public dynamic GetPayment(string paymentId) public async Task GetPaymentAsync(string paymentId) { - string _queryUrl = Utilities.APIHelper.GetBuiltUrl("payment", paymentId); var _headers = Utilities.APIHelper.GetHeader(); diff --git a/Moip/Models/MultipaymentBoletoOrDebitRequest.cs b/Moip/Models/MultipaymentBoletoOrDebitRequest.cs new file mode 100644 index 0000000..5b9829a --- /dev/null +++ b/Moip/Models/MultipaymentBoletoOrDebitRequest.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Moip.Models +{ + public class MultipaymentBoletoOrDebitRequest : BaseModel + { + private Models.FundingInstrumentRequest fundingInstrument; + + [JsonProperty("fundingInstrument")] + public Models.FundingInstrumentRequest FundingInstrument + { + get + { + return this.fundingInstrument; + } + set + { + this.fundingInstrument = value; + onPropertyChanged("FundingInstrument"); + } + } + } +} diff --git a/Moip/Models/MultipaymentRequest.cs b/Moip/Models/MultipaymentRequest.cs new file mode 100644 index 0000000..5260d79 --- /dev/null +++ b/Moip/Models/MultipaymentRequest.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Moip.Models +{ + public class MultipaymentRequest : BaseModel + { + + // These fields hold the values for the public properties. + private int? installmentCount; + private string statementDescriptor; + private Models.FundingInstrumentRequest fundingInstrument; + private Models.Escrow escrow; + private bool? delayCapture; + + [JsonProperty("installmentCount")] + public int? InstallmentCount + { + get + { + return this.installmentCount; + } + set + { + this.installmentCount = value; + onPropertyChanged("InstallmentCount"); + } + } + + [JsonProperty("statementDescriptor")] + public string StatementDescriptor + { + get + { + return this.statementDescriptor; + } + set + { + this.statementDescriptor = value; + onPropertyChanged("StatementDescriptor"); + } + } + + [JsonProperty("fundingInstrument")] + public Models.FundingInstrumentRequest FundingInstrument + { + get + { + return this.fundingInstrument; + } + set + { + this.fundingInstrument = value; + onPropertyChanged("FundingInstrument"); + } + } + + [JsonProperty("escrow")] + public Models.Escrow Escrow + { + get + { + return this.escrow; + } + set + { + this.escrow = value; + onPropertyChanged("Escrow"); + } + } + + [JsonProperty("delayCapture")] + public bool? DelayCapture + { + get + { + return this.delayCapture; + } + set + { + this.delayCapture = value; + onPropertyChanged("DelayCapture"); + } + } + } +} diff --git a/Moip/Models/MultipaymentResponse.cs b/Moip/Models/MultipaymentResponse.cs new file mode 100644 index 0000000..4101105 --- /dev/null +++ b/Moip/Models/MultipaymentResponse.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Moip.Models +{ + public class MultipaymentResponse : BaseModel + { + private string id; + private string status; + private Models.AmountPaymentOrRefundResponse amount; + private int installmentCount; + private List payments; + private Models.Links links; + + [JsonProperty("id")] + public string Id + { + get + { + return this.id; + } + set + { + this.id = value; + onPropertyChanged("Id"); + } + } + + [JsonProperty("status")] + public string Status + { + get + { + return this.status; + } + set + { + this.status = value; + onPropertyChanged("Status"); + } + } + + [JsonProperty("amount")] + public AmountPaymentOrRefundResponse Amount + { + get + { + return this.amount; + } + set + { + this.amount = value; + onPropertyChanged("Amount"); + } + } + + [JsonProperty("installmentCount")] + public int InstallmentCount + { + get + { + return this.installmentCount; + } + set + { + this.installmentCount = value; + onPropertyChanged("InstallmentCount"); + } + } + + [JsonProperty("payments")] + public List Payments + { + get + { + return this.payments; + } + set + { + this.payments = value; + onPropertyChanged("Payments"); + } + } + + [JsonProperty("_links")] + public Links Links + { + get + { + return this.links; + } + set + { + this.links = value; + onPropertyChanged("Links"); + } + } + } +} From 1b320bca489f8978a2183f9ff299c42e77bbd72d Mon Sep 17 00:00:00 2001 From: "Matheus B. Nakaya" Date: Fri, 27 Apr 2018 15:57:44 -0300 Subject: [PATCH 2/3] test: getMultipayment --- Moip.Tests/Api/MultipaymentsAPITest.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Moip.Tests/Api/MultipaymentsAPITest.cs b/Moip.Tests/Api/MultipaymentsAPITest.cs index 763af4c..5cab5ba 100644 --- a/Moip.Tests/Api/MultipaymentsAPITest.cs +++ b/Moip.Tests/Api/MultipaymentsAPITest.cs @@ -65,5 +65,23 @@ public void TestCreateMultipaymentWithOnlineDebit() Assert.AreEqual("341", multipaymentResponse.Payments[0].FundingInstrument.OnlineBankDebit.BankNumber, "Should match exactly (string literal match)"); Assert.AreEqual("2020-09-30", multipaymentResponse.Payments[0].FundingInstrument.OnlineBankDebit.ExpirationDate, "Should match exactly (string literal match)"); } + + [Test] + public void TestGetMultipayment() + { + Moip.Models.MultipaymentRequest multipaymentRequest = Helpers.RequestsCreator.CreateMultipaymetWithCCRequest(); + + string multipaymentId = controller.CreateCreditCard(GetClient().MultiOrders.CreateMultiorder(Helpers.RequestsCreator.CreateMultiorderRequest()).Id, multipaymentRequest).Id; + + Moip.Models.MultipaymentResponse multipaymentResponse = controller.GetMultipayment(multipaymentId); + + Assert.NotNull(multipaymentResponse.Id, "Id should not be null"); + Assert.AreEqual(1, multipaymentResponse.InstallmentCount, "Should match exactly (string literal match)"); + Assert.AreEqual("CREDIT_CARD", multipaymentResponse.Payments[0].FundingInstrument.Method, "Should match exactly (string literal match)"); + Assert.AreEqual("Jose Goku da Silva", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.Fullname, "Should match exactly (string literal match)"); + Assert.AreEqual("1988-12-30", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.Birthdate, "Should match exactly (string literal match)"); + Assert.AreEqual("CPF", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.TaxDocument.Type, "Should match exactly (string literal match)"); + Assert.AreEqual("33333333333", multipaymentResponse.Payments[0].FundingInstrument.CreditCard.Holder.TaxDocument.Number, "Should match exactly (string literal match)"); + } } } From e8e767f572b07e39856a2ed494f11fe192e9b93a Mon Sep 17 00:00:00 2001 From: "Matheus B. Nakaya" Date: Fri, 27 Apr 2018 16:33:49 -0300 Subject: [PATCH 3/3] docs(multipayment): add examples --- README.md | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 05852d8..7a7e5bd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + # Moip v2 .NET SDK > O jeito mais simples e rápido de integrar o Moip a sua aplicação .NET @@ -43,6 +43,7 @@ - [Criação](#criação-5) - [Cartão de Crédito](#cartão-de-crédito-1) - [Boleto Bancário](#boleto-bancário) + - [Débito Online](#débito-online) - [Consulta](#consulta-6) - [Capturar multipagamento pré-autorizado](#capturar-multipagamento-pré-autorizado) - [Cancelar multipagamento pré-autorizado](#cancelar-multipagamento-pré-autorizado) @@ -816,12 +817,76 @@ MultiorderResponse multiorder = client.Multiorders.GetMultiorder("MOR-F2R675E1X9 ### Criação #### Cartão de Crédito ```C# -TODO +Moip.Models.TaxDocument taxDocumentRequest = new Moip.Models.TaxDocument +{ + Type = "CPF", + Number = "33333333333" +}; + +Moip.Models.Phone phoneRequest = new Moip.Models.Phone +{ + CountryCode = "55", + AreaCode = "11", + Number = "66778899" +}; + +Moip.Models.HolderRequest holderRequest = new Moip.Models.HolderRequest +{ + Fullname = "Jose Goku da Silva", + Birthdate = "1988-12-30", + TaxDocument = taxDocumentRequest, + Phone = phoneRequest +}; + +Moip.Models.CreditCardRequest creditCardRequest = new Moip.Models.CreditCardRequest +{ + ExpirationMonth = "02", + ExpirationYear = "20", + Number = "5555666677778884", + Cvc = "123", + Holder = holderRequest +}; + +Moip.Models.FundingInstrumentRequest fundingInstrumentRequest = new Moip.Models.FundingInstrumentRequest +{ + Method = "CREDIT_CARD", + CreditCard = creditCardRequest +}; + +Moip.Models.MultipaymentRequest multipaymentRequest = new Moip.Models.MultipaymentRequest +{ + InstallmentCount = 1, + StatementDescriptor = "MyStore", + FundingInstrument = fundingInstrumentRequest +}; ``` #### Boleto Bancário ```C# -TODO +Moip.Models.BoletoInstructionLines boletoInstructionLines = new Moip.Models.BoletoInstructionLines() +{ + First = "TESTETETSTTTST", + Second = "tfcsddlksjsd", + Third = "lkshglashiuahgha" +}; + +Moip.Models.BoletoRequest boletoRequest = new Moip.Models.BoletoRequest() +{ + ExpirationDate = "2020-09-30", + InstructionLines = boletoInstructionLines, + LogoUri = "http://" +}; + +Moip.Models.FundingInstrumentRequest fundingInstrumentRequest = new Moip.Models.FundingInstrumentRequest +{ + Method = "BOLETO", + Boleto = boletoRequest +}; + +Moip.Models.MultipaymentBoletoOrDebitRequest multipaymentRequest = new Moip.Models.MultipaymentBoletoOrDebitRequest +{ + FundingInstrument = fundingInstrumentRequest +}; ``` > Para capturar os links do boleto: @@ -834,9 +899,29 @@ TODO TODO ``` +#### Débito Online +```C# +Moip.Models.OnlineBankDebitRequest onlineBankDebitRequest = new Moip.Models.OnlineBankDebitRequest() +{ + BankNumber = 341, + ExpirationDate = "2020-09-30" +}; + +Moip.Models.FundingInstrumentRequest fundingInstrumentRequest = new Moip.Models.FundingInstrumentRequest +{ + Method = "ONLINE_BANK_DEBIT", + OnlineBankDebit = onlineBankDebitRequest +}; + +Moip.Models.MultipaymentBoletoOrDebitRequest multipaymentRequest = new Moip.Models.MultipaymentBoletoOrDebitRequest +{ + FundingInstrument = fundingInstrumentRequest +}; +``` + ### Consulta ```C# -TODO +MultipaymentResponse multipayment = client.Multipayments.GetMultipayment("MPY-F2R675E1X97P"); ``` ### Capturar multipagamento pré-autorizado