Exemple #1
0
 @Override
 public Map<String, Object> getParameterMap(
     String sn, String description, HttpServletRequest request) {
   PluginConfig pluginConfig = getPluginConfig();
   Payment payment = getPayment(sn);
   Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
   parameterMap.put("inputCharset", "1");
   parameterMap.put("pageUrl", getNotifyUrl(sn, NotifyMethod.sync));
   parameterMap.put("bgUrl", getNotifyUrl(sn, NotifyMethod.async));
   parameterMap.put("version", "v2.0");
   parameterMap.put("language", "1");
   parameterMap.put("signType", "1");
   parameterMap.put("merchantAcctId", pluginConfig.getAttribute("partner"));
   parameterMap.put("payerIP", request.getLocalAddr());
   parameterMap.put("orderId", sn);
   parameterMap.put(
       "orderAmount", payment.getAmount().multiply(new BigDecimal(100)).setScale(0).toString());
   parameterMap.put("orderTime", new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
   parameterMap.put("orderTimestamp", new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
   parameterMap.put(
       "productName",
       StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 100));
   parameterMap.put(
       "productDesc",
       StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 400));
   parameterMap.put("ext1", "dp2345");
   parameterMap.put("payType", "00");
   parameterMap.put("signMsg", generateSign(parameterMap));
   return parameterMap;
 }
Exemple #2
0
 @Override
 public boolean verifyNotify(String sn, NotifyMethod notifyMethod, HttpServletRequest request) {
   PluginConfig pluginConfig = getPluginConfig();
   Payment payment = getPayment(sn);
   Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
   parameterMap.put("merchantAcctId", request.getParameter("merchantAcctId"));
   parameterMap.put("version", request.getParameter("version"));
   parameterMap.put("language", request.getParameter("language"));
   parameterMap.put("signType", request.getParameter("signType"));
   parameterMap.put("payType", request.getParameter("payType"));
   parameterMap.put("bankId", request.getParameter("bankId"));
   parameterMap.put("orderId", request.getParameter("orderId"));
   parameterMap.put("orderTime", request.getParameter("orderTime"));
   parameterMap.put("orderAmount", request.getParameter("orderAmount"));
   parameterMap.put("bindCard", request.getParameter("bindCard"));
   parameterMap.put("bindMobile", request.getParameter("bindMobile"));
   parameterMap.put("dealId", request.getParameter("dealId"));
   parameterMap.put("bankDealId", request.getParameter("bankDealId"));
   parameterMap.put("dealTime", request.getParameter("dealTime"));
   parameterMap.put("payAmount", request.getParameter("payAmount"));
   parameterMap.put("fee", request.getParameter("fee"));
   parameterMap.put("ext1", request.getParameter("ext1"));
   parameterMap.put("ext2", request.getParameter("ext2"));
   parameterMap.put("payResult", request.getParameter("payResult"));
   parameterMap.put("errCode", request.getParameter("errCode"));
   parameterMap.put("signMsg", request.getParameter("signMsg"));
   if (generateSign(parameterMap).equals(request.getParameter("signMsg"))
       && pluginConfig.getAttribute("partner").equals(request.getParameter("merchantAcctId"))
       && sn.equals(request.getParameter("orderId"))
       && "10".equals(request.getParameter("payResult"))
       && payment
               .getAmount()
               .multiply(new BigDecimal(100))
               .compareTo(new BigDecimal(request.getParameter("payAmount")))
           == 0) {
     return true;
   }
   return false;
 }
Exemple #3
0
  public void payment(Order order, Payment payment, Admin operator) {
    Assert.notNull(order);
    Assert.notNull(payment);

    orderDao.lock(order, LockModeType.PESSIMISTIC_WRITE);

    payment.setOrder(order);
    paymentDao.merge(payment);
    if (payment.getMethod() == Payment.Method.deposit) {
      Member member = order.getMember();
      memberDao.lock(member, LockModeType.PESSIMISTIC_WRITE);
      member.setBalance(member.getBalance().subtract(payment.getAmount()));
      memberDao.merge(member);

      Deposit deposit = new Deposit();
      deposit.setType(operator != null ? Deposit.Type.adminPayment : Deposit.Type.memberPayment);
      deposit.setCredit(new BigDecimal(0));
      deposit.setDebit(payment.getAmount());
      deposit.setBalance(member.getBalance());
      deposit.setOperator(operator != null ? operator.getUsername() : null);
      deposit.setMember(member);
      deposit.setOrder(order);
      depositDao.persist(deposit);
    }

    Setting setting = SettingUtils.get();
    if (!order.getIsAllocatedStock()
        && setting.getStockAllocationTime() == StockAllocationTime.payment) {
      for (OrderItem orderItem : order.getOrderItems()) {
        if (orderItem != null) {
          Product product = orderItem.getProduct();
          productDao.lock(product, LockModeType.PESSIMISTIC_WRITE);
          if (product != null && product.getStock() != null) {
            product.setAllocatedStock(
                product.getAllocatedStock()
                    + (orderItem.getQuantity() - orderItem.getShippedQuantity()));
            productDao.merge(product);
            orderDao.flush();
            staticService.build(product);
          }
        }
      }
      order.setIsAllocatedStock(true);
    }

    order.setAmountPaid(order.getAmountPaid().add(payment.getAmount()));
    order.setFee(payment.getFee());
    order.setExpire(null);
    if (order.getAmountPaid().compareTo(order.getAmount()) >= 0) {
      order.setOrderStatus(OrderStatus.confirmed);
      order.setPaymentStatus(PaymentStatus.paid);
    } else if (order.getAmountPaid().compareTo(new BigDecimal(0)) > 0) {
      order.setOrderStatus(OrderStatus.confirmed);
      order.setPaymentStatus(PaymentStatus.partialPayment);
    }
    orderDao.merge(order);

    OrderLog orderLog = new OrderLog();
    orderLog.setType(Type.payment);
    orderLog.setOperator(operator != null ? operator.getUsername() : null);
    orderLog.setOrder(order);
    orderLogDao.persist(orderLog);
  }