use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.
the class ValueLinkServices method disablePin.
public static Map<String, Object> disablePin(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
Properties props = getProperties(context);
String cardNumber = (String) context.get("cardNumber");
String pin = (String) context.get("pin");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
BigDecimal amount = (BigDecimal) context.get("amount");
Locale locale = (Locale) context.get("locale");
// get an api instance
ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
Map<String, Object> request = vl.getInitialRequestMap(context);
request.put("Interface", "Disable");
request.put("CardNo", cardNumber);
request.put("PIN", vl.encryptPin(pin));
request.put("Amount", vl.getAmount(amount));
// user defined field #1
if (UtilValidate.isNotEmpty(orderId)) {
request.put("User1", orderId);
}
// user defined field #2
if (UtilValidate.isNotEmpty(partyId)) {
request.put("User2", partyId);
}
// send the request
Map<String, Object> response = null;
try {
response = vl.send(request);
} catch (HttpClientException e) {
Debug.logError(e, "Problem communicating with VL");
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToDisablePin", locale));
}
String responseCode = (String) response.get("responsecode");
Map<String, Object> result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "AccountingValueLinkPinDisabled", locale));
result.put("processResult", "00".equals(responseCode));
result.put("responseCode", responseCode);
result.put("balance", vl.getAmount((String) response.get("currbal")));
result.put("expireDate", response.get("expiredate"));
result.put("cardClass", response.get("cardclass"));
result.put("referenceNum", response.get("traceno"));
Debug.logInfo("Disable Result : " + result, module);
return result;
}
use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.
the class ValueLinkServices method redeem.
public static Map<String, Object> redeem(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
Properties props = getProperties(context);
String cardNumber = (String) context.get("cardNumber");
String pin = (String) context.get("pin");
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
BigDecimal amount = (BigDecimal) context.get("amount");
Locale locale = (Locale) context.get("locale");
// override interface for void/rollback
String iFace = (String) context.get("Interface");
// get an api instance
ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
Map<String, Object> request = vl.getInitialRequestMap(context);
request.put("Interface", iFace != null ? iFace : "Redeem");
request.put("CardNo", cardNumber);
request.put("PIN", vl.encryptPin(pin));
request.put("Amount", vl.getAmount(amount));
request.put("LocalCurr", vl.getCurrency(currency));
// user defined field #1
if (UtilValidate.isNotEmpty(orderId)) {
request.put("User1", orderId);
}
// user defined field #2
if (UtilValidate.isNotEmpty(partyId)) {
request.put("User2", partyId);
}
// set the timeout reversal
setTimeoutReversal(dctx, context, request);
// send the request
Map<String, Object> response = null;
try {
response = vl.send(request);
} catch (HttpClientException e) {
Debug.logError(e, "Problem communicating with VL");
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToRedeemGiftCard", locale));
}
String responseCode = (String) response.get("responsecode");
Map<String, Object> result = ServiceUtil.returnSuccess();
result.put("processResult", "00".equals(responseCode));
result.put("responseCode", responseCode);
result.put("authCode", response.get("authcode"));
result.put("previousAmount", vl.getAmount((String) response.get("prevbal")));
result.put("amount", vl.getAmount((String) response.get("newbal")));
result.put("expireDate", response.get("expiredate"));
result.put("cardClass", response.get("cardclass"));
result.put("cashBack", vl.getAmount((String) response.get("cashback")));
result.put("referenceNum", response.get("traceno"));
Debug.logInfo("Redeem Result : " + result, module);
return result;
}
use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.
the class ClearCommerceException method sendRequest.
private static Document sendRequest(Document requestDocument, String paymentConfig, Delegator delegator) throws ClearCommerceException {
if (UtilValidate.isEmpty(paymentConfig)) {
paymentConfig = "payment.properties";
}
String serverURL = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.serverURL", delegator);
if (UtilValidate.isEmpty(serverURL)) {
throw new ClearCommerceException("Missing server URL; check your ClearCommerce configuration");
}
if (Debug.verboseOn()) {
Debug.logVerbose("ClearCommerce server URL: " + serverURL, module);
}
OutputStream os = new ByteArrayOutputStream();
try {
UtilXml.writeXmlDocument(requestDocument, os, "UTF-8", true, false, 0);
} catch (TransformerException e) {
throw new ClearCommerceException("Error serializing requestDocument: " + e.getMessage());
}
String xmlString = os.toString();
if (Debug.verboseOn()) {
Debug.logVerbose("ClearCommerce XML request string: " + xmlString, module);
}
HttpClient http = new HttpClient(serverURL);
http.setParameter("CLRCMRC_XML", xmlString);
String response = null;
try {
response = http.post();
} catch (HttpClientException hce) {
Debug.logInfo(hce, module);
throw new ClearCommerceException("ClearCommerce connection problem", hce);
}
Document responseDocument = null;
try {
responseDocument = UtilXml.readXmlDocument(response, false);
} catch (Exception e) {
throw new ClearCommerceException("Error reading response Document from a String: " + e.getMessage());
}
if (Debug.verboseOn()) {
Debug.logVerbose("Result severity from clearCommerce:" + getMessageListMaxSev(responseDocument), module);
}
if (Debug.verboseOn() && getMessageListMaxSev(responseDocument) > maxSevComp) {
Debug.logVerbose("Returned messages:" + getMessageList(responseDocument), module);
}
return responseDocument;
}
use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.
the class ValueLinkServices method balanceInquire.
public static Map<String, Object> balanceInquire(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
Properties props = getProperties(context);
String cardNumber = (String) context.get("cardNumber");
String pin = (String) context.get("pin");
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
Locale locale = (Locale) context.get("locale");
// get an api instance
ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
Map<String, Object> request = vl.getInitialRequestMap(context);
request.put("Interface", "Balance");
request.put("CardNo", cardNumber);
request.put("PIN", vl.encryptPin(pin));
request.put("LocalCurr", vl.getCurrency(currency));
// user defined field #1
if (UtilValidate.isNotEmpty(orderId)) {
request.put("User1", orderId);
}
// user defined field #2
if (UtilValidate.isNotEmpty(partyId)) {
request.put("User2", partyId);
}
// send the request
Map<String, Object> response = null;
try {
response = vl.send(request);
} catch (HttpClientException e) {
Debug.logError(e, "Problem communicating with VL");
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToCallBalanceInquiry", locale));
}
String responseCode = (String) response.get("responsecode");
Map<String, Object> result = ServiceUtil.returnSuccess();
result.put("processResult", "00".equals(responseCode));
result.put("responseCode", responseCode);
result.put("balance", vl.getAmount((String) response.get("currbal")));
result.put("expireDate", response.get("expiredate"));
result.put("cardClass", response.get("cardclass"));
result.put("referenceNum", response.get("traceno"));
Debug.logInfo("Balance Result : " + result, module);
return result;
}
use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.
the class ValueLinkServices method activate.
public static Map<String, Object> activate(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
Properties props = getProperties(context);
String vlPromoCode = (String) context.get("vlPromoCode");
String cardNumber = (String) context.get("cardNumber");
String pin = (String) context.get("pin");
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
BigDecimal amount = (BigDecimal) context.get("amount");
Locale locale = (Locale) context.get("locale");
// override interface for void/rollback
String iFace = (String) context.get("Interface");
// get an api instance
ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
Map<String, Object> request = vl.getInitialRequestMap(context);
request.put("Interface", iFace != null ? iFace : "Activate");
if (UtilValidate.isNotEmpty(vlPromoCode)) {
request.put("PromoCode", vlPromoCode);
}
request.put("Amount", vl.getAmount(amount));
request.put("LocalCurr", vl.getCurrency(currency));
if (UtilValidate.isNotEmpty(cardNumber)) {
request.put("CardNo", cardNumber);
}
if (UtilValidate.isNotEmpty(pin)) {
request.put("PIN", vl.encryptPin(pin));
}
// user defined field #1
if (UtilValidate.isNotEmpty(orderId)) {
request.put("User1", orderId);
}
// user defined field #2
if (UtilValidate.isNotEmpty(partyId)) {
request.put("User2", partyId);
}
// set the timeout reversal
setTimeoutReversal(dctx, context, request);
// send the request
Map<String, Object> response = null;
try {
response = vl.send(request);
} catch (HttpClientException e) {
Debug.logError(e, "Problem communicating with VL");
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToActivateGiftCard", locale));
}
String responseCode = (String) response.get("responsecode");
Map<String, Object> result = ServiceUtil.returnSuccess();
if ("00".equals(responseCode)) {
result.put("processResult", Boolean.TRUE);
result.put("pin", vl.decryptPin((String) response.get("pin")));
} else {
result.put("processResult", Boolean.FALSE);
result.put("pin", response.get("PIN"));
}
result.put("responseCode", responseCode);
result.put("authCode", response.get("authcode"));
result.put("cardNumber", response.get("cardno"));
result.put("amount", vl.getAmount((String) response.get("currbal")));
result.put("expireDate", response.get("expiredate"));
result.put("cardClass", response.get("cardclass"));
result.put("referenceNum", response.get("traceno"));
Debug.logInfo("Activate Result : " + result, module);
return result;
}
Aggregations