Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- added support for sorting all lists
- adjusted KYC upload unit tests to recent API changes
- added temporary API calls
  • Loading branch information
lukasz-drzewiecki committed Nov 27, 2014
1 parent 1dc7653 commit a2a2b8d
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 28 deletions.
Binary file modified dist/mangopaysdk.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion src/com/mangopay/core/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Map;

/**
* Base class for all Api classes.
* Base class for all API classes.
*/
public abstract class ApiBase {

Expand Down Expand Up @@ -94,6 +94,11 @@ public abstract class ApiBase {
put("kyc_page_create", new String[] { "/users/%s/KYC/documents/%s/pages", RequestType.POST });
put("kyc_documents_all", new String[] { "/KYC/documents", RequestType.GET });

// These are temporary functions and WILL be removed in the future.
// Contact support before using these features or if have any queries.
put("temp_paymentcards_create", new String[] { "/temp/paymentcards", RequestType.POST });
put("temp_paymentcards_get", new String[] { "/temp/paymentcards/%s", RequestType.GET });
put("temp_immediatepayins_create", new String[] { "/temp/immediate-payins", RequestType.POST });
}};

/**
Expand Down
29 changes: 29 additions & 0 deletions src/com/mangopay/core/ApiCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.mangopay.MangoPayApi;
import com.mangopay.entities.Card;
import com.mangopay.entities.TemporaryPaymentCard;

/**
* API for cards.
Expand Down Expand Up @@ -48,4 +49,32 @@ public Card disable(Card card) throws Exception {
card.Validity = "INVALID";
return update(card);
}

/**
* WARNING!
* This is temporary entity and will be removed in future.
* Contact support before using these features or if have any queries.
*
* Creates new temporary payment card.
* @param paymentCard Payment card object to create.
* @return Payment card object returned from API.
* @throws Exception
*/
public TemporaryPaymentCard createTemporaryPaymentCard(TemporaryPaymentCard paymentCard) throws Exception {
return this.createObject(TemporaryPaymentCard.class, "temp_paymentcards_create", paymentCard);
}

