Skip to content

Commit

Permalink
Refactors Disbursement and Remittance
Browse files Browse the repository at this point in the history
  • Loading branch information
regisbamba committed May 5, 2019
1 parent 77ba9a4 commit 5108a05
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 437 deletions.
29 changes: 5 additions & 24 deletions src/main/java/ci/bamba/regis/Collections.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package ci.bamba.regis;

import ci.bamba.regis.exceptions.RequestException;
import ci.bamba.regis.models.AccountBalance;
import ci.bamba.regis.models.AccountStatus;
import ci.bamba.regis.models.CollectionsRequestToPay;
import ci.bamba.regis.models.CollectionsRequestToPayBodyRequest;
import ci.bamba.regis.models.RequestToPay;
import ci.bamba.regis.models.Token;
import io.reactivex.Observable;

Expand All @@ -28,32 +26,15 @@ public Observable<String> requestToPay(float amount, String currency, String ext

public Observable<String> requestToPay(String token, float amount, String currency, String externalId,
String payerPartyId, String payerMessage, String payeeNote) {
CollectionsRequestToPayBodyRequest body = new CollectionsRequestToPayBodyRequest(String.format("%s", amount),
currency, externalId, payerPartyId, payerMessage, payeeNote);
String referenceId = getUUID();
return RestClient.getService(getBaseUrl()).collectionsCreateRequestToPay(getAuthHeader(token),
getSubscriptionKey(), referenceId, getEnvironment().getEnv(), body).map(response -> {
if (response.code() == 202) {
return referenceId;
} else {
throw new RequestException(response.code(), response.message());
}
});
return super.requestToPay(TYPE, token, amount, currency, externalId, payerPartyId, payerMessage, payeeNote);
}

public Observable<CollectionsRequestToPay> getRequestToPay(String referenceId) {
public Observable<RequestToPay> getRequestToPay(String referenceId) {
return createToken().flatMap(token -> getRequestToPay(token.getAccessToken(), referenceId));
}

public Observable<CollectionsRequestToPay> getRequestToPay(String token, String referenceId) {
return RestClient.getService(getBaseUrl()).collectionsGetRequestToPay(getAuthHeader(token),
getSubscriptionKey(), getEnvironment().getEnv(), referenceId).map(response -> {
if (response.code() == 200) {
return response.body();
} else {
throw new RequestException(response.code(), response.message());
}
});
public Observable<RequestToPay> getRequestToPay(String token, String referenceId) {
return super.getRequestToPay(TYPE, token, referenceId);
}

public Observable<AccountBalance> getAccountBalance() {
Expand Down
43 changes: 12 additions & 31 deletions src/main/java/ci/bamba/regis/Disbursements.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package ci.bamba.regis;

import ci.bamba.regis.exceptions.RequestException;
import ci.bamba.regis.models.AccountBalance;
import ci.bamba.regis.models.AccountStatus;
import ci.bamba.regis.models.DisbursementsTransfer;
import ci.bamba.regis.models.DisbursementsTransferBodyRequest;
import ci.bamba.regis.models.Token;
import ci.bamba.regis.models.Transfer;
import io.reactivex.Observable;

public class Disbursements extends Product {
Expand All @@ -20,48 +18,31 @@ public Observable<Token> createToken() {
return super.createToken(TYPE);
}

public Observable<String> transfer(float amount, String currency, String externalId, String payeePartyId, String payerMessage, String payeeNote) {
return createToken().flatMap(token -> transfer(token.getAccessToken(), amount, currency, externalId, payeePartyId, payerMessage, payeeNote));
public Observable<String> transfer(float amount, String currency, String externalId, String payeePartyId,
String payerMessage, String payeeNote) {
return createToken().flatMap(token -> transfer(token.getAccessToken(), amount, currency, externalId,
payeePartyId, payerMessage, payeeNote));
}

public Observable<String> transfer(String token, float amount, String currency, String externalId, String payeePartyId, String payerMessage, String payeeNote) {
DisbursementsTransferBodyRequest body = new DisbursementsTransferBodyRequest(String.format("%s", amount), currency, externalId, payeePartyId, payerMessage, payeeNote);
String referenceId = getUUID();
return RestClient
.getService(getBaseUrl())
.disbursementsCreateTransfer(getAuthHeader(token), getSubscriptionKey(), referenceId, getEnvironment().getEnv(), body)
.map(response -> {
if (response.code() == 202) {
return referenceId;
} else {
throw new RequestException(response.code(), response.message());
}
});
public Observable<String> transfer(String token, float amount, String currency, String externalId,
String payeePartyId, String payerMessage, String payeeNote) {
return super.transfer(TYPE, token, amount, currency, externalId, payeePartyId, payerMessage, payeeNote);
}

public Observable<DisbursementsTransfer> getTransfer(String referenceId) {
public Observable<Transfer> getTransfer(String referenceId) {
return createToken().flatMap(token -> getTransfer(token.getAccessToken(), referenceId));
}

public Observable<DisbursementsTransfer> getTransfer(String token, String referenceId) {
return RestClient
.getService(getBaseUrl())
.disbursementsGetTransfer(getAuthHeader(token), getSubscriptionKey(), getEnvironment().getEnv(), referenceId)
.map(response -> {
if (response.code() == 200) {
return response.body();
} else {
throw new RequestException(response.code(), response.message());
}
});
public Observable<Transfer> getTransfer(String token, String referenceId) {
return super.getTransfer(TYPE, token, referenceId);
}

public Observable<AccountBalance> getAccountBalance() {
return createToken().flatMap(token -> getAccountBalance(token.getAccessToken()));
}

public Observable<AccountBalance> getAccountBalance(String token) {
return super.getAccountBalance(TYPE, token);
return super.getAccountBalance(TYPE, token);
}

public Observable<AccountStatus> getAccountStatus(String msisdn) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ci/bamba/regis/MoMo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class MoMo {

private static final String BASE_URL_SANDBOX = "https://ericssonbasicapi2.azure-api.net/";
private static final String BASE_URL_PRODUCTION = "https://ericssonbasicapi1.azure-api.net";
private static final String BASE_URL_PRODUCTION = "https://ericssonbasicapi1.azure-api.net/";

private Environment environment;

Expand Down
57 changes: 57 additions & 0 deletions src/main/java/ci/bamba/regis/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import ci.bamba.regis.models.AccountBalance;
import ci.bamba.regis.models.AccountStatus;
import ci.bamba.regis.models.ApiCredentials;
import ci.bamba.regis.models.RequestToPay;
import ci.bamba.regis.models.RequestToPayBodyRequest;
import ci.bamba.regis.models.Token;
import ci.bamba.regis.models.Transfer;
import ci.bamba.regis.models.TransferBodyRequest;
import io.reactivex.Observable;

public class Product {
Expand Down Expand Up @@ -65,6 +69,59 @@ protected String getAuthHeader(String token) {
return String.format("Bearer %s", token);
}

public Observable<String> transfer(String type, String token, float amount, String currency,
String externalId, String payeePartyId, String payerMessage, String payeeNote) {
TransferBodyRequest body = new TransferBodyRequest(String.format("%s", amount), currency, externalId,
payeePartyId, payerMessage, payeeNote);
String referenceId = getUUID();
return RestClient.getService(getBaseUrl()).createTransfer(type, getAuthHeader(token), getSubscriptionKey(),
referenceId, getEnvironment().getEnv(), body).map(response -> {
if (response.code() == 202) {
return referenceId;
} else {
throw new RequestException(response.code(), response.message());
}
});
}

public Observable<Transfer> getTransfer(String type, String token, String referenceId) {
return RestClient.getService(getBaseUrl())
.getTransfer(type, getAuthHeader(token), getSubscriptionKey(), getEnvironment().getEnv(), referenceId)
.map(response -> {
if (response.code() == 200) {
return response.body();
} else {
throw new RequestException(response.code(), response.message());
}
});
}

public Observable<String> requestToPay(String type, String token, float amount, String currency, String externalId,
String payerPartyId, String payerMessage, String payeeNote) {
RequestToPayBodyRequest body = new RequestToPayBodyRequest(String.format("%s", amount), currency, externalId,
payerPartyId, payerMessage, payeeNote);
String referenceId = getUUID();
return RestClient.getService(getBaseUrl()).createRequestToPay(type, getAuthHeader(token), getSubscriptionKey(),
referenceId, getEnvironment().getEnv(), body).map(response -> {
if (response.code() == 202) {
return referenceId;
} else {
throw new RequestException(response.code(), response.message());
}
});
}

public Observable<RequestToPay> getRequestToPay(String type, String token, String referenceId) {
return RestClient.getService(getBaseUrl()).getRequestToPay(type, getAuthHeader(token), getSubscriptionKey(),
getEnvironment().getEnv(), referenceId).map(response -> {
if (response.code() == 200) {
return response.body();
} else {
throw new RequestException(response.code(), response.message());
}
});
}

protected Observable<AccountBalance> getAccountBalance(String type, String token) {
return RestClient.getService(getBaseUrl())
.getAccountBalance(type, getAuthHeader(token), getSubscriptionKey(), getEnvironment().getEnv())
Expand Down
29 changes: 5 additions & 24 deletions src/main/java/ci/bamba/regis/Remittances.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package ci.bamba.regis;

import ci.bamba.regis.exceptions.RequestException;
import ci.bamba.regis.models.AccountBalance;
import ci.bamba.regis.models.AccountStatus;
import ci.bamba.regis.models.RemittancesTransfer;
import ci.bamba.regis.models.RemittancesTransferBodyRequest;
import ci.bamba.regis.models.Token;
import ci.bamba.regis.models.Transfer;
import io.reactivex.Observable;

public class Remittances extends Product {
Expand All @@ -28,32 +26,15 @@ public Observable<String> transfer(float amount, String currency, String externa

public Observable<String> transfer(String token, float amount, String currency, String externalId,
String payeePartyId, String payerMessage, String payeeNote) {
RemittancesTransferBodyRequest body = new RemittancesTransferBodyRequest(String.format("%s", amount), currency,
externalId, payeePartyId, payerMessage, payeeNote);
String referenceId = getUUID();
return RestClient.getService(getBaseUrl()).remittancesCreateTransfer(getAuthHeader(token), getSubscriptionKey(),
referenceId, getEnvironment().getEnv(), body).map(response -> {
if (response.code() == 202) {
return referenceId;
} else {
throw new RequestException(response.code(), response.message());
}
});
return super.transfer(TYPE, token, amount, currency, externalId, payeePartyId, payerMessage, payeeNote);
}

public Observable<RemittancesTransfer> getTransfer(String referenceId) {
public Observable<Transfer> getTransfer(String referenceId) {
return createToken().flatMap(token -> getTransfer(token.getAccessToken(), referenceId));
}

public Observable<RemittancesTransfer> getTransfer(String token, String referenceId) {
return RestClient.getService(getBaseUrl()).remittancesGetTransfer(getAuthHeader(token), getSubscriptionKey(),
getEnvironment().getEnv(), referenceId).map(response -> {
if (response.code() == 200) {
return response.body();
} else {
throw new RequestException(response.code(), response.message());
}
});
public Observable<Transfer> getTransfer(String token, String referenceId) {
return super.getTransfer(TYPE, token, referenceId);
}

public Observable<AccountBalance> getAccountBalance() {
Expand Down
57 changes: 21 additions & 36 deletions src/main/java/ci/bamba/regis/RestClient.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package ci.bamba.regis;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import ci.bamba.regis.models.AccountBalance;
import ci.bamba.regis.models.AccountStatus;
import ci.bamba.regis.models.ApiKey;
import ci.bamba.regis.models.ApiUser;
import ci.bamba.regis.models.CollectionsRequestToPay;
import ci.bamba.regis.models.DisbursementsTransfer;
import ci.bamba.regis.models.DisbursementsTransferBodyRequest;
import ci.bamba.regis.models.RemittancesTransfer;
import ci.bamba.regis.models.RemittancesTransferBodyRequest;
import ci.bamba.regis.models.RequestToPay;
import ci.bamba.regis.models.RequestToPayBodyRequest;
import ci.bamba.regis.models.Token;
import ci.bamba.regis.models.Transfer;
import ci.bamba.regis.models.TransferBodyRequest;
import io.reactivex.Observable;
import ci.bamba.regis.models.CollectionsRequestToPayBodyRequest;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
Expand Down Expand Up @@ -96,51 +94,38 @@ Observable<Response<Token>> createToken(
@Path("type") String type
);

@POST("collection/v1_0/requesttopay")
Observable<Response<Void>> collectionsCreateRequestToPay(
@Header("Authorization") String authorization,
@Header("Ocp-Apim-Subscription-Key") String subscriptionKey,
@Header("X-Reference-Id") String referenceId,
@Header("X-Target-Environment") String targetEnvironment,
@Body CollectionsRequestToPayBodyRequest body
);

@POST("disbursement/v1_0/transfer")
Observable<Response<Void>> disbursementsCreateTransfer(
@POST("{type}/v1_0/requesttopay")
Observable<Response<Void>> createRequestToPay(
@Path("type") String type,
@Header("Authorization") String authorization,
@Header("Ocp-Apim-Subscription-Key") String subscriptionKey,
@Header("X-Reference-Id") String referenceId,
@Header("X-Target-Environment") String targetEnvironment,
@Body DisbursementsTransferBodyRequest body
@Body RequestToPayBodyRequest body
);

@POST("remittance/v1_0/transfer")
Observable<Response<Void>> remittancesCreateTransfer(
@POST("{type}/v1_0/transfer")
Observable<Response<Void>> createTransfer(
@Path("type") String type,
@Header("Authorization") String authorization,
@Header("Ocp-Apim-Subscription-Key") String subscriptionKey,
@Header("X-Reference-Id") String referenceId,
@Header("X-Target-Environment") String targetEnvironment,
@Body RemittancesTransferBodyRequest body
@Body TransferBodyRequest body
);

@GET("collection/v1_0/requesttopay/{referenceId}")
Observable<Response<CollectionsRequestToPay>> collectionsGetRequestToPay(
@Header("Authorization") String authorization,
@Header("Ocp-Apim-Subscription-Key") String subscriptionKey,
@Header("X-Target-Environment") String targetEnvironment,
@Path("referenceId") String referenceId
);

@GET("disbursement/v1_0/transfer/{referenceId}")
Observable<Response<DisbursementsTransfer>> disbursementsGetTransfer(
@GET("{type}/v1_0/requesttopay/{referenceId}")
Observable<Response<RequestToPay>> getRequestToPay(
@Path("type") String type,
@Header("Authorization") String authorization,
@Header("Ocp-Apim-Subscription-Key") String subscriptionKey,
@Header("X-Target-Environment") String targetEnvironment,
@Path("referenceId") String referenceId
);

@GET("remittance/v1_0/transfer/{referenceId}")
Observable<Response<RemittancesTransfer>> remittancesGetTransfer(
@GET("{type}/v1_0/transfer/{referenceId}")
Observable<Response<Transfer>> getTransfer(
@Path("type") String type,
@Header("Authorization") String authorization,
@Header("Ocp-Apim-Subscription-Key") String subscriptionKey,
@Header("X-Target-Environment") String targetEnvironment,
Expand Down
Loading

0 comments on commit 5108a05

Please sign in to comment.