/** * 支付准备 * * @param order 订单信息 * @param payConfig 支付配置 * @param payProduct 支付产品 * @param payer 付款人 * @return Payment * @throws PayException */ public Payment ready(Order order, PayConfig payConfig, PayProduct payProduct, String payer) throws PayException { // 在线支付 if (PayConfig.PayConfigType.online != payConfig.getPayConfigType()) { throw new PayException("暂时只支持在线支付"); } // 支付配置类型(线下支付、在线支付) Payment.PaymentType paymentType = Payment.PaymentType.online; BigDecimal paymentFee = BigDecimal.ZERO; // 支付手续费 BigDecimal amountPayable = order.getPayableFee(); // 应付金额(含支付手续费) Payment payment = this.paymentDao.findUnique( Restrictions.eq("payConfig.id", payConfig.getId()), Restrictions.eq("orderType", order.getType()), Restrictions.eq("orderSn", order.getSN()), Restrictions.eq("paymentStatus", Payment.PaymentStatus.ready)); if (payment != null) { // 如果存在未完成的支付信息 if (amountPayable.compareTo(payment.getTotalAmount().subtract(payment.getPaymentFee())) == 0) { return payment; } else { this.invalid(payment.getSn()); } } payment = new Payment(); // 在线支付 String bankName = payProduct.getName(); String bankAccount = payConfig.getBargainorId(); payment.setPaymentType(paymentType); payment.setPaymentConfigName(payConfig.getName()); payment.setBankName(bankName); payment.setBankAccount(bankAccount); payment.setTotalAmount(amountPayable.add(paymentFee)); payment.setPaymentFee(paymentFee); payment.setPayer(payer); payment.setMemo(null); payment.setPaymentStatus(Payment.PaymentStatus.ready); payment.setPayConfig(payConfig); payment.setOrderType(order.getType()); payment.setOrderSn(order.getSN()); return this.paymentDao.save(payment); }