Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversions #329

Merged
merged 11 commits into from
Mar 8, 2024
12 changes: 6 additions & 6 deletions src/main/java/com/mangopay/MangoPayApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public MangoPayApi() {
setSettlementApi(new SettlementApiImpl(this));
setRegulatoryApi(new RegulatoryApiImpl(this));
setDepositApi(new DepositApiImpl(this));
setInstantConversionApi(new InstantConversionApiImpl(this));
setConversionsApi(new ConversionsApiImpl(this));
setGson(gsonBuilder.create());
}

Expand Down Expand Up @@ -206,7 +206,7 @@ public MangoPayApi() {
/**
* Provides Instant conversion methods
*/
private InstantConversionApi instantConversionApi;
private ConversionsApi conversionApi;

private Gson gson;

Expand Down Expand Up @@ -447,11 +447,11 @@ public MangoPayApi setDepositApi(DepositApi depositApi) {
return this;
}

public InstantConversionApi getInstantConversionApi() {
return instantConversionApi;
public ConversionsApi getConversionsApi() {
return conversionApi;
}

public void setInstantConversionApi(InstantConversionApi instantConversionApi) {
this.instantConversionApi = instantConversionApi;
public void setConversionsApi(ConversionsApi conversionApi) {
this.conversionApi = conversionApi;
}
}
17 changes: 9 additions & 8 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ protected MangoPayApi getRoot() {
put("deposits_get", new String[]{"/deposit-preauthorizations/%s", RequestType.GET.toString()});
put("deposits_cancel", new String[]{"/deposit-preauthorizations/%s", RequestType.PUT.toString()});

put("get_conversion_rate", new String[]{"/conversion/rate/%s/%s", RequestType.GET.toString()});
put("create_instant_conversion", new String[]{"/instant-conversion", RequestType.POST.toString()});
put("get_instant_conversion", new String[]{"/instant-conversion/%s", RequestType.GET.toString()});

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_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 Expand Up @@ -329,11 +331,10 @@ protected <T extends Dto, U extends Dto> T createObject(Class<T> classOfT, Strin
}

/**
*
* @param classOfT Type on behalf of which the request is being called.
* @param classOfT Type on behalf of which the request is being called.
* @param methodKey Relevant method key.
* @param args Arguments that will be set on the method
* @param <T> Type on behalf of which the request is being called.
* @param args Arguments that will be set on the method
* @param <T> Type on behalf of which the request is being called.
* @return The Dto instance returned from API.
* @throws Exception
*/
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/mangopay/core/APIs/ConversionsApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mangopay.core.APIs;

import com.mangopay.entities.*;

public interface ConversionsApi {

/**
* This endpoint allows the platform to get a real
* time indicative market rate of a specific currency pair.
* The rate returned is given in real time.
* @param debitedCurrency The sell currency – the currency of the wallet to be debited
* @param creditedCurrency The buy currency – the currency of the wallet to be credited.
* @return ConversionRate object returned from API
*/
ConversionRate getConversionRate(String debitedCurrency, String creditedCurrency) throws Exception;

/**
* This endpoint allows the platform to move funds between two
* wallets of different currencies instantaneously.
* @return InstantConversion object returned from API
*/
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
*/
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(CreateConversionQuote createConversionQuote, String idempotencyKey) throws Exception;

/**
* This endpoint allows the platform to get the details of a quote
*
* @param quoteId The unique identifier of the quote
* @return Quote object returned from API
*/
ConversionQuote getConversionQuote(String quoteId) throws Exception;

}
32 changes: 0 additions & 32 deletions src/main/java/com/mangopay/core/APIs/InstantConversionApi.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mangopay.core.APIs.implementation;

import com.mangopay.MangoPayApi;
import com.mangopay.core.APIs.ApiBase;
import com.mangopay.core.APIs.ConversionsApi;
import com.mangopay.entities.*;

public class ConversionsApiImpl extends ApiBase implements ConversionsApi {

/**
* Creates new API instance.
*
* @param root Root/parent instance that holds the OAuthToken and Configuration instance.
*/
public ConversionsApiImpl(MangoPayApi root) {
super(root);
}

@Override
public ConversionRate getConversionRate(String debitedCurrency, String creditedCurrency) throws Exception {
return this.getObject(ConversionRate.class, "get_conversion_rate", debitedCurrency, creditedCurrency);
}

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

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

@Override
public Conversion getConversion(String id) throws Exception {
return this.getObject(Conversion.class, "get_conversion", id);
}

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

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

This file was deleted.

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
* Information about the fees taken by the platform for
* this transaction (and hence transferred to the Fees Wallet).
*/
@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:
*/
@SerializedName("Nature")
public TransactionNature nature;
@SerializedName("Fees")
public Money fees;

/**
* The code indicates the result of the operation.
Expand All @@ -88,6 +94,20 @@ public class InstantConversion extends EntityBase {
@SerializedName("ExecutionDate")
public Long executionDate;

/**
* Real time indicative market rate of a specific currency pair
*/
@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 Expand Up @@ -184,6 +204,14 @@ public void setExecutionDate(Long executionDate) {
this.executionDate = executionDate;
}

public Money getFees() {
return fees;
}

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

@Override
public ArrayList<String> getReadOnlyProperties() {
ArrayList<String> result = super.getReadOnlyProperties();
Expand Down
Loading
Loading