/**
* WARNING!
* This is temporary entity and will be removed in future.
* Contact support before using these features or if have any queries.
*
* Gets temporary payment card.
* @param paymentCardId Payment card identifier.
* @return Payment card object returned from API.
* @throws Exception
*/
public TemporaryPaymentCard getTemporaryPaymentCard(String paymentCardId) throws Exception {
return this.getObject(TemporaryPaymentCard.class, "temp_paymentcards_get", paymentCardId);
}
}
4 changes: 2 additions & 2 deletions src/com/mangopay/core/ApiEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ApiEvents extends ApiBase {
* @return List of events matching passed filter criteria.
* @throws Exception
*/
public List<Event> get(FilterEvents filter, Pagination pagination) throws Exception {
return this.getList(Event[].class, Event.class, "events_all", pagination, "", filter.getValues(), null);
public List<Event> get(FilterEvents filter, Pagination pagination, Sorting sorting) throws Exception {
return this.getList(Event[].class, Event.class, "events_all", pagination, "", filter.getValues(), sorting);
}
}
6 changes: 3 additions & 3 deletions src/com/mangopay/core/ApiHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public Hook update(Hook hook) throws Exception {
* @return List of Hook instances returned from API.
* @throws Exception
*/
public List<Hook> getAll(Pagination pagination) throws Exception {
return this.getList(Hook[].class, Hook.class, "hooks_all", pagination);
public List<Hook> getAll(Pagination pagination, Sorting sorting) throws Exception {
return this.getList(Hook[].class, Hook.class, "hooks_all", pagination, sorting);
}

/**
Expand All @@ -61,7 +61,7 @@ public List<Hook> getAll(Pagination pagination) throws Exception {
* @throws Exception
*/
public List<Hook> getAll() throws Exception {
return this.getAll(null);
return this.getAll(null, null);
}

}
15 changes: 15 additions & 0 deletions src/com/mangopay/core/ApiPayIns.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mangopay.MangoPayApi;
import com.mangopay.entities.PayIn;
import com.mangopay.entities.Refund;
import com.mangopay.entities.TemporaryImmediatePayIn;

/**
* API for PayIns.
Expand Down Expand Up @@ -58,6 +59,20 @@ public Refund getRefund(String payInId) throws Exception {
return this.getObject(Refund.class, "payins_getrefunds", payInId);
}

/**
* WARNING!
* This is temporary entity and will be removed in future.
* Contact support before using these features or if have any queries.
*
* Creates new temporary immediate pay-in.
* @param immediatePayIn Immediate pay-in object to create.
* @return Immediate pay-in object returned from API.
* @throws Exception
*/
public TemporaryImmediatePayIn createTemporaryImmediatePayIn(TemporaryImmediatePayIn immediatePayIn) throws Exception {
return this.createObject(TemporaryImmediatePayIn.class, "temp_immediatepayins_create", immediatePayIn);
}

private String getPaymentKey(PayIn payIn) throws Exception {

if (payIn.PaymentDetails == null)
Expand Down
15 changes: 4 additions & 11 deletions src/com/mangopay/core/ApiUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ else if (user instanceof UserLegal)
* @return Collection of User instances.
* @throws Exception
*/
public List<User> getAll(Pagination pagination) throws Exception {
return this.getList(User[].class, User.class, "users_all", pagination);
public List<User> getAll(Pagination pagination, Sorting sorting) throws Exception {
return this.getList(User[].class, User.class, "users_all", pagination, sorting);
}

/**
Expand All @@ -66,7 +66,7 @@ public List<User> getAll(Pagination pagination) throws Exception {
* @throws Exception
*/
public List<User> getAll() throws Exception {
return getAll(null);
return getAll(null, null);
}

/**
Expand Down Expand Up @@ -213,14 +213,7 @@ public void createKycPage(String userId, String kycDocumentId, byte[] binaryData

kycPage.File = fileContent;

try
{
this.createObject(KycPage.class, "users_createkycpage", kycPage, userId, kycDocumentId);
}
catch (Exception ex)
{
Exception e = ex;
}
this.createObject(KycPage.class, "kyc_page_create", kycPage, userId, kycDocumentId);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/com/mangopay/entities/TemporaryImmediatePayIn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mangopay.entities;

/**
* WARNING!
* This is temporary entity and will be removed in future.
* Contact support before using these features or if have any queries.
*
* TemporaryImmediatePayIn entity.
*/
public class TemporaryImmediatePayIn extends Transaction {
/**
* Payment card identifier.
*/
public String PaymentCardId;

/**
* Credited wallet identifier.
*/
public String CreditedWalletId;
}
42 changes: 42 additions & 0 deletions src/com/mangopay/entities/TemporaryPaymentCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mangopay.entities;

import com.mangopay.core.EntityBase;

/**
* WARNING!
* This is temporary entity and will be removed in future.
* Contact support before using these features or if have any queries.
*
* TemporaryPaymentCard entity.
*/
public class TemporaryPaymentCard extends EntityBase {
/**
* User identifier.
*/
public String UserId;

/**
* Culture.
*/
public String Culture;

/**
* Return URL.
*/
public String ReturnURL;

/**
* Template URL.
*/
public String TemplateURL;

/**
* Redirect URL.
*/
public String RedirectURL;

/**
* Alias.
*/
public String Alias;
}
38 changes: 38 additions & 0 deletions test/com/mangopay/core/ApiCardRegistrationsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mangopay.core;

import com.mangopay.entities.CardRegistration;
import com.mangopay.entities.TemporaryPaymentCard;
import com.mangopay.entities.UserNatural;
import org.junit.Test;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -49,4 +50,41 @@ public void test_CardRegistrations_Update() throws Exception {
assertEquals("VALIDATED", getCardRegistration.Status);
assertEquals("000000", getCardRegistration.ResultCode);
}


/* The two tests below are added to cover temporary use cases, which will be
* removed in future. */

@Test
public void test_TemporaryPaymentCard_Create() throws Exception {
UserNatural user = this.getJohn();
TemporaryPaymentCard paymentCard = new TemporaryPaymentCard();
paymentCard.UserId = user.Id;
paymentCard.Tag = "Test tag";
paymentCard.Culture = "FR";
paymentCard.ReturnURL = "http://test.com/test";
paymentCard.TemplateURL = "https://test.com/test";

TemporaryPaymentCard paymentCardCreated = this._api.Cards.createTemporaryPaymentCard(paymentCard);

assertTrue(paymentCardCreated.Id.length() > 0);
assertEquals(paymentCardCreated.UserId, user.Id);
}

@Test
public void test_TemporaryPaymentCard_Get() throws Exception {
UserNatural user = this.getJohn();
TemporaryPaymentCard paymentCard = new TemporaryPaymentCard();
paymentCard.UserId = user.Id;
paymentCard.Tag = "Test tag";
paymentCard.Culture = "FR";
paymentCard.ReturnURL = "http://test.com/test";
paymentCard.TemplateURL = "https://test.com/test";
TemporaryPaymentCard paymentCardCreated = this._api.Cards.createTemporaryPaymentCard(paymentCard);

TemporaryPaymentCard paymentCardGet = this._api.Cards.getTemporaryPaymentCard(paymentCardCreated.Id);

assertTrue(paymentCardGet.Id.length() > 0);
assertEquals(paymentCardGet.Id, paymentCardCreated.Id);
}
}
4 changes: 2 additions & 2 deletions test/com/mangopay/core/ApiEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public void test_Events_Get() throws Exception {
FilterEvents eventsFilter = new FilterEvents();
eventsFilter.Type = EventType.PAYIN_NORMAL_CREATED;

List<Event> getEvents = this._api.Events.get(eventsFilter, null);
List<Event> getEvents = this._api.Events.get(eventsFilter, null, null);

eventsFilter.Type = EventType.ALL;
List<Event> getAllEvents = this._api.Events.get(eventsFilter, null);
List<Event> getAllEvents = this._api.Events.get(eventsFilter, null, null);

assertNotNull(getEvents);
assertNotNull(getAllEvents);
Expand Down
2 changes: 1 addition & 1 deletion test/com/mangopay/core/ApiHooksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void test_Hooks_All() {
Hook hook = this.getJohnsHook();
Pagination pagination = new Pagination(1, 1);

List<Hook> list = this._api.Hooks.getAll(pagination);
List<Hook> list = this._api.Hooks.getAll(pagination, null);

assertTrue(list.get(0) instanceof Hook);
assertEquals(hook.Id, list.get(0).Id);
Expand Down
24 changes: 18 additions & 6 deletions test/com/mangopay/core/ApiUsersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.mangopay.entities.*;
import java.net.URL;
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -298,9 +300,18 @@ public void test_Users_BankAccounts() throws Exception {

List<BankAccount> list = this._api.Users.getBankAccounts(john.Id, pagination, null);

int index = -1;
for (int i=0; i<list.size(); i++)
{
if (account.Id.equals(list.get(i).Id)){
index = i;
break;
}
}

assertTrue(list.get(0) instanceof BankAccount);
assertTrue(account.Id.equals(list.get(0).Id));
assertEqualInputProps(account, list.get(0));
assertTrue(index > -1);
assertEqualInputProps(account, list.get(index));
assertTrue(pagination.Page == 1);
assertTrue(pagination.ItemsPerPage == 12);
}
Expand Down Expand Up @@ -363,15 +374,16 @@ public void test_Users_GetKycDocument() throws Exception {
@Test
public void test_Users_CreateKycPage() throws Exception {
UserNatural john = this.getJohn();
KycDocument kycDocument = this.getJohnsKycDocument();

this._api.Users.createKycPage(john.Id, kycDocument.Id, "Test KYC page".getBytes());
KycDocument kycDocument = this.getNewKycDocument();

URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
String filePath = url.toString() + "/com/mangopay/core/TestKycPageFile.txt";
String filePath = url.toString() + "/com/mangopay/core/TestKycPageFile.png";
filePath = filePath.replace("file:/", "").replace("//", "/").replace("/", "\\");

this._api.Users.createKycPage(john.Id, kycDocument.Id, filePath);

kycDocument = this.getNewKycDocument();
this._api.Users.createKycPage(john.Id, kycDocument.Id, Files.readAllBytes(Paths.get(filePath)));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion test/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ protected Hook getJohnsHook() throws Exception {
if (BaseTest._johnsHook == null) {

Pagination pagination = new Pagination(1, 1);
List<Hook> list = this._api.Hooks.getAll(pagination);
List<Hook> list = this._api.Hooks.getAll(pagination, null);

if (list != null && list.size() > 0 && list.get(0) != null) {
BaseTest._johnsHook = list.get(0);
Expand Down
Binary file added test/com/mangopay/core/TestKycPageFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion test/com/mangopay/core/TestKycPageFile.txt

This file was deleted.

0 comments on commit a2a2b8d

Please sign in to comment.