Skip to content

Commit

Permalink
Merge pull request #346 from Mangopay/feature/sca-users
Browse files Browse the repository at this point in the history
Feature/sca users
  • Loading branch information
alexxmattei authored Jan 17, 2025
2 parents 19e363c + ef6133e commit 17d2cf7
Show file tree
Hide file tree
Showing 19 changed files with 1,062 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ protected MangoPayApi getRoot() {
put("transfers_createrefunds", new String[]{"/transfers/%s/refunds", RequestType.POST.toString()});

put("users_createnaturals", new String[]{"/users/natural", RequestType.POST.toString()});
put("users_createnaturals_sca", new String[]{"/sca/users/natural", RequestType.POST.toString()});
put("users_createlegals", new String[]{"/users/legal", RequestType.POST.toString()});
put("users_createlegals_sca", new String[]{"/sca/users/legal", RequestType.POST.toString()});

put("users_createbankaccounts_iban", new String[]{"/users/%s/bankaccounts/iban", RequestType.POST.toString()});
put("users_createbankaccounts_gb", new String[]{"/users/%s/bankaccounts/gb", RequestType.POST.toString()});
Expand All @@ -140,13 +142,21 @@ protected MangoPayApi getRoot() {
put("users_alltransactions", new String[]{"/users/%s/transactions", RequestType.GET.toString()});
put("users_allkycdocuments", new String[]{"/users/%s/KYC/documents", RequestType.GET.toString()});
put("users_get", new String[]{"/users/%s", RequestType.GET.toString()});
put("users_get_sca", new String[]{"/sca/users/%s", RequestType.GET.toString()});
put("users_getnaturals", new String[]{"/users/natural/%s", RequestType.GET.toString()});
put("users_getnaturals_sca", new String[]{"/sca/users/natural/%s", RequestType.GET.toString()});
put("users_getlegals", new String[]{"/users/legal/%s", RequestType.GET.toString()});
put("users_getlegals_sca", new String[]{"/sca/users/legal/%s", RequestType.GET.toString()});
put("users_getbankaccount", new String[]{"/users/%s/bankaccounts/%s", RequestType.GET.toString()});
put("users_savenaturals", new String[]{"/users/natural/%s", RequestType.PUT.toString()});
put("users_savenaturals_sca", new String[]{"/sca/users/natural/%s", RequestType.PUT.toString()});
put("users_savelegals", new String[]{"/users/legal/%s", RequestType.PUT.toString()});
put("users_savelegals_sca", new String[]{"/sca/users/legal/%s", RequestType.PUT.toString()});
put("users_categorizenaturals_sca", new String[]{"/sca/users/natural/%s/category", RequestType.PUT.toString()});
put("users_categorizelegals_sca", new String[]{"/sca/users/legal/%s/category", RequestType.PUT.toString()});
put("users_block_status", new String[]{"/users/%s/blockStatus", RequestType.GET.toString()});
put("users_regulatory", new String[]{"/users/%s/Regulatory", RequestType.GET.toString()});
put("users_activate_sca", new String[]{"/sca/users/%s/activation", RequestType.POST.toString()});

put("users_emoney_year", new String[]{"/users/%s/emoney/%s", RequestType.GET.toString()});
put("users_emoney_month", new String[]{"/users/%s/emoney/%s/%s", RequestType.GET.toString()});
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/mangopay/core/APIs/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mangopay.core.enumerations.CurrencyIso;
import com.mangopay.core.enumerations.KycDocumentType;
import com.mangopay.entities.*;
import com.mangopay.entities.subentities.ActivateUserResult;

import java.util.List;

Expand All @@ -24,6 +25,15 @@ public interface UserApi {
*/
User get(String userId) throws Exception;

/**
* Gets user (SCA).
*
* @param userId User identifier.
* @return User instance returned from API, which is either of UserNaturalSca or UserLegalSca type.
* @throws Exception
*/
User getSca(String userId) throws Exception;

/**
* Creates new user.
*
Expand Down Expand Up @@ -69,6 +79,15 @@ public interface UserApi {
*/
UserNatural getNatural(String userId) throws Exception;

/**
* Gets natural sca user by its identifier,
*
* @param userId UserNaturalSca identifier.
* @return UserNaturalSca object returned from API.
* @throws Exception
*/
UserNaturalSca getNaturalSca(String userId) throws Exception;

/**
* Gets legal user by its identifier.
*
Expand All @@ -78,6 +97,15 @@ public interface UserApi {
*/
UserLegal getLegal(String userId) throws Exception;

/**
* Gets legal sca user by its identifier,
*
* @param userId UserLegalSca identifier.
* @return UserLegalSca object returned from API.
* @throws Exception
*/
UserLegalSca getLegalSca(String userId) throws Exception;

/**
* Updates the user.
*
Expand All @@ -87,6 +115,35 @@ public interface UserApi {
*/
User update(User user) throws Exception;

/**
* Updates the user (SCA).
*
* @param user Instance of UserNaturalSca or UserLegalSca class to be updated.
* @return Updated User object returned from API.
* @throws Exception
*/
User updateSca(User user) throws Exception;

/**
* Transition a Natural/Legal Payer to Owner (SCA).
*
* @param user Instance of UserNaturalSca or UserLegalSca to be transitioned. Some parameters may be required based on the kind of transition you do.
* See <a href="https://docs.mangopay.com/api-reference/users/categorize-natural-user">Categorize Natural User</a>
* or <a href="https://docs.mangopay.com/api-reference/users/categorize-legal-user">Categorize Legal User</a> for more info.
* @return Updated User object returned from API.
* @throws Exception
*/
User categorize(User user) throws Exception;

/**
* Obtain a new SCA redirection link to authenticate a user
*
* @param userId User identifier
* @return User for that User
* @throws Exception
*/
ActivateUserResult activate(String userId) throws Exception;

/**
* Creates bank account for user.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private Map<String, Class<?>> getMapForResource() {
put("transfers_create", Transfer.class);
put("users_createnaturals", UserNatural.class);
put("users_createlegals", UserLegal.class);
put("users_createlegals_sca", UserLegalSca.class);
put("users_createnaturals_sca", UserNaturalSca.class);
put("users_createkycdocument", KycDocument.class);
put("users_createbankaccounts_iban", BankAccount.class);
put("users_createbankaccounts_gb", BankAccount.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.mangopay.core.serializer.BankAccountSerializer;
import com.mangopay.core.serializer.UserSerializer;
import com.mangopay.entities.*;
import com.mangopay.entities.subentities.ActivateUserResult;
import org.apache.commons.codec.binary.Base64;

import java.nio.file.Files;
Expand All @@ -38,7 +39,9 @@ public class UserApiImpl extends ApiBase implements UserApi {
public UserApiImpl(MangoPayApi root, GsonBuilder gsonBuilder) {
super(root);
gsonBuilder.registerTypeAdapter(UserLegal.class, new UserSerializer());
gsonBuilder.registerTypeAdapter(UserLegalSca.class, new UserSerializer());
gsonBuilder.registerTypeAdapter(UserNatural.class, new UserSerializer());
gsonBuilder.registerTypeAdapter(UserNaturalSca.class, new UserSerializer());
gsonBuilder.registerTypeAdapter(User.class, new UserDeserializer());
gsonBuilder.registerTypeAdapter(BankAccount.class, new BankAccountSerializer());
gsonBuilder.registerTypeAdapter(BankAccount.class, new BankAccountDeserializer());
Expand All @@ -49,6 +52,11 @@ public User get(String userId) throws Exception {
return this.getObject(User.class, "users_get", userId);
}

@Override
public User getSca(String userId) throws Exception {
return this.getObject(User.class, "users_get_sca", userId);
}

@Override
public User create(User user) throws Exception {
return create(null, user);
Expand All @@ -63,6 +71,10 @@ public User create(String idempotencyKey, User user) throws Exception {
response = this.createObject(UserNatural.class, idempotencyKey, "users_createnaturals", (UserNatural) user);
else if (user instanceof UserLegal)
response = this.createObject(UserLegal.class, idempotencyKey, "users_createlegals", (UserLegal) user);
else if (user instanceof UserNaturalSca)
response = this.createObject(UserNaturalSca.class, idempotencyKey, "users_createnaturals_sca", (UserNaturalSca) user);
else if (user instanceof UserLegalSca)
response = this.createObject(UserLegalSca.class, idempotencyKey, "users_createlegals_sca", (UserLegalSca) user);
else
throw new Exception("Unsupported user entity type.");

Expand All @@ -84,11 +96,21 @@ public UserNatural getNatural(String userId) throws Exception {
return this.getObject(UserNatural.class, "users_getnaturals", userId);
}

@Override
public UserNaturalSca getNaturalSca(String userId) throws Exception {
return this.getObject(UserNaturalSca.class, "users_getnaturals_sca", userId);
}

@Override
public UserLegal getLegal(String userId) throws Exception {
return this.getObject(UserLegal.class, "users_getlegals", userId);
}

@Override
public UserLegalSca getLegalSca(String userId) throws Exception {
return this.getObject(UserLegalSca.class, "users_getlegals_sca", userId);
}

@Override
public User update(User user) throws Exception {

Expand All @@ -103,6 +125,39 @@ else if (user instanceof UserLegal)
return this.updateObject(User.class, methodKey, user);
}

@Override
public User updateSca(User user) throws Exception {

String methodKey = "";
if (user instanceof UserNaturalSca)
methodKey = "users_savenaturals_sca";
else if (user instanceof UserLegalSca)
methodKey = "users_savelegals_sca";
else
throw new Exception("Unsupported user entity type.");

return this.updateObject(User.class, methodKey, user);
}

@Override
public User categorize(User user) throws Exception {

String methodKey = "";
if (user instanceof UserNaturalSca)
methodKey = "users_categorizenaturals_sca";
else if (user instanceof UserLegalSca)
methodKey = "users_categorizelegals_sca";
else
throw new Exception("Unsupported user entity type.");

return this.updateObject(User.class, methodKey, user);
}

@Override
public ActivateUserResult activate(String userId) throws Exception {
return this.createObject(ActivateUserResult.class, null, "users_activate_sca", null, userId);
}

@Override
public BankAccount createBankAccount(String userId, BankAccount bankAccount) throws Exception {
return this.createBankAccount(null, userId, bankAccount);
Expand Down
122 changes: 122 additions & 0 deletions src/main/java/com/mangopay/core/LegalRepresentative.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.mangopay.core;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.enumerations.CountryIso;

/**
* Introduced with SCA
* Holds data for the LegalRepresentative of a UserLegal entity
*/
public class LegalRepresentative extends Dto {

@SerializedName("FirstName")
private String firstName;

@SerializedName("LastName")
private String lastName;

@SerializedName("ProofOfIdentity")
private String proofOfIdentity;

@SerializedName("Email")
private String email;

@SerializedName("Birthday")
private Long birthday;

@SerializedName("Nationality")
private CountryIso nationality;

@SerializedName("CountryOfResidence")
private CountryIso countryOfResidence;

@SerializedName("PhoneNumber")
private String phoneNumber;

@SerializedName("PhoneNumberCountry")
private CountryIso phoneNumberCountry;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Long getBirthday() {
return birthday;
}

public void setBirthday(Long birthday) {
this.birthday = birthday;
}

public CountryIso getNationality() {
return nationality;
}

public void setNationality(CountryIso nationality) {
this.nationality = nationality;
}

public CountryIso getCountryOfResidence() {
return countryOfResidence;
}

public void setCountryOfResidence(CountryIso countryOfResidence) {
this.countryOfResidence = countryOfResidence;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public CountryIso getPhoneNumberCountry() {
return phoneNumberCountry;
}

public void setPhoneNumberCountry(CountryIso phoneNumberCountry) {
this.phoneNumberCountry = phoneNumberCountry;
}

public String getProofOfIdentity() {
return proofOfIdentity;
}

public void setProofOfIdentity(String proofOfIdentity) {
this.proofOfIdentity = proofOfIdentity;
}

public Boolean allFieldsNull() {
return firstName == null &&
lastName == null &&
proofOfIdentity == null &&
email == null &&
birthday == null &&
nationality == null &&
countryOfResidence == null &&
phoneNumber == null &&
phoneNumberCountry == null;
}
}
14 changes: 11 additions & 3 deletions src/main/java/com/mangopay/core/deserializer/UserDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.google.gson.*;
import com.mangopay.core.enumerations.PersonType;
import com.mangopay.entities.User;
import com.mangopay.entities.UserLegal;
import com.mangopay.entities.UserNatural;
import com.mangopay.entities.*;

import java.lang.reflect.Type;

Expand All @@ -14,8 +12,18 @@ public User deserialize(JsonElement json, Type typeOfT, JsonDeserializationConte
JsonObject jsonObject = json.getAsJsonObject();
PersonType type = PersonType.valueOf(jsonObject.get("PersonType").getAsString());
if (type.equals(PersonType.LEGAL)) {
// if the json has SCA related properties -> deserialize to UserLegalSca
// !!! THIS LOGIC SHOULD NOT BE CHANGED ON API SIDE !!!
if (jsonObject.has("PendingUserAction")) {
return context.deserialize(json, UserLegalSca.class);
}
return context.deserialize(json, UserLegal.class);
} else if (type.equals(PersonType.NATURAL)) {
// if the json has SCA related properties -> deserialize to UserNaturalSca
// !!! THIS LOGIC SHOULD NOT BE CHANGED ON API SIDE !!!
if (jsonObject.has("PendingUserAction")) {
return context.deserialize(json, UserNaturalSca.class);
}
return context.deserialize(json, UserNatural.class);
} else {
throw new IllegalArgumentException("Invalid user JSON:" + json.getAsJsonObject().toString());
Expand Down
Loading

0 comments on commit 17d2cf7

Please sign in to comment.