Skip to content

Commit

Permalink
Added support for API v2.01
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-drzewiecki committed Jul 29, 2015
1 parent 6a9f5cc commit e885aa1
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ MangopaySDK is a Java client library to work with
[Mangopay REST API](http://docs.mangopay.com/api-references/).


Compatibility Note
-------------------------------------------------
Since v1.0.6 of this SDK, you must be using at least v2.01 of the API ([more information about the changes required](https://docs.mangopay.com/api-v2-01-overview/))


Installation
-------------------------------------------------
SDK has been written in Java 7. It depends only on a single external package:
Expand Down
Binary file modified dist/mangopaysdk.jar
Binary file not shown.
39 changes: 39 additions & 0 deletions src/com/mangopay/core/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mangopay.core;

import com.mangopay.core.enumerations.CountryIso;

/**
* Class represents an address.
*/
public class Address extends Dto {

/**
* Address line 1.
*/
public String AddressLine1;

/**
* Address line 2.
*/
public String AddressLine2;

/**
* City.
*/
public String City;

/**
* Region.
*/
public String Region;

/**
* Postal code.
*/
public String PostalCode;

/**
* Country.
*/
public CountryIso Country;
}
4 changes: 2 additions & 2 deletions src/com/mangopay/core/UrlTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public String getRestUrl(String urlKey, Boolean addClientId, Pagination paginati
String url;

if (!addClientId) {
url = "/v2" + urlKey;
url = "/v2.01" + urlKey;
} else {
url = "/v2/" + _root.Config.ClientId + urlKey;
url = "/v2.01/" + _root.Config.ClientId + urlKey;
}

Boolean paramsAdded = false;
Expand Down
19 changes: 18 additions & 1 deletion src/com/mangopay/entities/BankAccount.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.mangopay.entities;

import com.mangopay.core.Address;
import com.mangopay.entities.subentities.BankAccountDetailsCA;
import com.mangopay.entities.subentities.BankAccountDetailsGB;
import com.mangopay.entities.subentities.BankAccountDetailsIBAN;
import com.mangopay.entities.subentities.BankAccountDetailsOTHER;
import com.mangopay.entities.subentities.BankAccountDetailsUS;
import com.mangopay.core.enumerations.BankAccountType;
import com.mangopay.core.EntityBase;
import com.mangopay.core.Money;
import com.mangopay.core.interfaces.IBankAccountDetails;
import java.lang.reflect.Type;
import java.util.*;

/**
Expand All @@ -33,13 +36,27 @@ public class BankAccount extends EntityBase {
/**
* Owner address.
*/
public String OwnerAddress;
public Address OwnerAddress;

/**
* One of BankAccountDetails implementations, depending on Type.
*/
public IBankAccountDetails Details;

/**
* Gets map which property is an object and what type of object.
* @return Collection of field name-field type pairs.
*/
@Override
public Map<String, Type> getSubObjects() {

Map<String, Type> result = super.getSubObjects();

result.put("OwnerAddress", Address.class);

return result;
}

/**
* Gets the structure that maps which property depends on other property.
* @return
Expand Down
25 changes: 23 additions & 2 deletions src/com/mangopay/entities/UserLegal.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.mangopay.entities;

import com.mangopay.core.Address;
import com.mangopay.core.Money;
import com.mangopay.core.enumerations.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
* UserLegal entity.
Expand All @@ -21,7 +26,7 @@ public class UserLegal extends User {
/**
* Headquarters address.
*/
public String HeadquartersAddress;
public Address HeadquartersAddress;

/**
* Legal representative first name.
Expand All @@ -36,7 +41,7 @@ public class UserLegal extends User {
/**
* Legal representative address.
*/
public String LegalRepresentativeAddress;
public Address LegalRepresentativeAddress;

/**
* Legal representative email.
Expand Down Expand Up @@ -80,6 +85,22 @@ public UserLegal() {
PersonType = PersonType.LEGAL;
}

/**
* Gets map which property is an object and what type of object.
* @return Collection of field name-field type pairs.
*/
@Override
public Map<String, Type> getSubObjects() {

Map<String, Type> result = super.getSubObjects();

result.put("HeadquartersAddress", Address.class);
result.put("LegalRepresentativeAddress", Address.class);

return result;

}

/**
* Gets the collection of read-only fields names.
* @return List of field names.
Expand Down
20 changes: 19 additions & 1 deletion src/com/mangopay/entities/UserNatural.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.mangopay.entities;

import com.mangopay.core.Address;
import com.mangopay.core.enumerations.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
* UserNatural entity.
Expand All @@ -21,7 +25,7 @@ public final class UserNatural extends User {
/**
* Address.
*/
public String Address;
public Address Address;

/**
* Date of birth (UNIX timestamp).
Expand Down Expand Up @@ -88,6 +92,20 @@ public UserNatural() {
PersonType = PersonType.NATURAL;
}

/**
* Gets map which property is an object and what type of object.
* @return Collection of field name-field type pairs.
*/
@Override
public Map<String, Type> getSubObjects() {

Map<String, Type> result = super.getSubObjects();

result.put("Address", Address.class);

return result;
}

/**
* Gets the collection of read-only fields names.
* @return List of field names.
Expand Down
7 changes: 7 additions & 0 deletions test/com/mangopay/core/ApiUsersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public void test_Users_CreateLegal_FailsIfRequiredPropsNotProvided() throws Exce
@Test
public void test_Users_CreateLegal_PassesIfRequiredPropsProvided() throws Exception {
UserLegal user = new UserLegal();
user.HeadquartersAddress = new Address();
user.HeadquartersAddress.AddressLine1 = "AddressLine1";
user.HeadquartersAddress.AddressLine2 = "AddressLine2";
user.HeadquartersAddress.City = "City";
user.HeadquartersAddress.Country = CountryIso.FR;
user.HeadquartersAddress.PostalCode = "11222";
user.HeadquartersAddress.Region = "Region";
user.Name = "SomeOtherSampleOrg";
user.LegalPersonType = LegalPersonType.BUSINESS;
user.LegalRepresentativeFirstName = "RepFName";
Expand Down
51 changes: 45 additions & 6 deletions test/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ protected void holdOn(int sleepTimeInSeconds) {
}
}

protected Address getNewAddress() {
Address result = new Address();

result.AddressLine1 = "Address line 1";
result.AddressLine2 = "Address line 2";
result.City = "City";
result.Country = CountryIso.PL;
result.PostalCode = "11222";
result.Region = "Region";

return result;
}

protected UserNatural getJohn() throws Exception {
if (BaseTest._john == null) {
Calendar c = Calendar.getInstance();
Expand All @@ -105,7 +118,7 @@ protected UserNatural getJohn() throws Exception {
user.FirstName = "John";
user.LastName = "Doe";
user.Email = "[email protected]";
user.Address = "Some Address";
user.Address = this.getNewAddress();
user.Birthday = c.getTimeInMillis() / 1000;
user.Nationality = CountryIso.FR;
user.CountryOfResidence = CountryIso.FR;
Expand All @@ -126,7 +139,7 @@ protected UserNatural getNewJohn() throws Exception {
user.FirstName = "John";
user.LastName = "Doe";
user.Email = "[email protected]";
user.Address = "Some Address";
user.Address = this.getNewAddress();
user.Birthday = c.getTimeInMillis() / 1000;
user.Nationality = CountryIso.FR;
user.CountryOfResidence = CountryIso.FR;
Expand All @@ -142,7 +155,7 @@ protected UserLegal getMatrix() throws Exception {
UserLegal user = new UserLegal();
user.Name = "MartixSampleOrg";
user.LegalPersonType = LegalPersonType.BUSINESS;
user.HeadquartersAddress = "Some Address";
user.HeadquartersAddress = this.getNewAddress();
user.LegalRepresentativeFirstName = john.FirstName;
user.LegalRepresentativeLastName = john.LastName;
user.LegalRepresentativeAddress = john.Address;
Expand Down Expand Up @@ -647,7 +660,16 @@ protected <T> void assertEqualInputProps(T entity1, T entity2) throws Exception
assertEquals(((UserNatural)entity1).FirstName, ((UserNatural)entity2).FirstName);
assertEquals(((UserNatural)entity1).LastName, ((UserNatural)entity2).LastName);
assertEquals(((UserNatural)entity1).Email, ((UserNatural)entity2).Email);
assertEquals(((UserNatural)entity1).Address, ((UserNatural)entity2).Address);

assertNotNull(((UserNatural)entity1).Address);
assertNotNull(((UserNatural)entity2).Address);
assertEquals(((UserNatural)entity1).Address.AddressLine1, ((UserNatural)entity2).Address.AddressLine1);
assertEquals(((UserNatural)entity1).Address.AddressLine2, ((UserNatural)entity2).Address.AddressLine2);
assertEquals(((UserNatural)entity1).Address.City, ((UserNatural)entity2).Address.City);
assertEquals(((UserNatural)entity1).Address.Country, ((UserNatural)entity2).Address.Country);
assertEquals(((UserNatural)entity1).Address.PostalCode, ((UserNatural)entity2).Address.PostalCode);
assertEquals(((UserNatural)entity1).Address.Region, ((UserNatural)entity2).Address.Region);

assertEquals(((UserNatural)entity1).Birthday, ((UserNatural)entity2).Birthday);
assertEquals(((UserNatural)entity1).Nationality, ((UserNatural)entity2).Nationality);
assertEquals(((UserNatural)entity1).CountryOfResidence, ((UserNatural)entity2).CountryOfResidence);
Expand All @@ -658,7 +680,15 @@ protected <T> void assertEqualInputProps(T entity1, T entity2) throws Exception
assertEquals(((UserLegal)entity1).Tag, ((UserLegal)entity2).Tag);
assertEquals(((UserLegal)entity1).PersonType, ((UserLegal)entity2).PersonType);
assertEquals(((UserLegal)entity1).Name, ((UserLegal)entity2).Name);
assertEquals(((UserLegal)entity1).HeadquartersAddress, ((UserLegal)entity2).HeadquartersAddress);
assertNotNull(((UserLegal)entity1).HeadquartersAddress);
assertNotNull(((UserLegal)entity2).HeadquartersAddress);
assertEquals(((UserLegal)entity1).HeadquartersAddress.AddressLine1, ((UserLegal)entity2).HeadquartersAddress.AddressLine1);
assertEquals(((UserLegal)entity1).HeadquartersAddress.AddressLine2, ((UserLegal)entity2).HeadquartersAddress.AddressLine2);
assertEquals(((UserLegal)entity1).HeadquartersAddress.City, ((UserLegal)entity2).HeadquartersAddress.City);
assertEquals(((UserLegal)entity1).HeadquartersAddress.Country, ((UserLegal)entity2).HeadquartersAddress.Country);
assertEquals(((UserLegal)entity1).HeadquartersAddress.PostalCode, ((UserLegal)entity2).HeadquartersAddress.PostalCode);
assertEquals(((UserLegal)entity1).HeadquartersAddress.Region, ((UserLegal)entity2).HeadquartersAddress.Region);

assertEquals(((UserLegal)entity1).LegalRepresentativeFirstName, ((UserLegal)entity2).LegalRepresentativeFirstName);
assertEquals(((UserLegal)entity1).LegalRepresentativeLastName, ((UserLegal)entity2).LegalRepresentativeLastName);
//assertEquals("***** TEMPORARY API ISSUE: RETURNED OBJECT MISSES THIS PROP AFTER CREATION *****", ((UserLegal)entity1).LegalRepresentativeAddress, ((UserLegal)entity2).LegalRepresentativeAddress);
Expand All @@ -673,7 +703,16 @@ protected <T> void assertEqualInputProps(T entity1, T entity2) throws Exception
assertEquals(((BankAccount)entity1).UserId, ((BankAccount)entity2).UserId);
assertEquals(((BankAccount)entity1).Type, ((BankAccount)entity2).Type);
assertEquals(((BankAccount)entity1).OwnerName, ((BankAccount)entity2).OwnerName);
assertEquals(((BankAccount)entity1).OwnerAddress, ((BankAccount)entity2).OwnerAddress);
assertNotNull(((BankAccount)entity1).OwnerAddress);
assertNotNull(((BankAccount)entity2).OwnerAddress);
assertEquals(((BankAccount)entity1).OwnerAddress.AddressLine1, ((BankAccount)entity2).OwnerAddress.AddressLine1);
assertEquals(((BankAccount)entity1).OwnerAddress.AddressLine2, ((BankAccount)entity2).OwnerAddress.AddressLine2);
assertEquals(((BankAccount)entity1).OwnerAddress.City, ((BankAccount)entity2).OwnerAddress.City);
assertEquals(((BankAccount)entity1).OwnerAddress.Country, ((BankAccount)entity2).OwnerAddress.Country);
assertEquals(((BankAccount)entity1).OwnerAddress.PostalCode, ((BankAccount)entity2).OwnerAddress.PostalCode);
assertEquals(((BankAccount)entity1).OwnerAddress.Region, ((BankAccount)entity2).OwnerAddress.Region);


if (((BankAccount)entity1).Type == BankAccountType.IBAN) {
assertEquals(((BankAccountDetailsIBAN)((BankAccount)entity1).Details).IBAN, ((BankAccountDetailsIBAN)((BankAccount)entity2).Details).IBAN);
assertEquals(((BankAccountDetailsIBAN)((BankAccount)entity1).Details).BIC, ((BankAccountDetailsIBAN)((BankAccount)entity2).Details).BIC);
Expand Down

0 comments on commit e885aa1

Please sign in to comment.