use of org.apache.ofbiz.order.order.OrderReadHelper in project ofbiz-framework by apache.
the class PayflowPro method doExpressCheckout.
public static Map<String, Object> doExpressCheckout(DispatchContext dctx, Map<String, Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference");
OrderReadHelper orh = new OrderReadHelper(delegator, paymentPref.getString("orderId"));
GenericValue payPalPaymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, orh.getProductStoreId(), "EXT_PAYPAL", null, true);
String paymentGatewayConfigId = payPalPaymentSetting.getString("paymentGatewayConfigId");
String configString = "payment.properties";
GenericValue payPalPaymentMethod = null;
try {
payPalPaymentMethod = paymentPref.getRelatedOne("PaymentMethod", false);
payPalPaymentMethod = payPalPaymentMethod.getRelatedOne("PayPalPaymentMethod", false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
BigDecimal processAmount = paymentPref.getBigDecimal("maxAmount");
Map<String, String> data = new HashMap<String, String>();
data.put("TRXTYPE", "O");
data.put("TENDER", "P");
data.put("PAYERID", payPalPaymentMethod.getString("payerId"));
data.put("TOKEN", payPalPaymentMethod.getString("expressCheckoutToken"));
data.put("ACTION", "D");
// set the amount
data.put("AMT", processAmount.setScale(2).toPlainString());
PayflowAPI pfp = init(delegator, paymentGatewayConfigId, null, context);
// get the base params
StringBuilder params = makeBaseParams(delegator, paymentGatewayConfigId, null);
// parse the context parameters
params.append("&").append(parseContext(data));
// transmit the request
if (Debug.verboseOn())
Debug.logVerbose("Sending to Verisign: " + params.toString(), module);
String resp;
if (!comparePaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "enableTransmit", configString, "payment.verisign.enable_transmit", "false")) {
resp = pfp.submitTransaction(params.toString(), pfp.generateRequestId());
} else {
resp = "RESULT=0&PAYERID=" + (new Date()).getTime() + "&RESPMSG=Testing";
}
Map<String, String> responseMap = parseResponse(resp);
Map<String, Object> inMap = new HashMap<String, Object>();
inMap.put("userLogin", userLogin);
inMap.put("paymentMethodId", payPalPaymentMethod.get("paymentMethodId"));
inMap.put("transactionId", responseMap.get("PNREF"));
Map<String, Object> outMap = null;
try {
outMap = dispatcher.runSync("updatePayPalPaymentMethod", inMap);
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
if (ServiceUtil.isError(outMap)) {
Debug.logError(ServiceUtil.getErrorMessage(outMap), module);
return outMap;
}
return ServiceUtil.returnSuccess();
}
use of org.apache.ofbiz.order.order.OrderReadHelper in project ofbiz-framework by apache.
the class ValueLinkServices method giftCardReload.
public static Map<String, Object> giftCardReload(DispatchContext dctx, Map<String, Object> context) {
// this service should always be called via FULFILLMENT_EXTSYNC
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
GenericValue orderItem = (GenericValue) context.get("orderItem");
Locale locale = (Locale) context.get("locale");
// order ID for tracking
String orderId = orderItem.getString("orderId");
// the order header for store info
GenericValue orderHeader = null;
try {
orderHeader = orderItem.getRelatedOne("OrderHeader", false);
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get OrderHeader from OrderItem", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceOrder, "OrderOrderNotFound", UtilMisc.toMap("orderId", orderId), locale));
}
// get the order read helper
OrderReadHelper orh = new OrderReadHelper(orderHeader);
// get the currency
String currency = orh.getCurrency();
// make sure we have a currency
if (currency == null) {
currency = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
// get the product store
String productStoreId = null;
if (orderHeader != null) {
productStoreId = orh.getProductStoreId();
}
if (productStoreId == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotProcess", UtilMisc.toMap("orderId", orderId), locale));
}
// payment config
GenericValue paymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStoreId, "GIFT_CARD", null, true);
String paymentConfig = null;
if (paymentSetting != null) {
paymentConfig = paymentSetting.getString("paymentPropertiesPath");
}
if (paymentConfig == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotGetPaymentConfiguration", locale));
}
// party ID for tracking
GenericValue placingParty = orh.getPlacingParty();
String partyId = null;
if (placingParty != null) {
partyId = placingParty.getString("partyId");
}
// amount of the gift card reload
BigDecimal amount = orderItem.getBigDecimal("unitPrice");
// survey information
String surveyId = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.surveyId", delegator);
// get the survey response
GenericValue surveyResponse = null;
try {
surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("orderId", orderId, "orderItemSeqId", orderItem.get("orderItemSeqId"), "surveyId", surveyId).orderBy("-responseDate").queryFirst();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfill", locale));
}
// get the response answers
List<GenericValue> responseAnswers = null;
try {
responseAnswers = surveyResponse.getRelated("SurveyResponseAnswer", null, null, false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfillFromSurveyAnswers", locale));
}
// make a map of answer info
Map<String, Object> answerMap = new HashMap<String, Object>();
if (responseAnswers != null) {
for (GenericValue answer : responseAnswers) {
GenericValue question = null;
try {
question = answer.getRelatedOne("SurveyQuestion", false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfillFromSurveyAnswers", locale));
}
if (question != null) {
String desc = question.getString("description");
// only support text response types for now
String ans = answer.getString("textResponse");
answerMap.put(desc, ans);
}
}
}
String cardNumberKey = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.survey.cardNumber", delegator);
String pinNumberKey = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.survey.pinNumber", delegator);
String cardNumber = (String) answerMap.get(cardNumberKey);
String pinNumber = (String) answerMap.get(pinNumberKey);
// reload the gift card
Map<String, Object> reloadCtx = new HashMap<String, Object>();
reloadCtx.put("paymentConfig", paymentConfig);
reloadCtx.put("currency", currency);
reloadCtx.put("partyId", partyId);
reloadCtx.put("orderId", orderId);
reloadCtx.put("cardNumber", cardNumber);
reloadCtx.put("pin", pinNumber);
reloadCtx.put("amount", amount);
reloadCtx.put("userLogin", userLogin);
Map<String, Object> reloadResult = null;
try {
reloadResult = dispatcher.runSync("reloadGiftCard", reloadCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Unable to reload gift card", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToReloadGiftCard", locale));
}
// create the fulfillment record
Map<String, Object> vlFulFill = new HashMap<String, Object>();
vlFulFill.put("typeEnumId", "GC_RELOAD");
vlFulFill.put("merchantId", EntityUtilProperties.getPropertyValue(paymentConfig, "payment.valuelink.merchantId", delegator));
vlFulFill.put("partyId", partyId);
vlFulFill.put("orderId", orderId);
vlFulFill.put("orderItemSeqId", orderItem.get("orderItemSeqId"));
vlFulFill.put("surveyResponseId", surveyResponse.get("surveyResponseId"));
vlFulFill.put("cardNumber", cardNumber);
vlFulFill.put("pinNumber", pinNumber);
vlFulFill.put("amount", amount);
vlFulFill.put("responseCode", reloadResult.get("responseCode"));
vlFulFill.put("referenceNum", reloadResult.get("referenceNum"));
vlFulFill.put("authCode", reloadResult.get("authCode"));
vlFulFill.put("userLogin", userLogin);
try {
dispatcher.runAsync("createGcFulFillmentRecord", vlFulFill, true);
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotStoreFulfillmentInfo", locale));
}
Boolean processResult = (Boolean) reloadResult.get("processResult");
if (reloadResult.containsKey(ModelService.ERROR_MESSAGE) || !processResult.booleanValue()) {
Debug.logError("Reload Failed Need to Refund : " + reloadResult, module);
// process the return
try {
Map<String, Object> refundCtx = UtilMisc.<String, Object>toMap("orderItem", orderItem, "partyId", partyId, "userLogin", userLogin);
dispatcher.runAsync("refundGcPurchase", refundCtx, null, true, 300, true);
} catch (GenericServiceException e) {
Debug.logError(e, "ERROR! Unable to call create refund service; this failed reload will NOT be refunded", module);
}
String responseCode = "-1";
if (processResult != null) {
responseCode = (String) reloadResult.get("responseCode");
}
if ("17".equals(responseCode)) {
Debug.logError("Error code : " + responseCode + " : Max Balance Exceeded", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToRefundGiftCardMaxBalanceExceeded", locale));
} else {
Debug.logError("Error code : " + responseCode + " : Processing Error", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToReloadGiftCardFailed", locale));
}
}
// add some information to the answerMap for the email
answerMap.put("processResult", reloadResult.get("processResult"));
answerMap.put("responseCode", reloadResult.get("responseCode"));
answerMap.put("previousAmount", reloadResult.get("previousAmount"));
answerMap.put("amount", reloadResult.get("amount"));
// get the email setting for this email type
GenericValue productStoreEmail = null;
String emailType = "PRDS_GC_RELOAD";
try {
productStoreEmail = EntityQuery.use(delegator).from("ProductStoreEmailSetting").where("productStoreId", productStoreId, "emailType", emailType).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get product store email setting for gift card purchase", module);
}
if (productStoreEmail == null) {
Debug.logError("No gift card purchase email setting found for this store; cannot send gift card information", module);
} else {
Map<String, Object> emailCtx = new HashMap<String, Object>();
answerMap.put("locale", locale);
String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");
if (UtilValidate.isEmpty(bodyScreenLocation)) {
bodyScreenLocation = ProductStoreWorker.getDefaultProductStoreEmailScreenLocation(emailType);
}
emailCtx.put("bodyScreenUri", bodyScreenLocation);
emailCtx.put("bodyParameters", answerMap);
emailCtx.put("sendTo", orh.getOrderEmailString());
emailCtx.put("contentType", productStoreEmail.get("contentType"));
emailCtx.put("sendFrom", productStoreEmail.get("fromAddress"));
emailCtx.put("sendCc", productStoreEmail.get("ccAddress"));
emailCtx.put("sendBcc", productStoreEmail.get("bccAddress"));
emailCtx.put("subject", productStoreEmail.getString("subject"));
emailCtx.put("userLogin", userLogin);
// send off the email async so we will retry on failed attempts
try {
dispatcher.runAsync("sendMailFromScreen", emailCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Problem sending mail", module);
// this is fatal; we will rollback and try again later
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingGiftCerticateNumberCannotSendEmailNotice", UtilMisc.toMap("errorString", e.toString()), locale));
}
}
return ServiceUtil.returnSuccess();
}
use of org.apache.ofbiz.order.order.OrderReadHelper in project ofbiz-framework by apache.
the class ValueLinkServices method giftCardPurchase.
// item fulfillment wrappers (purchase/reload)
public static Map<String, Object> giftCardPurchase(DispatchContext dctx, Map<String, Object> context) {
// this service should always be called via FULFILLMENT_EXTASYNC
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
GenericValue orderItem = (GenericValue) context.get("orderItem");
Locale locale = (Locale) context.get("locale");
// order ID for tracking
String orderId = orderItem.getString("orderId");
// the order header for store info
GenericValue orderHeader = null;
try {
orderHeader = orderItem.getRelatedOne("OrderHeader", false);
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get OrderHeader from OrderItem", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceOrder, "OrderOrderNotFound", UtilMisc.toMap("orderId", orderId), locale));
}
// get the order read helper
OrderReadHelper orh = new OrderReadHelper(orderHeader);
// get the currency
String currency = orh.getCurrency();
// make sure we have a currency
if (currency == null) {
currency = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
// get the product store
String productStoreId = null;
if (orderHeader != null) {
productStoreId = orh.getProductStoreId();
}
if (productStoreId == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotProcess", locale));
}
// payment config
GenericValue paymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStoreId, "GIFT_CARD", null, true);
String paymentConfig = null;
if (paymentSetting != null) {
paymentConfig = paymentSetting.getString("paymentPropertiesPath");
}
if (paymentConfig == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingFinAccountSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", "GIFT_CARD"), locale));
}
// party ID for tracking
GenericValue placingParty = orh.getPlacingParty();
String partyId = null;
if (placingParty != null) {
partyId = placingParty.getString("partyId");
}
// amount/quantity of the gift card(s)
BigDecimal amount = orderItem.getBigDecimal("unitPrice");
BigDecimal quantity = orderItem.getBigDecimal("quantity");
// the product entity needed for information
GenericValue product = null;
try {
product = orderItem.getRelatedOne("Product", false);
} catch (GenericEntityException e) {
Debug.logError("Unable to get Product from OrderItem", module);
}
if (product == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfill", locale));
}
// get the productFeature type TYPE (VL promo code)
GenericValue typeFeature = null;
try {
typeFeature = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", product.get("productId"), "productFeatureTypeId", "TYPE").orderBy("-fromDate").filterByDate().queryFirst();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToGetFeatureType", locale));
}
if (typeFeature == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkFeatureTypeRequested", UtilMisc.toMap("productId", product.get("productId")), locale));
}
// get the VL promo code
String promoCode = typeFeature.getString("idCode");
if (UtilValidate.isEmpty(promoCode)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkPromoCodeInvalid", locale));
}
// survey information
String surveyId = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.purchase.surveyId", delegator);
// get the survey response
GenericValue surveyResponse = null;
try {
surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("orderId", orderId, "orderItemSeqId", orderItem.get("orderItemSeqId"), "surveyId", surveyId).queryFirst();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfill", locale));
}
// get the response answers
List<GenericValue> responseAnswers = null;
try {
responseAnswers = surveyResponse.getRelated("SurveyResponseAnswer", null, null, false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfillFromSurveyAnswers", locale));
}
// make a map of answer info
Map<String, Object> answerMap = new HashMap<String, Object>();
if (responseAnswers != null) {
for (GenericValue answer : responseAnswers) {
GenericValue question = null;
try {
question = answer.getRelatedOne("SurveyQuestion", false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotFulfillFromSurveyAnswers", locale));
}
if (question != null) {
String desc = question.getString("description");
// only support text response types for now
String ans = answer.getString("textResponse");
answerMap.put(desc, ans);
}
}
}
// get the send to email address - key defined in properties file
String sendToKey = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.purchase.survey.sendToEmail", delegator);
String sendToEmail = (String) answerMap.get(sendToKey);
// get the copyMe flag and set the order email address
String orderEmails = orh.getOrderEmailString();
String copyMeField = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.purchase.survey.copyMe", delegator);
String copyMeResp = copyMeField != null ? (String) answerMap.get(copyMeField) : null;
boolean copyMe = (UtilValidate.isNotEmpty(copyMeField) && UtilValidate.isNotEmpty(copyMeResp) && "true".equalsIgnoreCase(copyMeResp)) ? true : false;
int qtyLoop = quantity.intValue();
for (int i = 0; i < qtyLoop; i++) {
// activate a gift card
Map<String, Object> activateCtx = new HashMap<String, Object>();
activateCtx.put("paymentConfig", paymentConfig);
activateCtx.put("vlPromoCode", promoCode);
activateCtx.put("currency", currency);
activateCtx.put("partyId", partyId);
activateCtx.put("orderId", orderId);
activateCtx.put("amount", amount);
activateCtx.put("userLogin", userLogin);
boolean failure = false;
Map<String, Object> activateResult = null;
try {
activateResult = dispatcher.runSync("activateGiftCard", activateCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Unable to activate gift card(s)", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToActivateGiftCard", locale));
}
Boolean processResult = (Boolean) activateResult.get("processResult");
if (activateResult.containsKey(ModelService.ERROR_MESSAGE) || !processResult.booleanValue()) {
failure = true;
}
if (!failure) {
// set the void on rollback
try {
dispatcher.addRollbackService("voidActivateGiftCard", activateCtx, false);
} catch (GenericServiceException e) {
Debug.logError(e, "Unable to setup Activate/Void on error", module);
}
}
// create the fulfillment record
Map<String, Object> vlFulFill = new HashMap<String, Object>();
vlFulFill.put("typeEnumId", "GC_ACTIVATE");
vlFulFill.put("merchantId", EntityUtilProperties.getPropertyValue(paymentConfig, "payment.valuelink.merchantId", delegator));
vlFulFill.put("partyId", partyId);
vlFulFill.put("orderId", orderId);
vlFulFill.put("orderItemSeqId", orderItem.get("orderItemSeqId"));
vlFulFill.put("surveyResponseId", surveyResponse.get("surveyResponseId"));
vlFulFill.put("cardNumber", activateResult.get("cardNumber"));
vlFulFill.put("pinNumber", activateResult.get("pin"));
vlFulFill.put("amount", activateResult.get("amount"));
vlFulFill.put("responseCode", activateResult.get("responseCode"));
vlFulFill.put("referenceNum", activateResult.get("referenceNum"));
vlFulFill.put("authCode", activateResult.get("authCode"));
vlFulFill.put("userLogin", userLogin);
try {
dispatcher.runAsync("createGcFulFillmentRecord", vlFulFill, true);
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotStoreFulfillmentInfo", UtilMisc.toMap("errorString", e.toString()), locale));
}
if (failure) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToActivateGiftCard", locale));
}
// add some information to the answerMap for the email
answerMap.put("cardNumber", activateResult.get("cardNumber"));
answerMap.put("pinNumber", activateResult.get("pin"));
answerMap.put("amount", activateResult.get("amount"));
// get the email setting for this email type
GenericValue productStoreEmail = null;
String emailType = "PRDS_GC_PURCHASE";
try {
productStoreEmail = EntityQuery.use(delegator).from("ProductStoreEmailSetting").where("productStoreId", productStoreId, "emailType", emailType).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get product store email setting for gift card purchase", module);
}
if (productStoreEmail == null) {
Debug.logError("No gift card purchase email setting found for this store; cannot send gift card information", module);
} else {
answerMap.put("locale", locale);
// set the bcc address(s)
String bcc = productStoreEmail.getString("bccAddress");
if (copyMe) {
if (UtilValidate.isNotEmpty(bcc)) {
bcc = bcc + "," + orderEmails;
} else {
bcc = orderEmails;
}
}
Map<String, Object> emailCtx = new HashMap<String, Object>();
String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");
if (UtilValidate.isEmpty(bodyScreenLocation)) {
bodyScreenLocation = ProductStoreWorker.getDefaultProductStoreEmailScreenLocation(emailType);
}
emailCtx.put("bodyScreenUri", bodyScreenLocation);
emailCtx.put("bodyParameters", answerMap);
emailCtx.put("sendTo", sendToEmail);
emailCtx.put("contentType", productStoreEmail.get("contentType"));
emailCtx.put("sendFrom", productStoreEmail.get("fromAddress"));
emailCtx.put("sendCc", productStoreEmail.get("ccAddress"));
emailCtx.put("sendBcc", bcc);
emailCtx.put("subject", productStoreEmail.getString("subject"));
emailCtx.put("userLogin", userLogin);
// send off the email async so we will retry on failed attempts
try {
dispatcher.runAsync("sendMailFromScreen", emailCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "Problem sending mail", module);
// this is fatal; we will rollback and try again later
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingGiftCerticateNumberCannotSendEmailNotice", UtilMisc.toMap("errorString", e.toString()), locale));
}
}
}
return ServiceUtil.returnSuccess();
}
use of org.apache.ofbiz.order.order.OrderReadHelper in project ofbiz-framework by apache.
the class FinAccountPaymentServices method finAccountRefund.
public static Map<String, Object> finAccountRefund(DispatchContext dctx, Map<String, Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale) context.get("locale");
GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
GenericValue userLogin = (GenericValue) context.get("userLogin");
BigDecimal amount = (BigDecimal) context.get("refundAmount");
String currency = (String) context.get("currency");
String finAccountId = (String) context.get("finAccountId");
String productStoreId = null;
String partyId = null;
String orderId = null;
if (orderPaymentPreference != null) {
orderId = orderPaymentPreference.getString("orderId");
if (orderId != null) {
OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
productStoreId = orh.getProductStoreId();
GenericValue billToParty = orh.getBillToParty();
if (billToParty != null) {
partyId = billToParty.getString("partyId");
}
}
if (finAccountId == null) {
finAccountId = orderPaymentPreference.getString("finAccountId");
}
}
if (finAccountId == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", ""), locale));
}
// call the deposit service
Map<String, Object> depositCtx = new HashMap<>();
depositCtx.put("finAccountId", finAccountId);
depositCtx.put("productStoreId", productStoreId);
depositCtx.put("isRefund", Boolean.TRUE);
depositCtx.put("currency", currency);
depositCtx.put("partyId", partyId);
depositCtx.put("orderId", orderId);
depositCtx.put("amount", amount);
depositCtx.put("reasonEnumId", "FATR_REFUND");
depositCtx.put("userLogin", userLogin);
Map<String, Object> depositResp;
try {
depositResp = dispatcher.runSync("finAccountDeposit", depositCtx);
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
if (ServiceUtil.isError(depositResp)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(depositResp));
}
// create the refund response
Map<String, Object> result = ServiceUtil.returnSuccess();
Boolean processResult = (Boolean) depositResp.get("processResult");
BigDecimal depositAmount = (BigDecimal) depositResp.get("amount");
String referenceNum = (String) depositResp.get("referenceNum");
result.put("refundResult", processResult);
result.put("refundRefNum", referenceNum);
result.put("refundCode", "R");
result.put("refundFlag", "1");
result.put("refundAmount", depositAmount);
return result;
}
use of org.apache.ofbiz.order.order.OrderReadHelper in project ofbiz-framework by apache.
the class FinAccountPaymentServices method getLastProductStoreId.
private static String getLastProductStoreId(Delegator delegator, String finAccountId) {
GenericValue trans = null;
try {
trans = EntityQuery.use(delegator).from("FinAccountTrans").where(EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "DEPOSIT"), EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), EntityCondition.makeCondition("orderId", EntityOperator.NOT_EQUAL, null)).orderBy("-transactionDate").queryFirst();
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
if (trans != null) {
String orderId = trans.getString("orderId");
OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
return orh.getProductStoreId();
}
// none found; pick one from our set stores
try {
GenericValue store = EntityQuery.use(delegator).from("ProductStore").orderBy("productStoreId").queryFirst();
if (store != null) {
return store.getString("productStoreId");
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
return null;
}
Aggregations