Skip to content

Commit

Permalink
Merge pull request #289 from Mangopay/feature/deposits-endpoints
Browse files Browse the repository at this point in the history
Feature/deposits endpoints
  • Loading branch information
iulian03 authored Dec 20, 2022
2 parents 0cc543e + 99180fa commit 5baabe9
Show file tree
Hide file tree
Showing 18 changed files with 970 additions and 47 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/mangopay/MangoPayApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public MangoPayApi() {
setRepudiationApi(new RepudiationApiImpl(this));
setSettlementApi(new SettlementApiImpl(this));
setRegulatoryApi(new RegulatoryApiImpl(this));
setDepositApi(new DepositApiImpl(this));
setGson(gsonBuilder.create());
}

Expand Down Expand Up @@ -196,6 +197,11 @@ public MangoPayApi() {
*/
private RegulatoryApi regulatoryApi;

/**
* Provides Deposits methods
*/
private DepositApi depositApi;

private Gson gson;

/**
Expand Down Expand Up @@ -425,4 +431,13 @@ public MangoPayApi setRegulatoryApi(RegulatoryApi regulatoryApi) {
this.regulatoryApi = regulatoryApi;
return this;
}

public DepositApi getDepositApi() {
return depositApi;
}

public MangoPayApi setDepositApi(DepositApi depositApi) {
this.depositApi = depositApi;
return this;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected MangoPayApi getRoot() {
put("payins_recurring_registration_get", new String[]{"/recurringpayinregistrations/%s", RequestType.GET.toString()});
put("payins_recurring_registration_put", new String[]{"/recurringpayinregistrations/%s", RequestType.PUT.toString()});
put("payins_recurring_card_direct", new String[]{"/payins/recurring/card/direct", RequestType.POST.toString()});
put("payins_card_preauthorized_deposit", new String[]{"/payins/deposit-preauthorized/direct/full-capture", RequestType.POST.toString()});

put("payouts_bankwire_create", new String[]{"/payouts/bankwire/", RequestType.POST.toString()});
put("payouts_bankwire_get", new String[]{"/payouts/bankwire/%s", RequestType.GET.toString()});
Expand Down Expand Up @@ -207,6 +208,11 @@ protected MangoPayApi getRoot() {

put("country_authorization_get", new String[]{"/countries/%s/authorizations", RequestType.GET.toString()});
put("country_authorization_all", new String[]{"/countries/authorizations", RequestType.GET.toString()});

put("deposits_create", new String[]{"/deposit-preauthorizations/card/direct", RequestType.POST.toString()});
put("deposits_get", new String[]{"/deposit-preauthorizations/%s", RequestType.GET.toString()});
put("deposits_cancel", new String[]{"/deposit-preauthorizations/%s", RequestType.PUT.toString()});

}};

/**
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/mangopay/core/APIs/DepositApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mangopay.core.APIs;

import com.mangopay.entities.Deposit;
import com.mangopay.entities.subentities.CreateDeposit;

public interface DepositApi {
Deposit create(CreateDeposit deposit, String idempotencyKey) throws Exception;

Deposit get(String depositId) throws Exception;

Deposit cancel(String depositId) throws Exception;
}
3 changes: 3 additions & 0 deletions src/main/java/com/mangopay/core/APIs/PayInApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mangopay.core.Pagination;
import com.mangopay.core.Sorting;
import com.mangopay.entities.*;
import com.mangopay.entities.subentities.CreateCardPreAuthorizedDepositPayIn;

import java.util.List;

Expand Down Expand Up @@ -123,4 +124,6 @@ public interface PayInApi {
* @throws Exception
*/
List<Refund> getRefunds(String payInId, Pagination pagination, Sorting sorting) throws Exception;

CardPreAuthorizedDepositPayIn createCardPreAuthorizedDepositPayIn(CreateCardPreAuthorizedDepositPayIn payIn, String idempotencyKey) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mangopay.core.APIs.implementation;

import com.mangopay.MangoPayApi;
import com.mangopay.core.APIs.ApiBase;
import com.mangopay.core.APIs.DepositApi;
import com.mangopay.core.enumerations.PaymentStatus;
import com.mangopay.entities.Deposit;
import com.mangopay.entities.subentities.CancelDeposit;
import com.mangopay.entities.subentities.CreateDeposit;

public class DepositApiImpl extends ApiBase implements DepositApi {
public DepositApiImpl(MangoPayApi root) {
super(root);
}

@Override
public Deposit create(CreateDeposit deposit, String idempotencyKey) throws Exception {
return this.createObject(Deposit.class, idempotencyKey, "deposits_create", deposit);
}

@Override
public Deposit get(String depositId) throws Exception {
return this.getObject(Deposit.class, "deposits_get", depositId);
}

@Override
public Deposit cancel(String depositId) throws Exception {
CancelDeposit dto = new CancelDeposit();
dto.setPaymentStatus(PaymentStatus.CANCELED);

return this.updateObject(Deposit.class, "deposits_cancel", dto, depositId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mangopay.core.deserializer.RecurringPayInDeserializer;
import com.mangopay.core.serializer.PayInSerializer;
import com.mangopay.entities.*;
import com.mangopay.entities.subentities.CreateCardPreAuthorizedDepositPayIn;

import java.util.List;

Expand Down Expand Up @@ -98,6 +99,11 @@ public List<Refund> getRefunds(String payInId, Pagination pagination, Sorting so
return this.getList(Refund[].class, Refund.class, "payin_get_refunds", pagination, payInId, sorting);
}

@Override
public CardPreAuthorizedDepositPayIn createCardPreAuthorizedDepositPayIn(CreateCardPreAuthorizedDepositPayIn payIn, String idempotencyKey) throws Exception {
return this.createObject(CardPreAuthorizedDepositPayIn.class, idempotencyKey, "payins_card_preauthorized_deposit", payIn);
}

private String getPaymentKey(PayIn payIn) throws Exception {

if (payIn.getPaymentDetails() == null)
Expand All @@ -118,4 +124,6 @@ private String getExecutionKey(PayIn payIn) throws Exception {
}
throw new Exception("Execution is not defined or it is not object type");
}


}
15 changes: 15 additions & 0 deletions src/main/java/com/mangopay/core/RestTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ private <T extends Dto, U extends Dto> T doRequest(Class<T> classOfT, String ide
is = connection.getInputStream();
}

checkApiConnection(is);

StringBuffer resp;
try (BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
Expand Down Expand Up @@ -597,6 +599,8 @@ private <T extends Dto> List<T> doRequestList(Class<T[]> classOfT, Class<T> clas
is = connection.getInputStream();
}

checkApiConnection(is);

StringBuffer resp;
try (BufferedReader rd = new BufferedReader(new InputStreamReader(is))) {
String line;
Expand Down Expand Up @@ -679,6 +683,17 @@ private Map<String, String> getHttpHeaders(String restUrl) throws Exception {
return httpHeaders;
}

private void checkApiConnection(InputStream is) throws ResponseException {
if (is == null) {
ResponseException responseException = new ResponseException("Connection to Mangopay API failed");
responseException.setResponseHttpCode(500);
responseException.setResponseHttpDescription("Internal Server Error");
responseException.setApiMessage("Connection to Mangopay API failed");

throw responseException;
}
}

/**
* Checks the HTTP response code and if it's neither 200 nor 204 throws a ResponseException.
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/mangopay/core/enumerations/DepositStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mangopay.core.enumerations;

/**
* Business type enumeration
*/
public enum DepositStatus {
CREATED,

SUCCEEDED,

FAILED
}
10 changes: 9 additions & 1 deletion src/main/java/com/mangopay/core/enumerations/EventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,13 @@ public enum EventType {
PREAUTHORIZATION_FAILED,

INSTANT_PAYOUT_SUCCEEDED,
INSTANT_PAYOUT_FALLBACKED
INSTANT_PAYOUT_FALLBACKED,

DEPOSIT_PREAUTHORIZATION_CREATED,
DEPOSIT_PREAUTHORIZATION_FAILED,
DEPOSIT_PREAUTHORIZATION_PAYMENT_WAITING,
DEPOSIT_PREAUTHORIZATION_PAYMENT_EXPIRED,
DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCEL_REQUESTED,
DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCELED,
DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED
}
176 changes: 176 additions & 0 deletions src/main/java/com/mangopay/entities/CardPreAuthorizedDepositPayIn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.mangopay.entities;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.EntityBase;
import com.mangopay.core.Money;
import com.mangopay.core.enumerations.*;

public class CardPreAuthorizedDepositPayIn extends EntityBase {
@SerializedName("AuthorId")
private String authorId;

@SerializedName("CreditedUserId")
private String creditedUserId;

@SerializedName("DepositId")
private String depositId;

@SerializedName("ResultCode")
private String resultCode;

@SerializedName("ResultMessage")
private String resultMessage;

@SerializedName("Status")
private TransactionStatus status;

@SerializedName("ExecutionDate")
private Long executionDate;

@SerializedName("Type")
private TransactionType type;

@SerializedName("Nature")
private TransactionNature nature;

@SerializedName("PaymentType")
private PayInPaymentType paymentType;

@SerializedName("ExecutionType")
private PayInExecutionType executionType;

@SerializedName("DebitedFunds")
private Money debitedFunds;

@SerializedName("CreditedFunds")
private Money creditedFunds;

@SerializedName("Fees")
private Money fees;

public String getAuthorId() {
return authorId;
}

public CardPreAuthorizedDepositPayIn setAuthorId(String authorId) {
this.authorId = authorId;
return this;
}

public String getCreditedUserId() {
return creditedUserId;
}

public CardPreAuthorizedDepositPayIn setCreditedUserId(String creditedUserId) {
this.creditedUserId = creditedUserId;
return this;
}

public String getDepositId() {
return depositId;
}

public CardPreAuthorizedDepositPayIn setDepositId(String depositId) {
this.depositId = depositId;
return this;
}

public String getResultCode() {
return resultCode;
}

public CardPreAuthorizedDepositPayIn setResultCode(String resultCode) {
this.resultCode = resultCode;
return this;
}

public String getResultMessage() {
return resultMessage;
}

public CardPreAuthorizedDepositPayIn setResultMessage(String resultMessage) {
this.resultMessage = resultMessage;
return this;
}

public TransactionStatus getStatus() {
return status;
}

public CardPreAuthorizedDepositPayIn setStatus(TransactionStatus status) {
this.status = status;
return this;
}

public Long getExecutionDate() {
return executionDate;
}

public CardPreAuthorizedDepositPayIn setExecutionDate(Long executionDate) {
this.executionDate = executionDate;
return this;
}

public TransactionType getType() {
return type;
}

public CardPreAuthorizedDepositPayIn setType(TransactionType type) {
this.type = type;
return this;
}

public TransactionNature getNature() {
return nature;
}

public CardPreAuthorizedDepositPayIn setNature(TransactionNature nature) {
this.nature = nature;
return this;
}

public PayInPaymentType getPaymentType() {
return paymentType;
}

public CardPreAuthorizedDepositPayIn setPaymentType(PayInPaymentType paymentType) {
this.paymentType = paymentType;
return this;
}

public PayInExecutionType getExecutionType() {
return executionType;
}

public CardPreAuthorizedDepositPayIn setExecutionType(PayInExecutionType executionType) {
this.executionType = executionType;
return this;
}

public Money getDebitedFunds() {
return debitedFunds;
}

public CardPreAuthorizedDepositPayIn setDebitedFunds(Money debitedFunds) {
this.debitedFunds = debitedFunds;
return this;
}

public Money getCreditedFunds() {
return creditedFunds;
}

public CardPreAuthorizedDepositPayIn setCreditedFunds(Money creditedFunds) {
this.creditedFunds = creditedFunds;
return this;
}

public Money getFees() {
return fees;
}

public CardPreAuthorizedDepositPayIn setFees(Money fees) {
this.fees = fees;
return this;
}
}
Loading

0 comments on commit 5baabe9

Please sign in to comment.