Skip to content

Commit

Permalink
improvements on conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimoiseanu committed Mar 7, 2024
1 parent 346c0b8 commit 310503d
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected MangoPayApi getRoot() {

put("get_conversion_rate", new String[]{"/conversions/rate/%s/%s", RequestType.GET.toString()});
put("create_instant_conversion", new String[]{"/conversions/instant-conversion", RequestType.POST.toString()});
put("get_instant_conversion", new String[]{"/conversions/%s", RequestType.GET.toString()});
put("get_conversion", new String[]{"/conversions/%s", RequestType.GET.toString()});
put("create_conversion_quote", new String[]{"/conversions/quote", RequestType.POST.toString()});
put("get_conversion_quote", new String[]{"/conversions/quote/%s", RequestType.GET.toString()});
put("create_quoted_conversion", new String[]{"/conversions/quoted-conversion", RequestType.POST.toString()});
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/com/mangopay/core/APIs/ConversionsApi.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.mangopay.core.APIs;

import com.mangopay.entities.ConversionQuote;
import com.mangopay.entities.ConversionRate;
import com.mangopay.entities.InstantConversion;
import com.mangopay.entities.QuotedConversion;
import com.mangopay.entities.*;

public interface ConversionsApi {

Expand All @@ -22,22 +19,29 @@ public interface ConversionsApi {
* wallets of different currencies instantaneously.
* @return InstantConversion object returned from API
*/
InstantConversion createInstantConversion(InstantConversion conversion, String idempotencyKey) throws Exception;
Conversion createInstantConversion(CreateInstantConversion createInstantConversion, String idempotencyKey) throws Exception;

/**
* This call triggers a conversion, at the rate guaranteed by its quote, of the debited funds to the credited wallet.
*
* @return QuotedConversion
*/
Conversion createQuotedConversion(CreateQuotedConversion quotedConversion, String idempotencyKey) throws Exception;

/**
* This endpoint allows the platform to get
* the details of a conversion which has been carried out.
* @param id The unique identifier of the conversion.
* @return InstantConversion object returned from API
*/
InstantConversion getInstantConversion(String id) throws Exception;
Conversion getConversion(String id) throws Exception;

/**
* This call guarantees a conversion rate to let you Create a Quoted Conversion.
*
* @return Quote object returned from API
*/
ConversionQuote createConversionQuote(ConversionQuote conversionQuote, String idempotencyKey) throws Exception;
ConversionQuote createConversionQuote(CreateConversionQuote createConversionQuote, String idempotencyKey) throws Exception;

/**
* This endpoint allows the platform to get the details of a quote
Expand All @@ -47,11 +51,4 @@ public interface ConversionsApi {
*/
ConversionQuote getConversionQuote(String quoteId) throws Exception;


/**
* This call triggers a conversion, at the rate guaranteed by its quote, of the debited funds to the credited wallet.
*
* @return QuotedConversion
*/
QuotedConversion createQuotedConversion(QuotedConversion quotedConversion, String idempotencyKey) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.mangopay.MangoPayApi;
import com.mangopay.core.APIs.ApiBase;
import com.mangopay.core.APIs.ConversionsApi;
import com.mangopay.entities.ConversionQuote;
import com.mangopay.entities.ConversionRate;
import com.mangopay.entities.InstantConversion;
import com.mangopay.entities.QuotedConversion;
import com.mangopay.entities.*;

public class ConversionsApiImpl extends ApiBase implements ConversionsApi {

Expand All @@ -25,27 +22,27 @@ public ConversionRate getConversionRate(String debitedCurrency, String creditedC
}

@Override
public InstantConversion createInstantConversion(InstantConversion conversion, String idempotencyKey) throws Exception {
return this.createObject(InstantConversion.class, idempotencyKey, "create_instant_conversion", conversion);
public Conversion createInstantConversion(CreateInstantConversion createInstantConversion, String idempotencyKey) throws Exception {
return this.createObject(Conversion.class, idempotencyKey, "create_instant_conversion", createInstantConversion);
}

@Override
public InstantConversion getInstantConversion(String id) throws Exception {
return this.getObject(InstantConversion.class, "get_instant_conversion", id);
public Conversion createQuotedConversion(CreateQuotedConversion quotedConversion, String idempotencyKey) throws Exception {
return this.createObject(Conversion.class, idempotencyKey, "create_quoted_conversion", quotedConversion);
}

@Override
public ConversionQuote createConversionQuote(ConversionQuote conversionQuote, String idempotencyKey) throws Exception {
return this.createObject(ConversionQuote.class, idempotencyKey, "create_conversion_quote", conversionQuote);
public Conversion getConversion(String id) throws Exception {
return this.getObject(Conversion.class, "get_conversion", id);
}

@Override
public ConversionQuote getConversionQuote(String quoteId) throws Exception {
return this.getObject(ConversionQuote.class, "get_conversion_quote", quoteId);
public ConversionQuote createConversionQuote(CreateConversionQuote createConversionQuote, String idempotencyKey) throws Exception {
return this.createObject(ConversionQuote.class, idempotencyKey, "create_conversion_quote", createConversionQuote);
}

@Override
public QuotedConversion createQuotedConversion(QuotedConversion quotedConversion, String idempotencyKey) throws Exception {
return this.createObject(QuotedConversion.class, idempotencyKey, "create_quoted_conversion", quotedConversion);
public ConversionQuote getConversionQuote(String quoteId) throws Exception {
return this.getObject(ConversionQuote.class, "get_conversion_quote", quoteId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,32 @@

import java.util.ArrayList;

public class InstantConversion extends EntityBase {
public class Conversion extends EntityBase {

/**
* The unique identifier of the active quote which guaranteed the rate for the conversion.
*/
@SerializedName("QuoteId")
public String quoteId;

/**
* The type of transaction
*/
@SerializedName("Type")
public TransactionType type;

/**
* The nature of the transaction, providing more
* information about the context in which the transaction occurred:
*/
@SerializedName("Nature")
public TransactionNature nature;

/**
* The status of the transaction.
*/
@SerializedName("Status")
public TransactionStatus status;

/**
* The unique identifier of the user at the source of the transaction.
Expand All @@ -35,37 +60,18 @@ public class InstantConversion extends EntityBase {
@SerializedName("DebitedFunds")
public Money debitedFunds;


/**
* The buy funds
*/
@SerializedName("CreditedFunds")
public Money creditedFunds;

/**
* Real time indicative market rate of a specific currency pair
*/
@SerializedName("ConversionRate")
public ConversionRate conversionRate;

/**
* The status of the transaction.
*/
@SerializedName("Status")
public TransactionStatus status;

/**
* The type of transaction
*/
@SerializedName("Type")
public TransactionType type;

/**
* The nature of the transaction, providing more
* information about the context in which the transaction occurred:
* Information about the fees taken by the platform for
* this transaction (and hence transferred to the Fees Wallet).
*/
@SerializedName("Nature")
public TransactionNature nature;
@SerializedName("Fees")
public Money fees;

/**
* The code indicates the result of the operation.
Expand All @@ -89,11 +95,18 @@ public class InstantConversion extends EntityBase {
public Long executionDate;

/**
* Information about the fees taken by the platform for
* this transaction (and hence transferred to the Fees Wallet).
* Real time indicative market rate of a specific currency pair
*/
@SerializedName("Fees")
public Money fees;
@SerializedName("ConversionRateResponse")
public ConversionRate conversionRate;

public String getQuoteId() {
return quoteId;
}

public void setQuoteId(String quoteId) {
this.quoteId = quoteId;
}

public String getAuthorId() {
return authorId;
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/mangopay/entities/CreateConversionQuote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mangopay.entities;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.Dto;
import com.mangopay.core.Money;

public class CreateConversionQuote extends Dto {
@SerializedName("Duration")
private int duration;
@SerializedName("DebitedFunds")
private Money debitedFunds;
@SerializedName("CreditedFunds")
private Money creditedFunds;
@SerializedName("TAG")
private String tag;

public int getDuration() {
return duration;
}

public void setDuration(int duration) {
this.duration = duration;
}

public Money getDebitedFunds() {
return debitedFunds;
}

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

public Money getCreditedFunds() {
return creditedFunds;
}

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

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}
}
107 changes: 107 additions & 0 deletions src/main/java/com/mangopay/entities/CreateInstantConversion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.mangopay.entities;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.Dto;
import com.mangopay.core.Money;

public class CreateInstantConversion extends Dto {

/**
* The unique identifier of the user at the source of the transaction.
*/
@SerializedName("AuthorId")
public String authorId;

/**
* The unique identifier of the debited wallet.
*/
@SerializedName("DebitedWalletId")
public String debitedWalletId;

/**
* The unique identifier of the credited wallet
*/
@SerializedName("CreditedWalletId")
public String creditedWalletId;

/**
* The sell funds
*/
@SerializedName("DebitedFunds")
public Money debitedFunds;

/**
* The buy funds
*/
@SerializedName("CreditedFunds")
public Money creditedFunds;

/**
* Information about the fees taken by the platform for
* this transaction (and hence transferred to the Fees Wallet).
*/
@SerializedName("Fees")
public Money fees;

/**
* Custom data.
*/
@SerializedName("Tag")
private String tag;

public String getAuthorId() {
return authorId;
}

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

public String getDebitedWalletId() {
return debitedWalletId;
}

public void setDebitedWalletId(String debitedWalletId) {
this.debitedWalletId = debitedWalletId;
}

public String getCreditedWalletId() {
return creditedWalletId;
}

public void setCreditedWalletId(String creditedWalletId) {
this.creditedWalletId = creditedWalletId;
}

public Money getDebitedFunds() {
return debitedFunds;
}

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

public Money getCreditedFunds() {
return creditedFunds;
}

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

public Money getFees() {
return fees;
}

public void setFees(Money fees) {
this.fees = fees;
}

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}
}
Loading

0 comments on commit 310503d

Please sign in to comment.