com.payu.sdk.api.ApiClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-client Show documentation
Show all versions of api-client Show documentation
A fresh implementation of the PayU API Client for Android
The newest version!
package com.payu.sdk.api;
import com.payu.sdk.api.model.Bank;
import com.payu.sdk.api.model.CreditCard;
import com.payu.sdk.api.model.Language;
import com.payu.sdk.api.model.Order;
import com.payu.sdk.api.model.PaymentMethods;
import com.payu.sdk.api.model.TransactionResponse;
import com.payu.sdk.api.model.mobile.DeviceIdentifierResponse;
import com.payu.sdk.api.model.mobile.SenderIdResponse;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.payu.sdk.base.Preconditions.checkArg;
import static com.payu.sdk.base.Preconditions.checkStringArg;
import static com.payu.sdk.base.Preconditions.isNull;
public final class ApiClient {
private final String apiKey;
private final String apiLogin;
private final String applicationFingerprint;
private final String applicationPackage;
private final URI paymentsURI;
private final URI reportsURI;
private final Language language;
private final boolean enableTest;
private final boolean enableLog;
private final Mobile mobileApi;
private final Reports reportsApi;
private final Payments paymentsApi;
private ApiClient(Builder builder) {
this.apiKey = builder.apiKey;
this.apiLogin = builder.apiLogin;
this.applicationFingerprint = builder.applicationFingerprint;
this.applicationPackage = builder.applicationPackage;
this.paymentsURI = builder.paymentsURI;
this.reportsURI = builder.reportsURI;
this.language = builder.language;
this.enableTest = builder.enableTest;
this.enableLog = builder.enableLog;
final RawApi rawApi = new RawApi(this.apiLogin, this.apiKey).isDebug(this.enableLog)
.setPaymentsUrl(this.paymentsURI.toString())
.setReportsUrl(this.reportsURI.toString())
.setFingerprint(this.applicationFingerprint);
final RequestCreator requestCreator =
new RequestCreator(this.apiKey, this.apiLogin, this.applicationFingerprint,
this.applicationPackage).isTest(this.enableTest).language(this.language);
mobileApi = new Mobile(rawApi, requestCreator);
reportsApi = new Reports(rawApi, requestCreator);
paymentsApi = new Payments(rawApi, requestCreator);
}
public Builder builder() {
return new Builder(this);
}
/**
* You can use this method to verify connectivity to our Payment platform.
*/
public void paymentsDoPing(Callback callback) {
paymentsApi.doPing(callback);
}
public void getPaymentMethods(Callback> callback) {
paymentsApi.getPaymentMethods(callback);
}
public void getListPSEBanks(Callback> callback) {
paymentsApi.getListPSEBanks(callback);
}
/**
* You can use this method to verify connectivity to our Reports platform.
*/
public void reportsDoPing(Callback callback) {
reportsApi.doPing(callback);
}
public void doOrderDetailReportingById(Map parameters, Callback callback) {
reportsApi.doOrderDetailReportingById(parameters, callback);
}
public void doOrderDetailReportingByReferenceCode(Map parameters,
Callback> callback) {
reportsApi.doOrderDetailReportingByReferenceCode(parameters, callback);
}
public void doTransactionResponseReporting(HashMap parameters,
Callback callback) {
reportsApi.doTransactionResponseReporting(parameters, callback);
}
public void registerInstallation(Map parameters,
Callback callback) {
mobileApi.registerInstallation(parameters, callback);
}
public void authorizeInstallation(Map parameters,
Callback callback) {
mobileApi.authorizeInstallation(parameters, callback);
}
public void findDeviceTokens(Map parameters,
Callback> callback) {
mobileApi.findDeviceTokens(parameters, callback);
}
public void getSenderId(Callback callback) {
mobileApi.getSenderId(callback);
}
public static class Builder {
private final String apiKey;
private final String apiLogin;
private final String applicationFingerprint;
private final String applicationPackage;
private URI paymentsURI;
private URI reportsURI;
private Language language;
private boolean enableTest;
private boolean enableLog;
private Builder(ApiClient apiClient) {
this.apiKey = apiClient.apiKey;
this.apiLogin = apiClient.apiLogin;
this.applicationFingerprint = apiClient.applicationFingerprint;
this.applicationPackage = apiClient.applicationPackage;
this.paymentsURI = apiClient.paymentsURI;
this.reportsURI = apiClient.reportsURI;
this.language = apiClient.language;
this.enableTest = apiClient.enableTest;
this.enableLog = apiClient.enableLog;
}
public Builder(String apiKey, String apiLogin, String applicationFingerprint,
String applicationPackage) {
checkStringArg(apiKey, "apiKey must not be null.");
checkStringArg(apiLogin, "apiLogin must not be null");
checkStringArg(applicationFingerprint, "applicationFingerprint must not be null");
checkStringArg(applicationPackage, "applicationPackage must not be null");
this.apiKey = apiKey;
this.apiLogin = apiLogin;
this.applicationFingerprint = applicationFingerprint;
this.applicationPackage = applicationPackage;
}
public Builder paymentsURI(URI paymentsURI) {
checkArg(paymentsURI, "paymentsURI must not be null");
this.paymentsURI = paymentsURI;
return this;
}
public Builder reportsURI(URI reportsURI) {
checkArg(reportsURI, "reportsUri must not be null");
this.reportsURI = reportsURI;
return this;
}
public Builder language(Language language) {
checkArg(language, "language must not be null");
this.language = language;
return this;
}
public Builder enableTestMode(boolean enableTest) {
this.enableTest = enableTest;
return this;
}
public Builder enableLog(boolean enableLog) {
this.enableLog = enableLog;
return this;
}
/** Create the {@link ApiClient} instance. */
public ApiClient build() {
if (isNull(paymentsURI)) {
paymentsURI = URI.create(ApiEndpoints.PAYMENTS_PRODUCTION.url);
}
if (isNull(reportsURI)) {
reportsURI = URI.create(ApiEndpoints.REPORTS_PRODUCTION.url);
}
if (isNull(language)) {
language = Language.en;
}
return new ApiClient(this);
}
}
}