From ad3ec9189b1c61ebfc09793680f1153912b94764 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 19 Dec 2022 12:24:13 +0200 Subject: [PATCH] added Deposit service --- src/main/java/com/mangopay/MangoPayApi.java | 15 + .../java/com/mangopay/core/APIs/ApiBase.java | 6 + .../com/mangopay/core/APIs/DepositApi.java | 12 + .../java/com/mangopay/core/APIs/PayInApi.java | 3 + .../APIs/implementation/DepositApiImpl.java | 33 +++ .../APIs/implementation/PayInApiImpl.java | 8 + .../core/enumerations/DepositStatus.java | 12 + .../mangopay/core/enumerations/EventType.java | 10 +- .../CardPreAuthorizedDepositPayIn.java | 176 +++++++++++ .../java/com/mangopay/entities/Deposit.java | 279 ++++++++++++++++++ .../entities/subentities/CancelDeposit.java | 19 ++ .../CreateCardPreAuthorizedDepositPayIn.java | 89 ++++++ .../entities/subentities/CreateDeposit.java | 142 +++++++++ .../entities/subentities/PayinsLinked.java | 30 ++ src/test/java/com/mangopay/core/BaseTest.java | 89 +++--- .../com/mangopay/core/DepositApiImplTest.java | 53 ++++ .../com/mangopay/core/PayInApiImplTest.java | 26 ++ 17 files changed, 955 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/mangopay/core/APIs/DepositApi.java create mode 100644 src/main/java/com/mangopay/core/APIs/implementation/DepositApiImpl.java create mode 100644 src/main/java/com/mangopay/core/enumerations/DepositStatus.java create mode 100644 src/main/java/com/mangopay/entities/CardPreAuthorizedDepositPayIn.java create mode 100644 src/main/java/com/mangopay/entities/Deposit.java create mode 100644 src/main/java/com/mangopay/entities/subentities/CancelDeposit.java create mode 100644 src/main/java/com/mangopay/entities/subentities/CreateCardPreAuthorizedDepositPayIn.java create mode 100644 src/main/java/com/mangopay/entities/subentities/CreateDeposit.java create mode 100644 src/main/java/com/mangopay/entities/subentities/PayinsLinked.java create mode 100644 src/test/java/com/mangopay/core/DepositApiImplTest.java diff --git a/src/main/java/com/mangopay/MangoPayApi.java b/src/main/java/com/mangopay/MangoPayApi.java index 5989f1d6..cdbfb984 100644 --- a/src/main/java/com/mangopay/MangoPayApi.java +++ b/src/main/java/com/mangopay/MangoPayApi.java @@ -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()); } @@ -196,6 +197,11 @@ public MangoPayApi() { */ private RegulatoryApi regulatoryApi; + /** + * Provides Deposits methods + */ + private DepositApi depositApi; + private Gson gson; /** @@ -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; + } } diff --git a/src/main/java/com/mangopay/core/APIs/ApiBase.java b/src/main/java/com/mangopay/core/APIs/ApiBase.java index e70dfe87..8d3ac4a1 100644 --- a/src/main/java/com/mangopay/core/APIs/ApiBase.java +++ b/src/main/java/com/mangopay/core/APIs/ApiBase.java @@ -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()}); @@ -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()}); + }}; /** diff --git a/src/main/java/com/mangopay/core/APIs/DepositApi.java b/src/main/java/com/mangopay/core/APIs/DepositApi.java new file mode 100644 index 00000000..bf5d9498 --- /dev/null +++ b/src/main/java/com/mangopay/core/APIs/DepositApi.java @@ -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; +} diff --git a/src/main/java/com/mangopay/core/APIs/PayInApi.java b/src/main/java/com/mangopay/core/APIs/PayInApi.java index 7b080ad5..a8da7ac9 100644 --- a/src/main/java/com/mangopay/core/APIs/PayInApi.java +++ b/src/main/java/com/mangopay/core/APIs/PayInApi.java @@ -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; @@ -123,4 +124,6 @@ public interface PayInApi { * @throws Exception */ List getRefunds(String payInId, Pagination pagination, Sorting sorting) throws Exception; + + CardPreAuthorizedDepositPayIn createCardPreAuthorizedDepositPayIn(CreateCardPreAuthorizedDepositPayIn payIn, String idempotencyKey) throws Exception; } diff --git a/src/main/java/com/mangopay/core/APIs/implementation/DepositApiImpl.java b/src/main/java/com/mangopay/core/APIs/implementation/DepositApiImpl.java new file mode 100644 index 00000000..71f3a73d --- /dev/null +++ b/src/main/java/com/mangopay/core/APIs/implementation/DepositApiImpl.java @@ -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); + } +} diff --git a/src/main/java/com/mangopay/core/APIs/implementation/PayInApiImpl.java b/src/main/java/com/mangopay/core/APIs/implementation/PayInApiImpl.java index d068e711..09628000 100644 --- a/src/main/java/com/mangopay/core/APIs/implementation/PayInApiImpl.java +++ b/src/main/java/com/mangopay/core/APIs/implementation/PayInApiImpl.java @@ -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; @@ -98,6 +99,11 @@ public List 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) @@ -118,4 +124,6 @@ private String getExecutionKey(PayIn payIn) throws Exception { } throw new Exception("Execution is not defined or it is not object type"); } + + } diff --git a/src/main/java/com/mangopay/core/enumerations/DepositStatus.java b/src/main/java/com/mangopay/core/enumerations/DepositStatus.java new file mode 100644 index 00000000..3a38917f --- /dev/null +++ b/src/main/java/com/mangopay/core/enumerations/DepositStatus.java @@ -0,0 +1,12 @@ +package com.mangopay.core.enumerations; + +/** + * Business type enumeration + */ +public enum DepositStatus { + CREATED, + + SUCCEEDED, + + FAILED +} diff --git a/src/main/java/com/mangopay/core/enumerations/EventType.java b/src/main/java/com/mangopay/core/enumerations/EventType.java index 25a06197..2a266d09 100644 --- a/src/main/java/com/mangopay/core/enumerations/EventType.java +++ b/src/main/java/com/mangopay/core/enumerations/EventType.java @@ -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 } diff --git a/src/main/java/com/mangopay/entities/CardPreAuthorizedDepositPayIn.java b/src/main/java/com/mangopay/entities/CardPreAuthorizedDepositPayIn.java new file mode 100644 index 00000000..09de69cf --- /dev/null +++ b/src/main/java/com/mangopay/entities/CardPreAuthorizedDepositPayIn.java @@ -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; + } +} diff --git a/src/main/java/com/mangopay/entities/Deposit.java b/src/main/java/com/mangopay/entities/Deposit.java new file mode 100644 index 00000000..71676cf7 --- /dev/null +++ b/src/main/java/com/mangopay/entities/Deposit.java @@ -0,0 +1,279 @@ +package com.mangopay.entities; + +import com.google.gson.annotations.SerializedName; +import com.mangopay.core.Billing; +import com.mangopay.core.EntityBase; +import com.mangopay.core.Money; +import com.mangopay.core.Shipping; +import com.mangopay.core.enumerations.*; +import com.mangopay.entities.subentities.BrowserInfo; +import com.mangopay.entities.subentities.PayinsLinked; + +/** + * Deposit entity. + */ +public class Deposit extends EntityBase { + @SerializedName("AuthorId") + private String authorId; + + @SerializedName("DebitedFunds") + private Money debitedFunds; + + @SerializedName("Status") + private DepositStatus status; + + @SerializedName("PaymentStatus") + private PaymentStatus paymentStatus; + + @SerializedName("PayinsLinked") + private PayinsLinked payinsLinked; + + @SerializedName("ResultCode") + private String resultCode; + + @SerializedName("ResultMessage") + private String resultMessage; + + @SerializedName("CardId") + private String cardId; + + @SerializedName("SecureModeReturnURL") + private String secureModeReturnUrl; + + @SerializedName("SecureModeRedirectURL") + private String secureModeRedirectUrl; + + @SerializedName("SecureModeNeeded") + private Boolean secureModeNeeded; + + @SerializedName("ExpirationDate") + private Long expirationDate; + + @SerializedName("PaymentType") + private PayInPaymentType paymentType; + + @SerializedName("ExecutionType") + private PayInExecutionType executionType; + + @SerializedName("StatementDescriptor") + private String statementDescriptor; + + @SerializedName("Culture") + private CultureCode culture; + + @SerializedName("IpAddress") + private String ipAddress; + + @SerializedName("BrowserInfo") + private BrowserInfo browserInfo; + + @SerializedName("Billing") + private Billing billing; + + @SerializedName("Shipping") + private Shipping shipping; + + @SerializedName("Requested3DSVersion") + private String requested3DSVersion; + + @SerializedName("Applied3DSVersion") + private String applied3DSVersion; + + public String getAuthorId() { + return authorId; + } + + public Deposit setAuthorId(String authorId) { + this.authorId = authorId; + return this; + } + + public Money getDebitedFunds() { + return debitedFunds; + } + + public Deposit setDebitedFunds(Money debitedFunds) { + this.debitedFunds = debitedFunds; + return this; + } + + public DepositStatus getStatus() { + return status; + } + + public Deposit setStatus(DepositStatus status) { + this.status = status; + return this; + } + + public PaymentStatus getPaymentStatus() { + return paymentStatus; + } + + public Deposit setPaymentStatus(PaymentStatus paymentStatus) { + this.paymentStatus = paymentStatus; + return this; + } + + public PayinsLinked getPayinsLinked() { + return payinsLinked; + } + + public Deposit setPayinsLinked(PayinsLinked payinsLinked) { + this.payinsLinked = payinsLinked; + return this; + } + + public String getResultCode() { + return resultCode; + } + + public Deposit setResultCode(String resultCode) { + this.resultCode = resultCode; + return this; + } + + public String getResultMessage() { + return resultMessage; + } + + public Deposit setResultMessage(String resultMessage) { + this.resultMessage = resultMessage; + return this; + } + + public String getCardId() { + return cardId; + } + + public Deposit setCardId(String cardId) { + this.cardId = cardId; + return this; + } + + public String getSecureModeReturnUrl() { + return secureModeReturnUrl; + } + + public Deposit setSecureModeReturnUrl(String secureModeReturnUrl) { + this.secureModeReturnUrl = secureModeReturnUrl; + return this; + } + + public String getSecureModeRedirectUrl() { + return secureModeRedirectUrl; + } + + public Deposit setSecureModeRedirectUrl(String secureModeRedirectUrl) { + this.secureModeRedirectUrl = secureModeRedirectUrl; + return this; + } + + public Boolean getSecureModeNeeded() { + return secureModeNeeded; + } + + public Deposit setSecureModeNeeded(Boolean secureModeNeeded) { + this.secureModeNeeded = secureModeNeeded; + return this; + } + + public Long getExpirationDate() { + return expirationDate; + } + + public Deposit setExpirationDate(Long expirationDate) { + this.expirationDate = expirationDate; + return this; + } + + public PayInPaymentType getPaymentType() { + return paymentType; + } + + public Deposit setPaymentType(PayInPaymentType paymentType) { + this.paymentType = paymentType; + return this; + } + + public PayInExecutionType getExecutionType() { + return executionType; + } + + public Deposit setExecutionType(PayInExecutionType executionType) { + this.executionType = executionType; + return this; + } + + public String getStatementDescriptor() { + return statementDescriptor; + } + + public Deposit setStatementDescriptor(String statementDescriptor) { + this.statementDescriptor = statementDescriptor; + return this; + } + + public CultureCode getCulture() { + return culture; + } + + public Deposit setCulture(CultureCode culture) { + this.culture = culture; + return this; + } + + public String getIpAddress() { + return ipAddress; + } + + public Deposit setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + public BrowserInfo getBrowserInfo() { + return browserInfo; + } + + public Deposit setBrowserInfo(BrowserInfo browserInfo) { + this.browserInfo = browserInfo; + return this; + } + + public Billing getBilling() { + return billing; + } + + public Deposit setBilling(Billing billing) { + this.billing = billing; + return this; + } + + public Shipping getShipping() { + return shipping; + } + + public Deposit setShipping(Shipping shipping) { + this.shipping = shipping; + return this; + } + + public String getRequested3DSVersion() { + return requested3DSVersion; + } + + public Deposit setRequested3DSVersion(String requested3DSVersion) { + this.requested3DSVersion = requested3DSVersion; + return this; + } + + public String getApplied3DSVersion() { + return applied3DSVersion; + } + + public Deposit setApplied3DSVersion(String applied3DSVersion) { + this.applied3DSVersion = applied3DSVersion; + return this; + } +} diff --git a/src/main/java/com/mangopay/entities/subentities/CancelDeposit.java b/src/main/java/com/mangopay/entities/subentities/CancelDeposit.java new file mode 100644 index 00000000..96d6bb6f --- /dev/null +++ b/src/main/java/com/mangopay/entities/subentities/CancelDeposit.java @@ -0,0 +1,19 @@ +package com.mangopay.entities.subentities; + +import com.google.gson.annotations.SerializedName; +import com.mangopay.core.EntityBase; +import com.mangopay.core.enumerations.PaymentStatus; + +public class CancelDeposit extends EntityBase { + @SerializedName("PaymentStatus") + private PaymentStatus paymentStatus; + + public PaymentStatus getPaymentStatus() { + return paymentStatus; + } + + public CancelDeposit setPaymentStatus(PaymentStatus paymentStatus) { + this.paymentStatus = paymentStatus; + return this; + } +} diff --git a/src/main/java/com/mangopay/entities/subentities/CreateCardPreAuthorizedDepositPayIn.java b/src/main/java/com/mangopay/entities/subentities/CreateCardPreAuthorizedDepositPayIn.java new file mode 100644 index 00000000..9de96105 --- /dev/null +++ b/src/main/java/com/mangopay/entities/subentities/CreateCardPreAuthorizedDepositPayIn.java @@ -0,0 +1,89 @@ +package com.mangopay.entities.subentities; + +import com.google.gson.annotations.SerializedName; +import com.mangopay.core.Dto; +import com.mangopay.core.Money; + +public class CreateCardPreAuthorizedDepositPayIn extends Dto { + @SerializedName("AuthorId") + private String authorId; + + @SerializedName("CreditedWalletId") + private String creditedWalletId; + + @SerializedName("DebitedFunds") + private Money debitedFunds; + + @SerializedName("Fees") + private Money fees; + + @SerializedName("DepositId") + private String depositId; + + @SerializedName("Tag") + private String tag; + + public CreateCardPreAuthorizedDepositPayIn(String creditedWalletId, Money debitedFunds, Money fees, String depositId) { + this.creditedWalletId = creditedWalletId; + this.debitedFunds = debitedFunds; + this.fees = fees; + this.depositId = depositId; + } + + public CreateCardPreAuthorizedDepositPayIn() { + } + + public String getAuthorId() { + return authorId; + } + + public CreateCardPreAuthorizedDepositPayIn setAuthorId(String authorId) { + this.authorId = authorId; + return this; + } + + public String getCreditedWalletId() { + return creditedWalletId; + } + + public CreateCardPreAuthorizedDepositPayIn setCreditedWalletId(String creditedWalletId) { + this.creditedWalletId = creditedWalletId; + return this; + } + + public Money getDebitedFunds() { + return debitedFunds; + } + + public CreateCardPreAuthorizedDepositPayIn setDebitedFunds(Money debitedFunds) { + this.debitedFunds = debitedFunds; + return this; + } + + public Money getFees() { + return fees; + } + + public CreateCardPreAuthorizedDepositPayIn setFees(Money fees) { + this.fees = fees; + return this; + } + + public String getDepositId() { + return depositId; + } + + public CreateCardPreAuthorizedDepositPayIn setDepositId(String depositId) { + this.depositId = depositId; + return this; + } + + public String getTag() { + return tag; + } + + public CreateCardPreAuthorizedDepositPayIn setTag(String tag) { + this.tag = tag; + return this; + } +} diff --git a/src/main/java/com/mangopay/entities/subentities/CreateDeposit.java b/src/main/java/com/mangopay/entities/subentities/CreateDeposit.java new file mode 100644 index 00000000..90d532d0 --- /dev/null +++ b/src/main/java/com/mangopay/entities/subentities/CreateDeposit.java @@ -0,0 +1,142 @@ +package com.mangopay.entities.subentities; + +import com.google.gson.annotations.SerializedName; +import com.mangopay.core.Billing; +import com.mangopay.core.Dto; +import com.mangopay.core.Money; +import com.mangopay.core.Shipping; +import com.mangopay.core.enumerations.CultureCode; + +public class CreateDeposit extends Dto { + @SerializedName("AuthorId") + private String authorId; + + @SerializedName("DebitedFunds") + private Money debitedFunds; + + @SerializedName("CardId") + private String cardId; + + @SerializedName("SecureModeReturnURL") + private String secureModeReturnUrl; + + @SerializedName("StatementDescriptor") + private String statementDescriptor; + + @SerializedName("Culture") + private CultureCode culture; + + @SerializedName("IpAddress") + private String ipAddress; + + @SerializedName("BrowserInfo") + private BrowserInfo browserInfo; + + @SerializedName("Billing") + private Billing billing; + + @SerializedName("Shipping") + private Shipping shipping; + + public CreateDeposit(String authorId, Money debitedFunds, String cardId, String secureModeReturnUrl, String ipAddress, BrowserInfo browserInfo) { + this.authorId = authorId; + this.debitedFunds = debitedFunds; + this.cardId = cardId; + this.secureModeReturnUrl = secureModeReturnUrl; + this.ipAddress = ipAddress; + this.browserInfo = browserInfo; + } + + public CreateDeposit() { + } + + public String getAuthorId() { + return authorId; + } + + public CreateDeposit setAuthorId(String authorId) { + this.authorId = authorId; + return this; + } + + public Money getDebitedFunds() { + return debitedFunds; + } + + public CreateDeposit setDebitedFunds(Money debitedFunds) { + this.debitedFunds = debitedFunds; + return this; + } + + public String getCardId() { + return cardId; + } + + public CreateDeposit setCardId(String cardId) { + this.cardId = cardId; + return this; + } + + public String getSecureModeReturnUrl() { + return secureModeReturnUrl; + } + + public CreateDeposit setSecureModeReturnUrl(String secureModeReturnUrl) { + this.secureModeReturnUrl = secureModeReturnUrl; + return this; + } + + public String getStatementDescriptor() { + return statementDescriptor; + } + + public CreateDeposit setStatementDescriptor(String statementDescriptor) { + this.statementDescriptor = statementDescriptor; + return this; + } + + public CultureCode getCulture() { + return culture; + } + + public CreateDeposit setCulture(CultureCode culture) { + this.culture = culture; + return this; + } + + public String getIpAddress() { + return ipAddress; + } + + public CreateDeposit setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + public BrowserInfo getBrowserInfo() { + return browserInfo; + } + + public CreateDeposit setBrowserInfo(BrowserInfo browserInfo) { + this.browserInfo = browserInfo; + return this; + } + + public Billing getBilling() { + return billing; + } + + public CreateDeposit setBilling(Billing billing) { + this.billing = billing; + return this; + } + + public Shipping getShipping() { + return shipping; + } + + public CreateDeposit setShipping(Shipping shipping) { + this.shipping = shipping; + return this; + } +} diff --git a/src/main/java/com/mangopay/entities/subentities/PayinsLinked.java b/src/main/java/com/mangopay/entities/subentities/PayinsLinked.java new file mode 100644 index 00000000..414f7e79 --- /dev/null +++ b/src/main/java/com/mangopay/entities/subentities/PayinsLinked.java @@ -0,0 +1,30 @@ +package com.mangopay.entities.subentities; + +import com.google.gson.annotations.SerializedName; +import com.mangopay.core.Dto; + +public class PayinsLinked extends Dto { + @SerializedName("PayinCaptureId") + private String payinCaptureId; + + @SerializedName("PayinComplementId") + private String PayinComplementId; + + public String getPayinCaptureId() { + return payinCaptureId; + } + + public PayinsLinked setPayinCaptureId(String payinCaptureId) { + this.payinCaptureId = payinCaptureId; + return this; + } + + public String getPayinComplementId() { + return PayinComplementId; + } + + public PayinsLinked setPayinComplementId(String payinComplementId) { + PayinComplementId = payinComplementId; + return this; + } +} diff --git a/src/test/java/com/mangopay/core/BaseTest.java b/src/test/java/com/mangopay/core/BaseTest.java index 17fc7691..6fb3101c 100644 --- a/src/test/java/com/mangopay/core/BaseTest.java +++ b/src/test/java/com/mangopay/core/BaseTest.java @@ -809,6 +809,18 @@ protected CardRegistration getNewJohnsCardRegistration(CardType cardType) throws return getJohnsCardRegistration(cardType); } + protected CardRegistration getDepositCardRegistration() throws Exception { + UserNatural user = this.getJohn(); + CardRegistration cardRegistration = new CardRegistration(); + cardRegistration.setUserId(user.getId()); + cardRegistration.setCurrency(CurrencyIso.EUR); + CardRegistration newCardRegistration = this.api.getCardRegistrationApi().create(cardRegistration); + + String registrationData = this.getPaylineCorrectRegistartionDataForDeposit(newCardRegistration); + newCardRegistration.setRegistrationData(registrationData); + return this.api.getCardRegistrationApi().update(newCardRegistration); + } + /** * Creates card registration object. */ @@ -873,12 +885,20 @@ protected KycDocument getNewKycDocument() throws Exception { * @return Registration data. */ protected String getPaylineCorrectRegistartionData3DSecure(CardRegistration cardRegistration) throws MalformedURLException, IOException, Exception { + return getPaylineCorrectRegistartionData3DSecureForCardNumber(cardRegistration, "4970105191923460"); + } + + protected String getPaylineCorrectRegistartionDataForDeposit(CardRegistration cardRegistration) throws MalformedURLException, IOException, Exception { + return getPaylineCorrectRegistartionData3DSecureForCardNumber(cardRegistration, "4970105181818183"); + } + + protected String getPaylineCorrectRegistartionData3DSecureForCardNumber(CardRegistration cardRegistration, String cardNumber) throws MalformedURLException, IOException, Exception { String data = "data=" + cardRegistration.getPreregistrationData() + - "&accessKeyRef=" + cardRegistration.getAccessKey() + - "&cardNumber=4970105191923460" + - "&cardExpirationDate=1224" + - "&cardCvx=123"; + "&accessKeyRef=" + cardRegistration.getAccessKey() + + "&cardNumber=" + cardNumber + + "&cardExpirationDate=1224" + + "&cardCvx=123"; URL url = new URL(cardRegistration.getCardRegistrationUrl()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -924,48 +944,7 @@ protected String getPaylineCorrectRegistartionData3DSecure(CardRegistration card * @return Registration data. */ protected String getPaylineCorrectRegistartionData(CardRegistration cardRegistration) throws MalformedURLException, IOException, Exception { - - String data = "data=" + cardRegistration.getPreregistrationData() + - "&accessKeyRef=" + cardRegistration.getAccessKey() + - "&cardNumber=4970105191923460" + - "&cardExpirationDate=1224" + - "&cardCvx=123"; - - URL url = new URL(cardRegistration.getCardRegistrationUrl()); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - - connection.setRequestMethod("POST"); - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - - try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) { - wr.writeBytes(data); - wr.flush(); - } - - int responseCode = connection.getResponseCode(); - InputStream is; - if (responseCode != 200) { - is = connection.getErrorStream(); - } else { - is = connection.getInputStream(); - } - - StringBuffer resp; - try (BufferedReader rd = new BufferedReader(new InputStreamReader(is))) { - String line; - resp = new StringBuffer(); - while ((line = rd.readLine()) != null) { - resp.append(line); - } - } - String responseString = resp.toString(); - - if (responseCode == 200) - return responseString; - else - throw new Exception(responseString); + return getPaylineCorrectRegistartionData3DSecureForCardNumber(cardRegistration, "4970105191923460"); } protected Hook getJohnsHook() throws Exception { @@ -1078,6 +1057,24 @@ protected BankAccount getClientBankAccount() throws Exception { return this.api.getClientApi().createBankAccountIBAN(bankAccountIBAN); } + protected Deposit createNewDeposit() throws Exception { + User john = this.getJohn(); + CardRegistration cardRegistration = this.getDepositCardRegistration(); + + Money debitedFunds = new Money(CurrencyIso.EUR, 1000); + + CreateDeposit dto = new CreateDeposit( + john.getId(), + debitedFunds, + cardRegistration.getCardId(), + "http://lorem", + "2001:0620:0000:0000:0211:24FF:FE80:C12C", + getNewBrowserInfo() + ); + + return this.api.getDepositApi().create(dto, null); + } + protected void assertEqualInputProps(T entity1, T entity2) throws Exception { if (entity1 instanceof UserNatural) { diff --git a/src/test/java/com/mangopay/core/DepositApiImplTest.java b/src/test/java/com/mangopay/core/DepositApiImplTest.java new file mode 100644 index 00000000..207494a1 --- /dev/null +++ b/src/test/java/com/mangopay/core/DepositApiImplTest.java @@ -0,0 +1,53 @@ +package com.mangopay.core; + +import com.mangopay.core.enumerations.PaymentStatus; +import com.mangopay.entities.Deposit; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +/** + * DepositApiImpl test methods. + */ +public class DepositApiImplTest extends BaseTest { + + @Test + public void createDeposit() { + try { + Deposit deposit = this.createNewDeposit(); + + Assert.assertNotNull(deposit); + } catch (Exception ex) { + Assert.fail(ex.getMessage()); + } + } + + @Test + public void getDeposit() { + try { + Deposit deposit = this.createNewDeposit(); + Deposit fetchedDeposit = this.api.getDepositApi().get(deposit.getId()); + + Assert.assertNotNull(fetchedDeposit); + Assert.assertEquals(deposit.getId(), fetchedDeposit.getId()); + } catch (Exception ex) { + Assert.fail(ex.getMessage()); + } + } + + @Ignore("Manual deposit confirmation needed") + @Test + public void cancelDeposit() { + try { + Deposit deposit = this.createNewDeposit(); + this.api.getDepositApi().cancel(deposit.getId()); + + Deposit canceledDeposit = this.api.getDepositApi().get(deposit.getId()); + + Assert.assertNotNull(canceledDeposit); + Assert.assertEquals(PaymentStatus.CANCELED, canceledDeposit.getPaymentStatus()); + } catch (Exception ex) { + Assert.fail(ex.getMessage()); + } + } +} diff --git a/src/test/java/com/mangopay/core/PayInApiImplTest.java b/src/test/java/com/mangopay/core/PayInApiImplTest.java index dee63897..ba1d5869 100644 --- a/src/test/java/com/mangopay/core/PayInApiImplTest.java +++ b/src/test/java/com/mangopay/core/PayInApiImplTest.java @@ -3,6 +3,7 @@ import com.mangopay.core.enumerations.*; import com.mangopay.entities.*; import com.mangopay.entities.subentities.*; +import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -882,4 +883,29 @@ public void testIssue220() { } } + + @Ignore("Manual deposit confirmation needed") + @Test + public void testCreateCardPreAuthorizedDepositPayIn() { + try { + Deposit deposit = this.createNewDeposit(); + Wallet wallet = this.getJohnsWallet(); + + Money debitedFunds = new Money(CurrencyIso.EUR, 1000); + Money fees = new Money(CurrencyIso.EUR, 0); + + CreateCardPreAuthorizedDepositPayIn dto = new CreateCardPreAuthorizedDepositPayIn( + wallet.getId(), + debitedFunds, + fees, + deposit.getId() + ); + + CardPreAuthorizedDepositPayIn payIn = this.api.getPayInApi().createCardPreAuthorizedDepositPayIn(dto, null); + + Assert.assertNotNull(payIn); + } catch (Exception ex) { + Assert.fail(ex.getMessage()); + } + } }