Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[FEAT] Multipayment #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions Moip.Tests/Api/MultipaymentsAPITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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)");
}

[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)");
}
}
}
3 changes: 0 additions & 3 deletions Moip.Tests/Api/PaymentsAPITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
96 changes: 96 additions & 0 deletions Moip.Tests/Helpers/RequestsCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
8 changes: 8 additions & 0 deletions Moip/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public MultiOrdersController MultiOrders
}
}

public MultipaymentsController Multipayments
{
get
{
return MultipaymentsController.Instance;
}
}

public AccountsController Accounts
{
get
Expand Down
Loading