📄 giftcertificateservices.java
字号:
gcFulFill.set("partyId", context.get("partyId")); gcFulFill.set("orderId", context.get("orderId")); gcFulFill.set("orderItemSeqId", context.get("orderItemSeqId")); gcFulFill.set("surveyResponseId", context.get("surveyResponseId")); gcFulFill.set("cardNumber", context.get("cardNumber")); gcFulFill.set("pinNumber", context.get("pinNumber")); gcFulFill.set("amount", context.get("amount")); gcFulFill.set("responseCode", context.get("responseCode")); gcFulFill.set("referenceNum", context.get("referenceNum")); gcFulFill.set("authCode", context.get("authCode")); gcFulFill.set("fulfillmentDate", UtilDateTime.nowTimestamp()); try { delegator.create(gcFulFill); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to store fulfillment info"); } return ServiceUtil.returnSuccess(); } // Refund Service public static Map refundGcPurchase(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); GenericValue orderItem = (GenericValue) context.get("orderItem"); String partyId = (String) context.get("partyId"); // refresh the item object for status changes try { orderItem.refresh(); } catch (GenericEntityException e) { Debug.logError(e, module); } Map returnableInfo = null; try { returnableInfo = dispatcher.runSync("getReturnableQuantity", UtilMisc.toMap("orderItem", orderItem, "userLogin", userLogin)); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to get returnable infomation for order item : " + orderItem); } if (returnableInfo != null) { Double returnableQuantity = (Double) returnableInfo.get("returnableQuantity"); Double returnablePrice = (Double) returnableInfo.get("returnablePrice"); Debug.logInfo("Returnable INFO : " + returnableQuantity + " @ " + returnablePrice + " :: " + orderItem, module); // create the return header Map returnHeaderInfo = new HashMap(); returnHeaderInfo.put("fromPartyId", partyId); returnHeaderInfo.put("userLogin", userLogin); Map returnHeaderResp = null; try { returnHeaderResp = dispatcher.runSync("createReturnHeader", returnHeaderInfo); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to create return header"); } if (returnHeaderResp != null) { String errorMessage = ServiceUtil.getErrorMessage(returnHeaderResp); if (errorMessage != null) { return ServiceUtil.returnError(errorMessage); } } String returnId = null; if (returnHeaderResp != null) { returnId = (String) returnHeaderResp.get("returnId"); } if (returnId == null) { return ServiceUtil.returnError("Create return did not return a valid return id"); } // create the return item Map returnItemInfo = new HashMap(); returnItemInfo.put("returnId", returnId); returnItemInfo.put("returnReasonId", "RTN_DIG_FILL_FAIL"); returnItemInfo.put("returnTypeId", "RTN_REFUND"); returnItemInfo.put("returnItemType", "ITEM"); returnItemInfo.put("description", orderItem.get("itemDescription")); returnItemInfo.put("orderId", orderItem.get("orderId")); returnItemInfo.put("orderItemSeqId", orderItem.get("orderItemSeqId")); returnItemInfo.put("returnQuantity", returnableQuantity); returnItemInfo.put("returnPrice", returnablePrice); returnItemInfo.put("userLogin", userLogin); Map returnItemResp = null; try { returnItemResp = dispatcher.runSync("createReturnItem", returnItemInfo); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to create return item"); } if (returnItemResp != null) { String errorMessage = ServiceUtil.getErrorMessage(returnItemResp); if (errorMessage != null) { return ServiceUtil.returnError(errorMessage); } } String returnItemSeqId = null; if (returnItemResp != null) { returnItemSeqId = (String) returnItemResp.get("returnItemSeqId"); } if (returnItemSeqId == null) { return ServiceUtil.returnError("Create return item did not return a valid sequence id"); } else { Debug.logVerbose("Created return item : " + returnId + " / " + returnItemSeqId, module); } // need the admin userLogin to "fake" out the update service GenericValue admin = null; try { admin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin")); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to look up UserLogin from database"); } // update the status to received so it can process Map updateReturnInfo = new HashMap(); updateReturnInfo.put("returnId", returnId); updateReturnInfo.put("statusId", "RETURN_RECEIVED"); updateReturnInfo.put("currentStatusId", "RETURN_REQUESTED"); updateReturnInfo.put("userLogin", admin); Map updateReturnResp = null; try { updateReturnResp = dispatcher.runSync("updateReturnHeader", updateReturnInfo); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to update return header status"); } if (updateReturnResp != null) { String errorMessage = ServiceUtil.getErrorMessage(updateReturnResp); if (errorMessage != null) { return ServiceUtil.returnError(errorMessage); } } } return ServiceUtil.returnSuccess(); } // Private worker methods private static boolean validatePin(GenericDelegator delegator, String cardNumber, String pinNumber) { GenericValue finAccount = null; try { finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", cardNumber)); } catch (GenericEntityException e) { Debug.logError(e, module); } if (finAccount != null) { String dbPin = finAccount.getString("finAccountCode"); Debug.log("GC Pin Validation: [Sent: " + pinNumber + "] [Actual: " + dbPin + "]", module); if (dbPin != null && dbPin.equals(pinNumber)) { return true; } } else { Debug.logInfo("GC FinAccount record not found (" + cardNumber + ")", module); } return false; } private static String createTransaction(GenericDelegator delegator, LocalDispatcher dispatcher, GenericValue userLogin, Double amount, String productStoreId, String partyId, String currencyUom, String txType, String finAccountId) throws GeneralException { final String coParty = getPayToPartyId(delegator, productStoreId); final String paymentMethodType = "GIFT_CERTIFICATE"; if (UtilValidate.isEmpty(partyId)) { partyId = "_NA_"; } String paymentType = null; String partyIdFrom = null; String partyIdTo = null; if ("DEPOSIT".equals(txType)) { paymentType = "GC_DEPOSIT"; partyIdFrom = partyId; partyIdTo = coParty; } else if ("WITHDRAWAL".equals(txType)) { paymentType = "GC_WITHDRAWAL"; partyIdFrom = coParty; partyIdTo = partyId; } else { throw new GeneralException("Unable to create financial account transaction!"); } // create the payment for the transaction Map paymentCtx = UtilMisc.toMap("paymentTypeId", paymentType); paymentCtx.put("paymentMethodTypeId", paymentMethodType); //paymentCtx.put("paymentMethodId", ""); //paymentCtx.put("paymentGatewayResponseId", ""); paymentCtx.put("partyIdTo", partyIdTo); paymentCtx.put("partyIdFrom", partyIdFrom); paymentCtx.put("statusId", "PMNT_RECEIVED"); //paymentCtx.put("paymentPreferenceId", ""); paymentCtx.put("currencyUomId", currencyUom); paymentCtx.put("amount", amount); paymentCtx.put("userLogin", userLogin); paymentCtx.put("paymentRefNum", "N/A"); String paymentId = null; Map payResult = null; try { payResult = dispatcher.runSync("createPayment", paymentCtx); } catch (GenericServiceException e) { throw new GeneralException(e); } if (payResult == null) { throw new GeneralException("Unknow error in creating financial account transaction!"); } if (ServiceUtil.isError(payResult)) { throw new GeneralException(ServiceUtil.getErrorMessage(payResult)); } else { paymentId = (String) payResult.get("paymentId"); } // create the initial transaction Map transCtx = UtilMisc.toMap("finAccountTransTypeId", txType); transCtx.put("finAccountId", finAccountId); transCtx.put("partyId", userLogin.getString("partyId")); transCtx.put("userLogin", userLogin); transCtx.put("paymentId", paymentId); Map transResult = null; String txId = null; try { transResult = dispatcher.runSync("createFinAccountTrans", transCtx); } catch (GenericServiceException e) { throw new GeneralException(e); } if (transResult == null) { throw new GeneralException("Unknown error in creating financial account transaction!"); } if (ServiceUtil.isError(transResult)) { throw new GeneralException(ServiceUtil.getErrorMessage(transResult)); } else { txId = (String) transResult.get("finAccountTransId"); } return txId; } private static String generateNumber(GenericDelegator delegator, int length, boolean isId) throws GenericEntityException { if (length > 19) { length = 19; } Random rand = new Random(); boolean isValid = false; String number = null; while (!isValid) { number = ""; for (int i = 0; i < length; i++) { int randInt = rand.nextInt(9); number = number + randInt; } if (isId) { int check = UtilValidate.getLuhnCheckDigit(number); number = number + check; // validate the number if (checkCardNumber(number)) { // make sure this number doens't already exist isValid = checkNumberInDatabase(delegator, number); } } el
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -