Skip to content

Commit

Permalink
Merge pull request #68 from VKNikov/master
Browse files Browse the repository at this point in the history
Added DCC and MCP requests. Added preAuth transaction type.
  • Loading branch information
BozhidarDedelyanov authored Jan 22, 2021
2 parents 6c432a0 + 827be67 commit 0359a00
Show file tree
Hide file tree
Showing 44 changed files with 913 additions and 329 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.safecharge</groupId>
<artifactId>safecharge-sdk-java</artifactId>
<version>1.4.4</version>
<version>1.5.0</version>

<name>Safecharge SDK for Java</name>
<description>SafeCharge’s REST API SDK for Java provides developer tools for accessing Safecharge's REST API. SafeCharge’s REST API is a simple,
Expand Down
49 changes: 43 additions & 6 deletions src/main/java/com/safecharge/biz/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import com.safecharge.model.Addendums;
import com.safecharge.model.AmountDetails;
import com.safecharge.model.CashierUserDetails;
import com.safecharge.model.CurrencyConversion;
import com.safecharge.model.RestApiUserDetails;
import com.safecharge.model.DeviceDetails;
import com.safecharge.model.DynamicDescriptor;
import com.safecharge.model.ExternalSchemeDetails;
Expand All @@ -21,9 +22,11 @@
import com.safecharge.model.Verify3dPaymentOption;
import com.safecharge.request.Authorize3dRequest;
import com.safecharge.request.CardDetailsRequest;
import com.safecharge.request.DccDetailsRequest;
import com.safecharge.request.GetPaymentStatusRequest;
import com.safecharge.request.GetSessionTokenRequest;
import com.safecharge.request.InitPaymentRequest;
import com.safecharge.request.McpRatesRequest;
import com.safecharge.request.OpenOrderRequest;
import com.safecharge.request.PaymentRequest;
import com.safecharge.request.RefundTransactionRequest;
Expand All @@ -47,12 +50,12 @@ public SafechargeBaseRequest getSessionTokenRequest(MerchantInfo merchantInfo) {
public SafechargeBaseRequest getPaymentRequest(MerchantInfo merchantInfo, String sessionToken, String userTokenId, String clientUniqueId,
String clientRequestId, PaymentOption paymentOption, Integer isRebilling, String currency,
String amount, AmountDetails amountDetails, List<Item> items, DeviceDetails deviceDetails,
CashierUserDetails userDetails, UserAddress shippingAddress, UserAddress billingAddress,
RestApiUserDetails userDetails, UserAddress shippingAddress, UserAddress billingAddress,
DynamicDescriptor dynamicDescriptor, MerchantDetails merchantDetails, Addendums addendums,
UrlDetails urlDetails, String customSiteName, String productId, String customData,
String relatedTransactionId, Constants.TransactionType transactionType, Boolean autoPayment3D,
String isMoto, SubMerchant subMerchant, String rebillingType, String authenticationOnlyType,
String userId, ExternalSchemeDetails externalSchemeDetails) {
String userId, ExternalSchemeDetails externalSchemeDetails, CurrencyConversion currencyConversion) {
return PaymentRequest.builder()
.addSessionToken(sessionToken)
.addIsRebilling(isRebilling)
Expand Down Expand Up @@ -85,6 +88,7 @@ public SafechargeBaseRequest getPaymentRequest(MerchantInfo merchantInfo, String
.addAuthenticationOnlyType(authenticationOnlyType)
.addUserId(userId)
.addExternalSchemeDetails(externalSchemeDetails)
.addCurrencyConversion(currencyConversion)
.build();
}

Expand All @@ -110,7 +114,7 @@ public SafechargeBaseRequest getInitPaymentRequest(String sessionToken, String u

public SafechargeBaseRequest getOpenOrderRequest(MerchantInfo merchantInfo, String sessionToken, String clientRequestId, String customSiteName,
String productId, OpenOrderPaymentOption paymentOption, Constants.TransactionType transactionType,
String currency, String amount, List<Item> items, DeviceDetails deviceDetails, CashierUserDetails userDetails,
String currency, String amount, List<Item> items, DeviceDetails deviceDetails, RestApiUserDetails userDetails,
UserAddress shippingAddress, UserAddress billingAddress, DynamicDescriptor dynamicDescriptor, MerchantDetails merchantDetails,
UrlDetails urlDetails, String userTokenId, String clientUniqueId, UserPaymentOption userPaymentOption,
String paymentMethod, AmountDetails amountDetails, Addendums addendums, String customData, Boolean autoPayment3D,
Expand Down Expand Up @@ -256,11 +260,12 @@ public SafechargeBaseRequest getVerify3dRequest(String sessionToken, MerchantInf
public SafechargeBaseRequest getAuthorize3dRequest(MerchantInfo merchantInfo, String sessionToken, String userTokenId, String clientUniqueId,
String clientRequestId, PaymentOption paymentOption, Integer isRebilling, String currency,
String amount, AmountDetails amountDetails, List<Item> items, DeviceDetails deviceDetails,
CashierUserDetails userDetails, UserAddress shippingAddress, UserAddress billingAddress,
RestApiUserDetails userDetails, UserAddress shippingAddress, UserAddress billingAddress,
DynamicDescriptor dynamicDescriptor, MerchantDetails merchantDetails, Addendums addendums,
UrlDetails urlDetails, String customSiteName, String productId, String customData,
String relatedTransactionId, Constants.TransactionType transactionType, Boolean autoPayment3D,
SubMerchant subMerchant, String userId) {
SubMerchant subMerchant, String userId, ExternalSchemeDetails externalSchemeDetails,
CurrencyConversion currencyConversion) {
return Authorize3dRequest.builder()
.addSessionToken(sessionToken)
.addIsRebilling(isRebilling)
Expand Down Expand Up @@ -289,6 +294,8 @@ public SafechargeBaseRequest getAuthorize3dRequest(MerchantInfo merchantInfo, St
.addAutoPayment3D(autoPayment3D)
.addSubMerchant(subMerchant)
.addUserId(userId)
.addExternalSchemeDetails(externalSchemeDetails)
.addCurrencyConversion(currencyConversion)
.build();
}

Expand All @@ -302,4 +309,34 @@ public CardDetailsRequest getCardDetailsRequest(String sessionToken, MerchantInf
.addCardNumber(cardNumber)
.build();
}

public DccDetailsRequest getDccDetailsRequest(String sessionToken, MerchantInfo merchantInfo, String clientUniqueId,
String clientRequestId, String cardNumber, String apm, String originalAmount,
String originalCurrency, String currency, String country) {
return DccDetailsRequest.builder()
.addSessionToken(sessionToken)
.addMerchantInfo(merchantInfo)
.addClientUniqueId(clientUniqueId)
.addClientRequestId(clientRequestId)
.addCardNumber(cardNumber)
.addApm(apm)
.addOriginalAmount(originalAmount)
.addOriginalCurrency(originalCurrency)
.addCurrency(currency)
.addCountry(country)
.build();
}

public McpRatesRequest getMcpRatesRequest(String sessionToken, MerchantInfo merchantInfo, String clientUniqueId, String clientRequestId,
String fromCurrency, List<String> toCurrency, List<String> paymentMethods) {
return McpRatesRequest.builder()
.addSessionToken(sessionToken)
.addMerchantInfo(merchantInfo)
.addClientUniqueId(clientUniqueId)
.addClientRequestId(clientRequestId)
.addFromCurrency(fromCurrency)
.addToCurrency(toCurrency)
.addPaymentMethods(paymentMethods)
.build();
}
}
46 changes: 37 additions & 9 deletions src/main/java/com/safecharge/biz/Safecharge.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.safecharge.exception.SafechargeException;
import com.safecharge.model.Addendums;
import com.safecharge.model.AmountDetails;
import com.safecharge.model.CashierUserDetails;
import com.safecharge.model.CurrencyConversion;
import com.safecharge.model.RestApiUserDetails;
import com.safecharge.model.DeviceDetails;
import com.safecharge.model.DynamicDescriptor;
import com.safecharge.model.ExternalSchemeDetails;
Expand All @@ -22,11 +23,15 @@
import com.safecharge.model.UserPaymentOption;
import com.safecharge.model.Verify3dPaymentOption;
import com.safecharge.request.CardDetailsRequest;
import com.safecharge.request.DccDetailsRequest;
import com.safecharge.request.McpRatesRequest;
import com.safecharge.request.SafechargeBaseRequest;
import com.safecharge.response.Authorize3dResponse;
import com.safecharge.response.CardDetailsResponse;
import com.safecharge.response.DccDetailsResponse;
import com.safecharge.response.GetPaymentStatusResponse;
import com.safecharge.response.InitPaymentResponse;
import com.safecharge.response.McpRatesResponse;
import com.safecharge.response.OpenOrderResponse;
import com.safecharge.response.PaymentResponse;
import com.safecharge.response.RefundTransactionResponse;
Expand Down Expand Up @@ -141,17 +146,18 @@ private String getSessionToken() throws SafechargeException {
*/
public PaymentResponse payment(String userTokenId, String clientUniqueId, String clientRequestId, PaymentOption paymentOption, Integer isRebilling,
String currency, String amount, AmountDetails amountDetails, List<Item> items, DeviceDetails deviceDetails,
CashierUserDetails userDetails, UserAddress shippingAddress, UserAddress billingAddress, DynamicDescriptor dynamicDescriptor,
RestApiUserDetails userDetails, UserAddress shippingAddress, UserAddress billingAddress, DynamicDescriptor dynamicDescriptor,
MerchantDetails merchantDetails, Addendums addendums, UrlDetails urlDetails, String customSiteName, String productId,
String customData, String relatedTransactionId, Constants.TransactionType transactionType, Boolean autoPayment3D,
String isMoto, SubMerchant subMerchant, String rebillingType, String authenticationOnlyType, String userId, ExternalSchemeDetails externalSchemeDetails) throws SafechargeException {
String isMoto, SubMerchant subMerchant, String rebillingType, String authenticationOnlyType, String userId,
ExternalSchemeDetails externalSchemeDetails, CurrencyConversion currencyConversion) throws SafechargeException {
ensureMerchantInfoAndSessionTokenNotNull();

RequestBuilder requestBuilder = serviceFactory.getRequestBuilder();
SafechargeBaseRequest request = requestBuilder.getPaymentRequest(merchantInfo, sessionToken, userTokenId, clientUniqueId, clientRequestId, paymentOption,
isRebilling, currency, amount, amountDetails, items, deviceDetails, userDetails, shippingAddress, billingAddress,
dynamicDescriptor, merchantDetails, addendums, urlDetails, customSiteName, productId, customData, relatedTransactionId,
transactionType, autoPayment3D, isMoto, subMerchant, rebillingType, authenticationOnlyType, userId, externalSchemeDetails);
transactionType, autoPayment3D, isMoto, subMerchant, rebillingType, authenticationOnlyType, userId, externalSchemeDetails, currencyConversion);

return (PaymentResponse) requestExecutor.execute(request);
}
Expand Down Expand Up @@ -246,7 +252,7 @@ public InitPaymentResponse initPayment(String userTokenId, String clientUniqueId
*/
public OpenOrderResponse openOrder(String userTokenId, String clientRequestId, String clientUniqueId, String customSiteName, String productId,
OpenOrderPaymentOption paymentOption, Constants.TransactionType transactionType, String currency, String amount,
List<Item> items, DeviceDetails deviceDetails, CashierUserDetails userDetails, UserAddress shippingAddress,
List<Item> items, DeviceDetails deviceDetails, RestApiUserDetails userDetails, UserAddress shippingAddress,
UserAddress billingAddress, DynamicDescriptor dynamicDescriptor, MerchantDetails merchantDetails,
UrlDetails urlDetails, UserPaymentOption userPaymentOption, String paymentMethod, AmountDetails amountDetails,
Addendums addendums, String customData, Boolean autoPayment3D, String isMoto, String authenticationOnlyType,
Expand Down Expand Up @@ -429,7 +435,7 @@ public RefundTransactionResponse refundTransaction(String clientUniqueId, String
* @param customSiteName The merchant’s site name. This is useful for merchants operating many websites that are distinguished only by name.
* @param merchantDetails
* @param relatedTransactionId The transaction ID of the of the call to {@link Safecharge#authorize3d(String, String, String,
* PaymentOption, Integer, String, String, AmountDetails, List, DeviceDetails, CashierUserDetails, UserAddress,
* PaymentOption, Integer, String, String, AmountDetails, List, DeviceDetails, RestApiUserDetails, UserAddress,
* UserAddress, DynamicDescriptor, MerchantDetails, Addendums, UrlDetails, String, String, String, String,
* Constants.TransactionType, Boolean, SubMerchant, String)}.
* @param subMerchant Contains information about the SubMerchant.
Expand Down Expand Up @@ -505,18 +511,19 @@ public Verify3dResponse verify3d(String clientUniqueId, String clientRequestId,
*/
public Authorize3dResponse authorize3d(String userTokenId, String clientUniqueId, String clientRequestId, PaymentOption paymentOption,
Integer isRebilling, String currency, String amount, AmountDetails amountDetails,
List<Item> items, DeviceDetails deviceDetails, CashierUserDetails userDetails,
List<Item> items, DeviceDetails deviceDetails, RestApiUserDetails userDetails,
UserAddress shippingAddress, UserAddress billingAddress, DynamicDescriptor dynamicDescriptor,
MerchantDetails merchantDetails, Addendums addendums, UrlDetails urlDetails,
String customSiteName, String productId, String customData, String relatedTransactionId,
Constants.TransactionType transactionType, Boolean autoPayment3D, SubMerchant subMerchant, String userId) throws SafechargeException {
Constants.TransactionType transactionType, Boolean autoPayment3D, SubMerchant subMerchant,
String userId, ExternalSchemeDetails externalSchemeDetails, CurrencyConversion currencyConversion) throws SafechargeException {
ensureMerchantInfoAndSessionTokenNotNull();

RequestBuilder requestBuilder = serviceFactory.getRequestBuilder();
SafechargeBaseRequest request = requestBuilder.getAuthorize3dRequest(merchantInfo, sessionToken, userTokenId, clientUniqueId,
clientRequestId, paymentOption, isRebilling, currency, amount, amountDetails, items, deviceDetails, userDetails,
shippingAddress, billingAddress, dynamicDescriptor, merchantDetails, addendums, urlDetails, customSiteName,
productId, customData, relatedTransactionId, transactionType, autoPayment3D, subMerchant, userId);
productId, customData, relatedTransactionId, transactionType, autoPayment3D, subMerchant, userId, externalSchemeDetails, currencyConversion);

return (Authorize3dResponse) requestExecutor.execute(request);
}
Expand All @@ -539,4 +546,25 @@ public CardDetailsResponse getCardDetails(String clientUniqueId, String clientRe

return (CardDetailsResponse) requestExecutor.execute(request);
}

public DccDetailsResponse getDccDetails(String clientUniqueId, String clientRequestId, String cardNumber, String apm, String originalAmount,
String originalCurrency, String currency, String country) throws SafechargeException {
ensureMerchantInfoAndSessionTokenNotNull();

RequestBuilder requestBuilder = serviceFactory.getRequestBuilder();
DccDetailsRequest request = requestBuilder.getDccDetailsRequest(sessionToken, merchantInfo, clientUniqueId, clientRequestId, cardNumber,
apm, originalAmount, originalCurrency, currency, country);

return (DccDetailsResponse) requestExecutor.execute(request);
}

public McpRatesResponse getMcpRates(String clientUniqueId, String clientRequestId, String fromCurrency, List<String> toCurrency, List<String> paymentMethods) throws SafechargeException {
ensureMerchantInfoAndSessionTokenNotNull();

RequestBuilder requestBuilder = serviceFactory.getRequestBuilder();
McpRatesRequest request = requestBuilder.getMcpRatesRequest(sessionToken, merchantInfo, clientUniqueId, clientRequestId, fromCurrency,
toCurrency, paymentMethods);

return (McpRatesResponse) requestExecutor.execute(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class SafechargeRequestExecutor {
put(Verify3dRequest.class, Verify3dResponse.class);
put(Authorize3dRequest.class, Authorize3dResponse.class);
put(CardDetailsRequest.class, CardDetailsResponse.class);
put(DccDetailsRequest.class, DccDetailsResponse.class);
put(McpRatesRequest.class, McpRatesResponse.class);
}
};
private static final Map<Class<? extends SafechargeBaseRequest>, String> REQUEST_URL_BY_REQUEST_TYPE =
Expand Down Expand Up @@ -121,6 +123,8 @@ public class SafechargeRequestExecutor {
put(Verify3dRequest.class, APIConstants.VERIFY3D_URL);
put(Authorize3dRequest.class, APIConstants.AUTHORIZE3D_URL);
put(CardDetailsRequest.class, APIConstants.GET_CARD_DETAILS_URL);
put(DccDetailsRequest.class, APIConstants.DCC_DETAILS_URL);
put(McpRatesRequest.class, APIConstants.MCP_RATES_URL);
}
};

Expand Down Expand Up @@ -258,6 +262,7 @@ public String executeRequest(String request, String serviceUrl, Header[] headers
Class<? extends SafechargeResponse> responseClass = RESPONSE_TYPE_BY_REQUEST_TYPE.get(requestClass);
logger.debug(responseClass.getSimpleName() + " Received " + responseJSON);
}

return responseJSON;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/safecharge/model/ApiExternalToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Copyright (C) 2007-2017 SafeCharge International Group Limited.
* <p>
* Holder for Cashier's Payment Gateway external token data.
* Holder for Checkout Page's Payment Gateway external token data.
*
* @author <a mailto:[email protected]>Nikola Dichev</a>
* @since 3/10/2017
Expand Down
Loading

0 comments on commit 0359a00

Please sign in to comment.