use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class PaymentGatewayServices method refundOrderPaymentPreference.
public static Map<String, Object> refundOrderPaymentPreference(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
String orderPaymentPreferenceId = (String) context.get("orderPaymentPreferenceId");
BigDecimal amount = (BigDecimal) context.get("amount");
Locale locale = (Locale) context.get("locale");
GenericValue orderPaymentPreference = null;
try {
orderPaymentPreference = EntityQuery.use(delegator).from("OrderPaymentPreference").where("orderPaymentPreferenceId", orderPaymentPreferenceId).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingProblemGettingOrderPaymentPreferences", locale) + " " + orderPaymentPreferenceId);
}
// call the service refundPayment
Map<String, Object> refundResponse = null;
try {
Map<String, Object> serviceContext = new HashMap<>();
serviceContext.put("orderPaymentPreference", orderPaymentPreference);
serviceContext.put("refundAmount", amount);
serviceContext.put("userLogin", userLogin);
refundResponse = dispatcher.runSync("refundPayment", serviceContext, TX_TIME, true);
if (ServiceUtil.isError(refundResponse)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(refundResponse));
}
} catch (GenericServiceException e) {
Debug.logError(e, "Problem refunding payment through processor", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentRefundError", locale));
}
refundResponse.putAll(ServiceUtil.returnSuccess(UtilProperties.getMessage(resourceError, "AccountingPaymentRefundedSuccessfully", UtilMisc.toMap("paymentId", refundResponse.get("paymentId"), "refundAmount", refundResponse.get("refundAmount")), locale)));
return refundResponse;
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class PaymentGatewayServices method retryFailedAuths.
public static Map<String, Object> retryFailedAuths(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
EntityQuery eq = EntityQuery.use(delegator).from("OrderPaymentPreference").where(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PAYMENT_NOT_AUTH"), EntityCondition.makeCondition("processAttempt", EntityOperator.GREATER_THAN, Long.valueOf(0))).orderBy("orderId");
try (EntityListIterator eli = eq.queryIterator()) {
List<String> processList = new LinkedList<>();
if (eli != null) {
Debug.logInfo("Processing failed order re-auth(s)", module);
GenericValue value = null;
while (((value = eli.next()) != null)) {
String orderId = value.getString("orderId");
if (!processList.contains(orderId)) {
// just try each order once
try {
// each re-try is independent of each other; if one fails it should not effect the others
dispatcher.runAsync("retryFailedOrderAuth", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin));
processList.add(orderId);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
}
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
return ServiceUtil.returnSuccess();
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class ValueLinkServices method giftCardRefund.
public static Map<String, Object> giftCardRefund(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Locale locale = (Locale) context.get("locale");
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
String paymentConfig = (String) context.get("paymentConfig");
String currency = (String) context.get("currency");
BigDecimal amount = (BigDecimal) context.get("refundAmount");
// get the orderId for tracking
String orderId = paymentPref.getString("orderId");
// get the GiftCard VO
GenericValue giftCard = null;
try {
giftCard = paymentPref.getRelatedOne("GiftCard", false);
} catch (GenericEntityException e) {
Debug.logError("Unable to get GiftCard from OrderPaymentPreference", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotLocateItFromOrderPaymentPreference", locale));
}
if (giftCard == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToReleaseGiftCard", locale));
}
// make sure we have a currency
if (currency == null) {
currency = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
Map<String, Object> refundCtx = new HashMap<String, Object>();
refundCtx.put("userLogin", userLogin);
refundCtx.put("paymentConfig", paymentConfig);
refundCtx.put("cardNumber", giftCard.get("cardNumber"));
refundCtx.put("pin", giftCard.get("pinNumber"));
refundCtx.put("currency", currency);
refundCtx.put("orderId", orderId);
refundCtx.put("amount", amount);
// invoke the refund service
Map<String, Object> redeemResult = null;
try {
redeemResult = dispatcher.runSync("refundGiftCard", refundCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Problem calling the refund service", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToRefundGiftCardFailure", locale));
}
Map<String, Object> result = ServiceUtil.returnSuccess();
if (redeemResult != null) {
Boolean processResult = (Boolean) redeemResult.get("processResult");
result.put("refundAmount", redeemResult.get("amount"));
result.put("refundFlag", redeemResult.get("responseCode"));
result.put("refundResult", processResult);
result.put("refundCode", redeemResult.get("authCode"));
result.put("refundRefNum", redeemResult.get("referenceNum"));
}
return result;
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class ValueLinkServices method giftCardProcessor.
// payment processing wrappers (process/release/refund)
public static Map<String, Object> giftCardProcessor(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
Locale locale = (Locale) context.get("locale");
GenericValue giftCard = (GenericValue) context.get("giftCard");
GenericValue party = (GenericValue) context.get("billToParty");
String paymentConfig = (String) context.get("paymentConfig");
String currency = (String) context.get("currency");
String orderId = (String) context.get("orderId");
BigDecimal amount = (BigDecimal) context.get("processAmount");
// make sure we have a currency
if (currency == null) {
currency = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
Map<String, Object> redeemCtx = new HashMap<String, Object>();
redeemCtx.put("userLogin", userLogin);
redeemCtx.put("paymentConfig", paymentConfig);
redeemCtx.put("cardNumber", giftCard.get("cardNumber"));
redeemCtx.put("pin", giftCard.get("pinNumber"));
redeemCtx.put("currency", currency);
redeemCtx.put("orderId", orderId);
redeemCtx.put("partyId", party.get("partyId"));
redeemCtx.put("amount", amount);
// invoke the redeem service
Map<String, Object> redeemResult = null;
try {
redeemResult = dispatcher.runSync("redeemGiftCard", redeemCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Problem calling the redeem service", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToRedeemGiftCardFailure", locale));
}
Map<String, Object> result = ServiceUtil.returnSuccess();
if (redeemResult != null) {
Boolean processResult = (Boolean) redeemResult.get("processResult");
// confirm the amount redeemed; since VL does not error in insufficient funds
if (processResult.booleanValue()) {
BigDecimal previous = (BigDecimal) redeemResult.get("previousAmount");
if (previous == null)
previous = BigDecimal.ZERO;
BigDecimal current = (BigDecimal) redeemResult.get("amount");
if (current == null)
current = BigDecimal.ZERO;
BigDecimal redeemed = previous.subtract(current);
Debug.logInfo("Redeemed (" + amount + "): " + redeemed + " / " + previous + " : " + current, module);
if (redeemed.compareTo(amount) < 0) {
// we didn't redeem enough void the transaction and return false
Map<String, Object> voidResult = null;
try {
voidResult = dispatcher.runSync("voidRedeemGiftCard", redeemCtx);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
if (ServiceUtil.isError(voidResult)) {
return voidResult;
}
processResult = Boolean.FALSE;
amount = redeemed;
result.put("authMessage", "Gift card did not contain enough funds");
}
}
result.put("processAmount", amount);
result.put("authFlag", redeemResult.get("responseCode"));
result.put("authResult", processResult);
result.put("captureResult", processResult);
result.put("authCode", redeemResult.get("authCode"));
result.put("captureCode", redeemResult.get("authCode"));
result.put("authRefNum", redeemResult.get("referenceNum"));
result.put("captureRefNum", redeemResult.get("referenceNum"));
}
return result;
}
use of org.apache.ofbiz.service.GenericServiceException in project ofbiz-framework by apache.
the class WorldPayEvents method setPaymentPreference.
private static boolean setPaymentPreference(LocalDispatcher dispatcher, GenericValue userLogin, GenericValue paymentPreference, HttpServletRequest request) {
Locale locale = UtilHttp.getLocale(request);
String paymentStatus = request.getParameter("transStatus");
String paymentAmount = request.getParameter("authAmount");
Long paymentDate = Long.valueOf(request.getParameter("transTime"));
String transactionId = request.getParameter("transId");
String gatewayFlag = request.getParameter("rawAuthCode");
String avs = request.getParameter("AVS");
List<GenericValue> toStore = new LinkedList<>();
java.sql.Timestamp authDate = null;
try {
authDate = new java.sql.Timestamp(paymentDate.longValue());
} catch (Exception e) {
Debug.logError(e, "Cannot create date from long: " + paymentDate, module);
authDate = UtilDateTime.nowTimestamp();
}
paymentPreference.set("maxAmount", new BigDecimal(paymentAmount));
if ("Y".equals(paymentStatus)) {
paymentPreference.set("statusId", "PAYMENT_RECEIVED");
} else if ("C".equals(paymentStatus)) {
paymentPreference.set("statusId", "PAYMENT_CANCELLED");
} else {
paymentPreference.set("statusId", "PAYMENT_NOT_RECEIVED");
}
toStore.add(paymentPreference);
Delegator delegator = paymentPreference.getDelegator();
// create the PaymentGatewayResponse
String responseId = delegator.getNextSeqId("PaymentGatewayResponse");
GenericValue response = delegator.makeValue("PaymentGatewayResponse");
response.set("paymentGatewayResponseId", responseId);
response.set("paymentServiceTypeEnumId", "PRDS_PAY_EXTERNAL");
response.set("orderPaymentPreferenceId", paymentPreference.get("orderPaymentPreferenceId"));
response.set("paymentMethodTypeId", paymentPreference.get("paymentMethodTypeId"));
response.set("paymentMethodId", paymentPreference.get("paymentMethodId"));
// set the auth info
response.set("amount", new BigDecimal(paymentAmount));
response.set("referenceNum", transactionId);
response.set("gatewayCode", paymentStatus);
response.set("gatewayFlag", gatewayFlag);
response.set("transactionDate", authDate);
response.set("gatewayAvsResult", avs);
response.set("gatewayCvResult", avs.substring(0, 1));
toStore.add(response);
try {
delegator.storeAll(toStore);
} catch (GenericEntityException e) {
Debug.logError(e, "Cannot set payment preference/payment info", module);
return false;
}
// create a payment record too
Map<String, Object> results = null;
try {
String comment = UtilProperties.getMessage(resource, "AccountingPaymentReceiveViaWorldPay", locale);
results = dispatcher.runSync("createPaymentFromPreference", UtilMisc.toMap("userLogin", userLogin, "orderPaymentPreferenceId", paymentPreference.get("orderPaymentPreferenceId"), "comments", comment));
} catch (GenericServiceException e) {
Debug.logError(e, "Failed to execute service createPaymentFromPreference", module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "worldPayEvents.failedToExecuteServiceCreatePaymentFromPreference", locale));
return false;
}
if (ServiceUtil.isError(results)) {
Debug.logError((String) results.get(ModelService.ERROR_MESSAGE), module);
request.setAttribute("_ERROR_MESSAGE_", (String) results.get(ModelService.ERROR_MESSAGE));
return false;
}
return true;
}
Aggregations