-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from Mangopay/bugfix/fix-tests
Tests updates and fixes
- Loading branch information
Showing
13 changed files
with
150 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/mangopay/core/serializer/CreateConversionQuoteSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.mangopay.core.serializer; | ||
|
||
import com.google.gson.*; | ||
import com.mangopay.core.Money; | ||
import com.mangopay.entities.CreateConversionQuote; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
public class CreateConversionQuoteSerializer implements JsonSerializer<CreateConversionQuote> { | ||
|
||
/** | ||
* For creating a Conversion Quote, the Money.Amount fields needs to be sent as NULL in some cases | ||
*/ | ||
@Override | ||
public JsonElement serialize(CreateConversionQuote src, Type typeOfSrc, JsonSerializationContext context) { | ||
JsonObject object = new Gson().toJsonTree(src, typeOfSrc).getAsJsonObject(); | ||
|
||
Money debitedFunds = src.getDebitedFunds(); | ||
Money creditedFunds = src.getCreditedFunds(); | ||
|
||
if (debitedFunds != null && creditedFunds != null) { | ||
// as per API docs: the DebitedFunds.Amount is required if CreditedFunds.Amount is null | ||
if (debitedFunds.getAmount() == 0 && creditedFunds.getAmount() != 0) { | ||
JsonObject debitedFundsObj = object.getAsJsonObject("DebitedFunds"); | ||
debitedFundsObj.addProperty("Amount", (String) null); | ||
object.add("DebitedFunds", debitedFundsObj); | ||
} | ||
|
||
// as per API docs: the CreditedFunds.Amount is required if DebitedFunds.Amount is null | ||
if (debitedFunds.getAmount() != 0 && creditedFunds.getAmount() == 0) { | ||
JsonObject creditedFundsObj = object.getAsJsonObject("CreditedFunds"); | ||
creditedFundsObj.addProperty("Amount", (String) null); | ||
object.add("CreditedFunds", creditedFundsObj); | ||
} | ||
} | ||
|
||
return object; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public abstract class BaseTest { | |
private static UboDeclaration UBO_DECLARATION; | ||
private static PayInTemplateURLOptions PAYIN_TEMPLATE_URL_OPTIONS; | ||
private static VirtualAccount JOHNS_VIRTUAL_ACCOUNT; | ||
private static Mandate MANDATE; | ||
|
||
public BaseTest() { | ||
this.api = buildNewMangoPayApi(); | ||
|
@@ -259,32 +260,6 @@ protected UserNaturalSca getJohnScaPayer(Boolean recreate, Boolean termsAccepted | |
return BaseTest.JOHN_SCA_PAYER; | ||
} | ||
|
||
protected UserNatural getNewDeclarativeJohn() throws Exception { | ||
return getNewJohn(true); | ||
} | ||
|
||
protected UserNatural getNewJohn(boolean declarative) throws Exception { | ||
|
||
Calendar c = Calendar.getInstance(); | ||
c.set(1975, 12, 21, 0, 0, 0); | ||
|
||
UserNatural user = new UserNatural(); | ||
user.setFirstName("John"); | ||
user.setLastName("Doe"); | ||
user.setEmail("[email protected]"); | ||
user.setAddress(this.getNewAddress()); | ||
user.setBirthday(c.getTimeInMillis() / 1000); | ||
user.setNationality(CountryIso.FR); | ||
user.setCountryOfResidence(CountryIso.FR); | ||
user.setOccupation("programmer"); | ||
user.setIncomeRange(3); | ||
user.setUserCategory(UserCategory.OWNER); | ||
if (declarative) { | ||
user.setCapacity(NaturalUserCapacity.DECLARATIVE); | ||
} | ||
return (UserNatural) this.api.getUserApi().create(user); | ||
} | ||
|
||
protected UserLegal getMatrix(UserCategory userCategory) throws Exception { | ||
switch (userCategory) { | ||
case OWNER: | ||
|
@@ -471,7 +446,7 @@ protected Wallet getJohnsWallet() throws Exception { | |
* @return Wallet instance loaded with 10k EUR. | ||
*/ | ||
protected Wallet getJohnsWalletWithMoney() throws Exception { | ||
return getJohnsWalletWithMoney(500); | ||
return getJohnsWalletWithMoney(1000); | ||
} | ||
|
||
/** | ||
|
@@ -1912,13 +1887,15 @@ protected Conversion createQuotedConversion() throws Exception { | |
|
||
Wallet debitedWallet = getJohnsWalletWithMoney(); | ||
ConversionQuote quote = createConversionQuote(); | ||
System.out.println("quote created"); | ||
|
||
CreateQuotedConversion quotedConversion = new CreateQuotedConversion(); | ||
quotedConversion.setQuoteId(quote.getId()); | ||
quotedConversion.setAuthorId(debitedWallet.getOwners().get(0)); | ||
quotedConversion.setCreditedWalletId(creditedWallet.getId()); | ||
quotedConversion.setDebitedWalletId(debitedWallet.getId()); | ||
|
||
System.out.println("creating conversion quote"); | ||
return this.api.getConversionsApi().createQuotedConversion(quotedConversion, null); | ||
} | ||
|
||
|
@@ -1937,12 +1914,48 @@ protected ConversionQuote createConversionQuote() throws Exception { | |
|
||
Money debitedFunds = new Money(); | ||
debitedFunds.setCurrency(CurrencyIso.EUR); | ||
debitedFunds.setAmount(50); | ||
debitedFunds.setAmount(1); | ||
conversionQuote.setDebitedFunds(debitedFunds); | ||
|
||
conversionQuote.setDuration(90); | ||
conversionQuote.setDuration(300); | ||
conversionQuote.setTag("Created using the Mangopay PHP SDK"); | ||
|
||
return this.api.getConversionsApi().createConversionQuote(conversionQuote, null); | ||
} | ||
|
||
protected Mandate createMandate(Boolean recreate) throws Exception { | ||
if (BaseTest.MANDATE == null || recreate) { | ||
Mandate mandatePost = new Mandate(); | ||
mandatePost.setBankAccountId(this.getJohnsAccount().getId()); | ||
mandatePost.setReturnUrl("http://test.test"); | ||
mandatePost.setCulture(CultureCode.EN); | ||
|
||
BaseTest.MANDATE = this.api.getMandateApi().create(mandatePost); | ||
} | ||
return BaseTest.MANDATE; | ||
} | ||
|
||
public PayIn createDirectDebitDirect() throws Exception { | ||
Wallet wallet = this.getJohnsWallet(); | ||
UserNatural user = this.getJohn(); | ||
|
||
Mandate mandate = this.createMandate(false); | ||
|
||
PayIn payIn = new PayIn(); | ||
payIn.setAuthorId(user.getId()); | ||
payIn.setDebitedFunds(new Money()); | ||
payIn.getDebitedFunds().setAmount(10); | ||
payIn.getDebitedFunds().setCurrency(CurrencyIso.EUR); | ||
payIn.setFees(new Money()); | ||
payIn.getFees().setAmount(0); | ||
payIn.getFees().setCurrency(CurrencyIso.EUR); | ||
payIn.setCreditedWalletId(wallet.getId()); | ||
PayInPaymentDetailsDirectDebit paymentDetails = new PayInPaymentDetailsDirectDebit(); | ||
paymentDetails.setMandateId(mandate.getId()); | ||
payIn.setPaymentDetails(paymentDetails); | ||
PayInExecutionDetailsDirect executionDetails = new PayInExecutionDetailsDirect(); | ||
payIn.setExecutionDetails(executionDetails); | ||
|
||
return this.api.getPayInApi().create(payIn); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.