📄 checkouthelper.java
字号:
// make sure we have enough to cover; if this is selected we don't have other payment methods if (cart.getGrandTotal() > accountCredit) { errMsg = UtilProperties.getMessage(resource,"checkhelper.insufficient_credit_available_on_account", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } } Set paymentMethods = selectedPaymentMethods.keySet(); Iterator i = paymentMethods.iterator(); while (i.hasNext()) { String checkOutPaymentId = (String) i.next(); // get the selected amount to use Double paymentAmount = null; if (selectedPaymentMethods.get(checkOutPaymentId) != null) { paymentAmount = (Double) selectedPaymentMethods.get(checkOutPaymentId); } boolean singleUse = singleUsePayments.contains(checkOutPaymentId); cart.addPaymentAmount(checkOutPaymentId, paymentAmount, singleUse); } } else if (cart.getGrandTotal() != 0.00) { // only return an error if the order total is not 0.00 errMsg = UtilProperties.getMessage(resource,"checkhelper.select_method_of_payment", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } return errorMessages; } public Map setCheckOutDates(Timestamp shipBefore, Timestamp shipAfter) { List errorMessages = new ArrayList(); Map result = null; String errMsg = null; if (this.cart != null && this.cart.size() > 0) { this.cart.setShipBeforeDate(shipBefore); this.cart.setShipAfterDate(shipAfter); } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.no_items_in_cart", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } if (errorMessages.size() == 1) { result = ServiceUtil.returnError(errorMessages.get(0).toString()); } else if (errorMessages.size() > 0) { result = ServiceUtil.returnError(errorMessages); } else { result = ServiceUtil.returnSuccess(); } return result; } public Map setCheckOutOptions(String shippingMethod, String shippingContactMechId, Map selectedPaymentMethods, List singleUsePayments, String billingAccountId, Double billingAccountAmt, String correspondingPoId, String shippingInstructions, String orderAdditionalEmails, String maySplit, String giftMessage, String isGift, String internalCode, String shipBeforeDate, String shipAfterDate) { List errorMessages = new ArrayList(); Map result = null; String errMsg = null; if (this.cart != null && this.cart.size() > 0) { // set the general shipping options and method errorMessages.addAll(setCheckOutShippingOptionsInternal(shippingMethod, correspondingPoId, shippingInstructions, orderAdditionalEmails, maySplit, giftMessage, isGift, internalCode, shipBeforeDate, shipAfterDate)); // set the shipping address errorMessages.addAll(setCheckOutShippingAddressInternal(shippingContactMechId)); // set the payment method(s) option errorMessages.addAll(setCheckOutPaymentInternal(selectedPaymentMethods, singleUsePayments, billingAccountId, billingAccountAmt)); } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.no_items_in_cart", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } if (errorMessages.size() == 1) { result = ServiceUtil.returnError(errorMessages.get(0).toString()); } else if (errorMessages.size() > 0) { result = ServiceUtil.returnError(errorMessages); } else { result = ServiceUtil.returnSuccess(); } return result; } public Map checkGiftCard(Map params, Map selectedPaymentMethods) { List errorMessages = new ArrayList(); Map errorMaps = new HashMap(); Map result = new HashMap(); String errMsg = null; // handle gift card payment if (params.get("addGiftCard") != null) { String gcNum = (String) params.get("giftCardNumber"); String gcPin = (String) params.get("giftCardPin"); String gcAmt = (String) params.get("giftCardAmount"); double gcAmount = -1; boolean gcFieldsOkay = true; if (gcNum == null || gcNum.length() == 0) { errMsg = UtilProperties.getMessage(resource,"checkhelper.enter_gift_card_number", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); gcFieldsOkay = false; } if (cart.isPinRequiredForGC(delegator)) { // if a PIN is required, make sure the PIN is valid if ((gcPin == null) || (gcPin.length() == 0)) { errMsg = UtilProperties.getMessage(resource,"checkhelper.enter_gift_card_pin_number", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); gcFieldsOkay = false; } } // See if we should validate gift card code against FinAccount's accountCode if (cart.isValidateGCFinAccount(delegator)) { try { // No PIN required - validate gift card number against account code if (!cart.isPinRequiredForGC(delegator)) { GenericValue finAccount = FinAccountHelper.getFinAccountFromCode(gcNum, delegator); if (finAccount == null) { errMsg = UtilProperties.getMessage(resource,"checkhelper.gift_card_does_not_exist", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); gcFieldsOkay = false; } else if ((FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"), cart.getCurrency(), delegator) == null) || !(FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"), cart.getCurrency(), delegator).compareTo(FinAccountHelper.ZERO) == 1)) { // if account's available balance (including authorizations) is not greater than zero, then return an error errMsg = UtilProperties.getMessage(resource,"checkhelper.gift_card_has_no_value", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); gcFieldsOkay = false; } } // TODO: else case when pin is required - we should validate gcNum and gcPin } catch (GenericEntityException ex) { errorMessages.add(ex.getMessage()); gcFieldsOkay = false; } } if (selectedPaymentMethods != null && selectedPaymentMethods.size() > 0) { if (gcAmt == null || gcAmt.length() == 0) { errMsg = UtilProperties.getMessage(resource,"checkhelper.enter_amount_to_place_on_gift_card", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); gcFieldsOkay = false; } } if (gcAmt != null && gcAmt.length() > 0) { try { gcAmount = Double.parseDouble(gcAmt); } catch (NumberFormatException e) { Debug.logError(e, module); errMsg = UtilProperties.getMessage(resource,"checkhelper.invalid_amount_for_gift_card", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); gcFieldsOkay = false; } } if (gcFieldsOkay) { // store the gift card Map gcCtx = new HashMap(); gcCtx.put("partyId", params.get("partyId")); gcCtx.put("cardNumber", gcNum); if (cart.isPinRequiredForGC(delegator)) { gcCtx.put("pinNumber", gcPin); } gcCtx.put("userLogin", cart.getUserLogin()); Map gcResult = null; try { gcResult = dispatcher.runSync("createGiftCard", gcCtx); } catch (GenericServiceException e) { Debug.logError(e, module); errorMessages.add(e.getMessage()); } if (gcResult != null) { this.addErrors(errorMessages, errorMaps, gcResult); if (errorMessages.size() == 0 && errorMaps.size() == 0) { // set the GC payment method Double giftCardAmount = null; if (gcAmount > 0) { giftCardAmount = new Double(gcAmount); } String gcPaymentMethodId = (String) gcResult.get("paymentMethodId"); result = ServiceUtil.returnSuccess(); result.put("paymentMethodId", gcPaymentMethodId); result.put("amount", giftCardAmount); } } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.problem_with_gift_card_information", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } } } else { result = ServiceUtil.returnSuccess(); } // see whether we need to return an error or not if (errorMessages.size() > 0) { result.put(ModelService.ERROR_MESSAGE_LIST, errorMessages); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); } if (errorMaps.size() > 0) { result.put(ModelService.ERROR_MESSAGE_MAP, errorMaps); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); } return result; } public Map createOrder(GenericValue userLogin) { return createOrder(userLogin, null, null, null, false, null, null); } // Create order event - uses createOrder service for processing public Map createOrder(GenericValue userLogin, String distributorId, String affiliateId, List trackingCodeOrders, boolean areOrderItemsExploded, String visitId, String webSiteId) { if (this.cart == null) { return null; } String orderId = this.cart.getOrderId(); this.cart.clearAllItemStatus(); // format the grandTotal String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00"); DecimalFormat formatter = new DecimalFormat(currencyFormat); double cartTotal = this.cart.getGrandTotal(); String grandTotalString = formatter.format(cartTotal); Double grandTotal = null; try { grandTotal = new Double(formatter.parse(grandTotalString).doubleValue()); } catch (ParseException e) { Debug.logError(e, "Problem getting parsed currency amount from DecimalFormat", module); String errMsg = UtilProperties.getMessage(resource,"checkhelper.could_not_create_order_parsing_totals", (cart != null ? cart.getLocale() : Locale.getDefault())); return ServiceUtil.returnError(errMsg); } // store the order - build the context Map context = this.cart.makeCartMap(this.dispatcher, areOrderItemsExploded); //get the TrackingCodeOrder List context.put("trackingCodeOrders", trackingCodeOrders); if (distributorId != null) context.put("distributorId", distributorId); if (affiliateId != null) context.put("affiliateId", affiliateId); // need the partyId; don't use userLogin in case of an order via order mgr String partyId = this.cart.getPartyId(); String facilityId = this.cart.getFacilityId(); String terminalId = this.cart.getTerminalId(); String transactionId = cart.getTransactionId(); String productStoreId = cart.getProductStoreId(); context.put("grandTotal", grandTotal); context.put("userLogin", userLogin); context.put("partyId", partyId); context.put("productStoreId", productStoreId); context.put("transactionId", transactionId); context.put("originFacilityId", facilityId); context.put("visitId", visitId); context.put("terminalId", terminalId); context.put("webSiteId", webSiteId); // store the order - invoke the service Map storeResult = null; try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -