diff --git a/dist/mangopaysdk.jar b/dist/mangopaysdk.jar index 25dcf265..59dd6a2d 100644 Binary files a/dist/mangopaysdk.jar and b/dist/mangopaysdk.jar differ diff --git a/src/com/mangopay/core/ApiBase.java b/src/com/mangopay/core/ApiBase.java index 6726737b..db5dcd8c 100644 --- a/src/com/mangopay/core/ApiBase.java +++ b/src/com/mangopay/core/ApiBase.java @@ -6,7 +6,7 @@ import java.util.Map; /** - * Base class for all Api classes. + * Base class for all API classes. */ public abstract class ApiBase { @@ -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 }); }}; /** diff --git a/src/com/mangopay/core/ApiCards.java b/src/com/mangopay/core/ApiCards.java index caf2eef5..72b2b3b7 100644 --- a/src/com/mangopay/core/ApiCards.java +++ b/src/com/mangopay/core/ApiCards.java @@ -6,6 +6,7 @@ import com.mangopay.MangoPayApi; import com.mangopay.entities.Card; +import com.mangopay.entities.TemporaryPaymentCard; /** * API for cards. @@ -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); + } } diff --git a/src/com/mangopay/core/ApiEvents.java b/src/com/mangopay/core/ApiEvents.java index 9373a936..1415f002 100644 --- a/src/com/mangopay/core/ApiEvents.java +++ b/src/com/mangopay/core/ApiEvents.java @@ -22,7 +22,7 @@ public class ApiEvents extends ApiBase { * @return List of events matching passed filter criteria. * @throws Exception */ - public List get(FilterEvents filter, Pagination pagination) throws Exception { - return this.getList(Event[].class, Event.class, "events_all", pagination, "", filter.getValues(), null); + public List get(FilterEvents filter, Pagination pagination, Sorting sorting) throws Exception { + return this.getList(Event[].class, Event.class, "events_all", pagination, "", filter.getValues(), sorting); } } diff --git a/src/com/mangopay/core/ApiHooks.java b/src/com/mangopay/core/ApiHooks.java index 95c87cba..1338c47c 100644 --- a/src/com/mangopay/core/ApiHooks.java +++ b/src/com/mangopay/core/ApiHooks.java @@ -51,8 +51,8 @@ public Hook update(Hook hook) throws Exception { * @return List of Hook instances returned from API. * @throws Exception */ - public List getAll(Pagination pagination) throws Exception { - return this.getList(Hook[].class, Hook.class, "hooks_all", pagination); + public List getAll(Pagination pagination, Sorting sorting) throws Exception { + return this.getList(Hook[].class, Hook.class, "hooks_all", pagination, sorting); } /** @@ -61,7 +61,7 @@ public List getAll(Pagination pagination) throws Exception { * @throws Exception */ public List getAll() throws Exception { - return this.getAll(null); + return this.getAll(null, null); } } diff --git a/src/com/mangopay/core/ApiPayIns.java b/src/com/mangopay/core/ApiPayIns.java index 03faa22a..3dcb29fd 100644 --- a/src/com/mangopay/core/ApiPayIns.java +++ b/src/com/mangopay/core/ApiPayIns.java @@ -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. @@ -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) diff --git a/src/com/mangopay/core/ApiUsers.java b/src/com/mangopay/core/ApiUsers.java index 4960ac78..c8884f62 100644 --- a/src/com/mangopay/core/ApiUsers.java +++ b/src/com/mangopay/core/ApiUsers.java @@ -56,8 +56,8 @@ else if (user instanceof UserLegal) * @return Collection of User instances. * @throws Exception */ - public List getAll(Pagination pagination) throws Exception { - return this.getList(User[].class, User.class, "users_all", pagination); + public List getAll(Pagination pagination, Sorting sorting) throws Exception { + return this.getList(User[].class, User.class, "users_all", pagination, sorting); } /** @@ -66,7 +66,7 @@ public List getAll(Pagination pagination) throws Exception { * @throws Exception */ public List getAll() throws Exception { - return getAll(null); + return getAll(null, null); } /** @@ -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); } /** diff --git a/src/com/mangopay/entities/TemporaryImmediatePayIn.java b/src/com/mangopay/entities/TemporaryImmediatePayIn.java new file mode 100644 index 00000000..5354129a --- /dev/null +++ b/src/com/mangopay/entities/TemporaryImmediatePayIn.java @@ -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; +} diff --git a/src/com/mangopay/entities/TemporaryPaymentCard.java b/src/com/mangopay/entities/TemporaryPaymentCard.java new file mode 100644 index 00000000..96f9b78f --- /dev/null +++ b/src/com/mangopay/entities/TemporaryPaymentCard.java @@ -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; +} diff --git a/test/com/mangopay/core/ApiCardRegistrationsTest.java b/test/com/mangopay/core/ApiCardRegistrationsTest.java index c65a9a27..81a3aa0c 100644 --- a/test/com/mangopay/core/ApiCardRegistrationsTest.java +++ b/test/com/mangopay/core/ApiCardRegistrationsTest.java @@ -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.*; @@ -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); + } } diff --git a/test/com/mangopay/core/ApiEventsTest.java b/test/com/mangopay/core/ApiEventsTest.java index 8fd3ce2f..b8e106b9 100644 --- a/test/com/mangopay/core/ApiEventsTest.java +++ b/test/com/mangopay/core/ApiEventsTest.java @@ -16,10 +16,10 @@ public void test_Events_Get() throws Exception { FilterEvents eventsFilter = new FilterEvents(); eventsFilter.Type = EventType.PAYIN_NORMAL_CREATED; - List getEvents = this._api.Events.get(eventsFilter, null); + List getEvents = this._api.Events.get(eventsFilter, null, null); eventsFilter.Type = EventType.ALL; - List getAllEvents = this._api.Events.get(eventsFilter, null); + List getAllEvents = this._api.Events.get(eventsFilter, null, null); assertNotNull(getEvents); assertNotNull(getAllEvents); diff --git a/test/com/mangopay/core/ApiHooksTest.java b/test/com/mangopay/core/ApiHooksTest.java index 38712c5a..644691cc 100644 --- a/test/com/mangopay/core/ApiHooksTest.java +++ b/test/com/mangopay/core/ApiHooksTest.java @@ -54,7 +54,7 @@ public void test_Hooks_All() { Hook hook = this.getJohnsHook(); Pagination pagination = new Pagination(1, 1); - List list = this._api.Hooks.getAll(pagination); + List list = this._api.Hooks.getAll(pagination, null); assertTrue(list.get(0) instanceof Hook); assertEquals(hook.Id, list.get(0).Id); diff --git a/test/com/mangopay/core/ApiUsersTest.java b/test/com/mangopay/core/ApiUsersTest.java index 2cab6f91..7ae7ab58 100644 --- a/test/com/mangopay/core/ApiUsersTest.java +++ b/test/com/mangopay/core/ApiUsersTest.java @@ -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; @@ -298,9 +300,18 @@ public void test_Users_BankAccounts() throws Exception { List list = this._api.Users.getBankAccounts(john.Id, pagination, null); + int index = -1; + for (int i=0; i -1); + assertEqualInputProps(account, list.get(index)); assertTrue(pagination.Page == 1); assertTrue(pagination.ItemsPerPage == 12); } @@ -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 diff --git a/test/com/mangopay/core/BaseTest.java b/test/com/mangopay/core/BaseTest.java index e1532d65..a9058b85 100644 --- a/test/com/mangopay/core/BaseTest.java +++ b/test/com/mangopay/core/BaseTest.java @@ -611,7 +611,7 @@ protected Hook getJohnsHook() throws Exception { if (BaseTest._johnsHook == null) { Pagination pagination = new Pagination(1, 1); - List list = this._api.Hooks.getAll(pagination); + List list = this._api.Hooks.getAll(pagination, null); if (list != null && list.size() > 0 && list.get(0) != null) { BaseTest._johnsHook = list.get(0); diff --git a/test/com/mangopay/core/TestKycPageFile.png b/test/com/mangopay/core/TestKycPageFile.png new file mode 100644 index 00000000..699a6fc2 Binary files /dev/null and b/test/com/mangopay/core/TestKycPageFile.png differ diff --git a/test/com/mangopay/core/TestKycPageFile.txt b/test/com/mangopay/core/TestKycPageFile.txt deleted file mode 100644 index dfa3f980..00000000 --- a/test/com/mangopay/core/TestKycPageFile.txt +++ /dev/null @@ -1 +0,0 @@ -This is a sample file to be used in KycPage test. \ No newline at end of file