Skip to content

Commit

Permalink
handle recipient deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Feb 14, 2025
1 parent f7ccc6c commit 38b29d9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ protected MangoPayApi getRoot() {
put("recipient_get_all", new String[]{"/users/%s/recipients", RequestType.GET.toString()});
put("recipient_get_schema", new String[]{"/recipients/schema?payoutMethodType=%s&recipientType=%s&currency=%s", RequestType.GET.toString()});
put("recipient_validate", new String[]{"/users/%s/recipients/validate", RequestType.POST.toString()});
put("recipient_deactivate", new String[]{"/recipients/%s", RequestType.PUT.toString()});
}};

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/mangopay/core/APIs/RecipientApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ public interface RecipientApi {
*/
void validate(String idempotencyKey, Recipient recipient, String userId) throws Exception;

/**
* Deactivate a Recipient
*
* @param recipientId the recipient identifier
*/
void deactivate(String recipientId) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public void validate(Recipient recipient, String userId) throws Exception {
public void validate(String idempotencyKey, Recipient recipient, String userId) throws Exception {
this.createObject(Recipient.class, idempotencyKey, "recipient_validate", recipient, userId);
}

@Override
public void deactivate(String recipientId) throws Exception {
this.updateObject(Recipient.class, "recipient_deactivate", new Recipient(), recipientId);
}
}
10 changes: 10 additions & 0 deletions src/test/java/com/mangopay/core/RecipientApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mangopay.entities.subentities.RecipientPropertySchema;
import com.mangopay.entities.subentities.RecipientSchema;
import com.mangopay.entities.subentities.UserRecipients;
import org.junit.Ignore;
import org.junit.Test;

import java.util.HashMap;
Expand Down Expand Up @@ -74,6 +75,15 @@ public void validate() throws Exception {
getApi().getRecipientApi().validate(recipient, ACTIVE_USER_NATURAL_SCA_ID);
}

@Ignore("A recipient needs to be manually activated before testing this")
@Test
public void deactivateRecipient() throws Exception {
String recipientId = "rec_01JM2J975QESK6AB9RNBV7EZSF";
getApi().getRecipientApi().deactivate(recipientId);
Recipient afterDeactivation = getApi().getRecipientApi().get(recipientId);
assertEquals("DEACTIVATED", afterDeactivation.getStatus());
}

private void createNewRecipient() throws Exception {
if (recipient == null) {
Map<String, Object> localBankTransfer = new HashMap<>();
Expand Down

0 comments on commit 38b29d9

Please sign in to comment.