Esempio n. 1
0
 /**
  * If the payout-limit of current merchant is 'follow parent', TE should query its parent merchant
  * till find a parent merchant whose payout-limit isn't 'follow parent'.
  *
  * @return the PrizeGroup which will be applied at final.
  */
 private PrizeGroup determinePrizeGroup(Context respCtx, Operator operator)
     throws ApplicationException {
   PrizeGroup prizeGroup = operator.getPrizeGroup();
   if (prizeGroup == null) {
     throw new ApplicationException(
         SystemException.CODE_MERCHANT_UNALLOWED_PAY,
         "No any prize group definition found of Operator("
             + operator
             + "), System will simply reject this payout request.");
   }
   if (PrizeGroup.ALLOWTYPE_USEPARENT == prizeGroup.getAllowType()) {
     // lookup prize group definition of operator's parent merchant
     Merchant leafMerchant =
         this.getMerchantDao().findById(Merchant.class, respCtx.getTransaction().getMerchantId());
     if (leafMerchant == null) {
       throw new ApplicationException(
           SystemException.CODE_NO_MERCHANT,
           "can NOT find merhcant by id=" + respCtx.getTransaction().getMerchantId());
     }
     prizeGroup = this.determinePrizeGroup(leafMerchant);
   } else {
     if (logger.isDebugEnabled()) {
       logger.debug(
           "Use the payout-limit setting(max="
               + prizeGroup.getMaxPayoutAmount()
               + ",min="
               + prizeGroup.getMinPayoutAmount()
               + ") of Operator("
               + operator
               + ") to verify payout limit.");
     }
   }
   return prizeGroup;
 }
Esempio n. 2
0
 private void addBalanceTransactionRecord(
     Context respCtx,
     BigDecimal cashoutAmount,
     int transType,
     String operatorMerchantid,
     int ownerType,
     int paymentType,
     BigDecimal commissionAmount,
     BigDecimal commissionRate)
     throws ApplicationException {
   BalanceTransactions bt = new BalanceTransactions();
   bt.setTeTransactionId(respCtx.getTransaction().getId());
   bt.setMerchantId(respCtx.getTransaction().getMerchantId());
   bt.setDeviceId(respCtx.getTransaction().getDeviceId());
   bt.setOperatorId(respCtx.getTransaction().getOperatorId());
   bt.setOwnerId(operatorMerchantid);
   bt.setOwnerType(ownerType);
   bt.setPaymentType(paymentType);
   bt.setTransactionType(transType);
   bt.setOriginalTransType(transType);
   bt.setTransactionAmount(cashoutAmount);
   bt.setCommissionAmount(commissionAmount);
   bt.setCommissionRate(commissionRate);
   bt.setCreateTime(net.mpos.fk.util.DateUtils.getNowTimestamp());
   bt.setStatus(BalanceTransactions.STATUS_VALID);
   this.balanceTransactionsDao.insert(bt);
 }
Esempio n. 3
0
 /**
  * When cash out, system check the cashout-limit of the merchant.
  *
  * @param respCtx The context of cashout transaction.
  * @param actualCashout The actual amount of cashout.
  * @throws ApplicationException when encounter any business exception.
  */
 protected void allowCashoutByLimit(Context respCtx, BigDecimal actualCashout)
     throws ApplicationException {
   PrizeGroup cashoutGroup = respCtx.getOperator().getCashoutGroup();
   if (cashoutGroup == null) {
     throw new ApplicationException(
         SystemException.CODE_MERCHANT_UNALLOWED_CASHOUT,
         "Operator("
             + respCtx.getOperator()
             + ") can't perform cashout, no any cashout group definition found.");
   }
   if (cashoutGroup.getMaxPayoutAmount() != null
       && cashoutGroup.getMaxPayoutAmount().compareTo(new BigDecimal("0")) >= 0) {
     if (actualCashout.compareTo(cashoutGroup.getMaxPayoutAmount()) > 0) {
       throw new ApplicationException(
           SystemException.CODE_MERCHANT_UNALLOWED_CASHOUT_SCOPE,
           "The prize actual amount("
               + actualCashout
               + ") exceed the max "
               + "allowed cashout amount("
               + cashoutGroup.getMaxPayoutAmount()
               + ") of the Operator("
               + respCtx.getOperator()
               + ").");
     }
   }
   if (cashoutGroup.getMinPayoutAmount() != null
       && cashoutGroup.getMinPayoutAmount().compareTo(new BigDecimal("0")) >= 0) {
     if (actualCashout.compareTo(cashoutGroup.getMinPayoutAmount()) < 0) {
       throw new ApplicationException(
           SystemException.CODE_MERCHANT_UNALLOWED_CASHOUT_SCOPE,
           "The prize actual amount("
               + actualCashout
               + ") is less than min cashout amount("
               + cashoutGroup.getMinPayoutAmount()
               + ") of Operator("
               + respCtx.getOperator()
               + ").");
     }
   }
 }
Esempio n. 4
0
 @Override
 public void allowPayout(
     Context respCtx,
     Game game,
     PayoutLevelAllowRequest[] levelAllowRequests,
     BigDecimal actualPayout)
     throws ApplicationException {
   // verify whether the game has been allocated
   MerchantCommission comm =
       this.getMerchantCommissionDao()
           .getByMerchantAndGame(respCtx.getTransaction().getMerchantId(), game.getId());
   if (comm == null || !comm.isAllowPayout()) {
     throw new SystemException(
         SystemException.CODE_OPERATOR_PAYOUT_NOPRIVILEDGE,
         "operator(id="
             + respCtx.getOperatorId()
             + ") has no priviledge to payout ticket of game '"
             + game.getId()
             + "', allocate the game to its merchant(id="
             + respCtx.getTransaction().getMerchantId()
             + ") first.");
   }
   GameType gameType = GameType.fromType(game.getType());
   // only need to check the prize group constraints of operator
   PrizeGroup prizeGroup = respCtx.getOperator().getPrizeGroup();
   if (!prizeGroup.isPayoutAllowed()) {
     throw new ApplicationException(
         SystemException.CODE_MERCHANT_UNALLOWED_PAY,
         "Operator(" + respCtx.getOperator() + ") doesn't allow payout.");
   }
   // ** both conditions must be satisfied
   // by payout limit
   if (new BigDecimal("0").compareTo(actualPayout) != 0) {
     this.verifyPayoutByLimit(respCtx, actualPayout, respCtx.getOperator());
   }
   // for odds and fix-prize game, no need to check prize level.
   if (!gameType.isFixedPrize()) {
     // by prize level
     if (levelAllowRequests != null) {
       for (PayoutLevelAllowRequest levelAllowRequest : levelAllowRequests) {
         this.verifyPayoutByLevel(
             respCtx,
             respCtx.getOperator(),
             levelAllowRequest.getRequestedPrizeLevels(),
             levelAllowRequest.getGameType(),
             levelAllowRequest.getPrizeGroupType());
       }
     }
   }
 }
Esempio n. 5
0
 /**
  * When cash out, a merchant can only cashout a given max amount.
  *
  * @param respCtx The context of cashout transaction.
  * @param actualCashout The actual amount of cashout.
  * @throws ApplicationException when encounter any business exception.
  */
 protected void allowDailyCashout(Context respCtx, BigDecimal actualCashout)
     throws ApplicationException {
   PrizeGroup cashoutGroup = respCtx.getOperator().getCashoutGroup();
   if (cashoutGroup == null) {
     throw new ApplicationException(
         SystemException.CODE_MERCHANT_UNALLOWED_CASHOUT,
         "Operator("
             + respCtx.getOperator()
             + ") can't perform cashout, no any cashout "
             + "group definition found.");
   }
   if (logger.isDebugEnabled()) {
     logger.debug(
         "Before cash out[dailyCashoutLevel: "
             + respCtx.getOperator().getDailyCashoutLevel()
             + ", dailyCashoutLimit: "
             + cashoutGroup.getDailyCashoutLimit()
             + ", cashoutAmount: "
             + actualCashout
             + "] of Operator( "
             + respCtx.getOperator()
             + ").");
   }
   if (actualCashout
           .add(respCtx.getOperator().getDailyCashoutLevel())
           .compareTo(cashoutGroup.getDailyCashoutLimit())
       > 0) {
     throw new ApplicationException(
         SystemException.CODE_EXCEED_ALLOWED_MERCHANT_DAILY_CASHOUT_LIMIT,
         "Cash out amount("
             + actualCashout
             + ") + current cashout level("
             + respCtx.getOperator().getDailyCashoutLevel()
             + ") has exceeded allowed limit("
             + cashoutGroup.getDailyCashoutLimit()
             + ") of Operator("
             + respCtx.getOperator()
             + ").");
   }
 }
Esempio n. 6
0
  // -----------------------------------------------------
  // HELP METHOD
  // -----------------------------------------------------
  private void cashoutLogic(
      Context respCtx,
      CashoutPass cashoutpass,
      String cashoutOperatorid,
      BigDecimal cashoutAmount,
      int transType)
      throws ApplicationException {
    GsonCashOutOperator gcoo = new GsonCashOutOperator();
    // check account whether or not sufficient
    Operator operator = this.operatorDao.findById(Operator.class, cashoutOperatorid);
    if (operator == null) {
      throw new ApplicationException(
          SystemException.CODE_NO_OPERATOR,
          "[Cashout] operator(id=" + cashoutOperatorid + ") doesn't exist.");
    }

    // check cash out operator id whether equals respCtx operator id , should not be the same
    if (cashoutOperatorid.equals(respCtx.getOperatorId())) {
      throw new ApplicationException(
          SystemException.CODE_CASHOUT_OPERATOR_SHOULD_NOT_SAME,
          "[Cashout] operator(id=" + cashoutOperatorid + ") should not the same with Operator.");
    }

    if (operator.getCreditType() == Merchant.CREDIT_TYPE_DEFINITIVEVALUE) {
      // check operator balance
      BigDecimal totalBalance = new BigDecimal("0");
      totalBalance = totalBalance.add(operator.getCommisionBalance());
      totalBalance = totalBalance.add(operator.getPayoutCreditLevel());
      totalBalance = totalBalance.add(operator.getCashoutBalance());

      if (logger.isDebugEnabled()) {
        logger.debug(
            "[Cashout] current operator :operator_id:"
                + operator.getId()
                + ",totalbalance="
                + totalBalance.toPlainString());
      }

      // judge the balance whether or not sufficient
      if (totalBalance.compareTo(cashoutAmount) < 0) {
        throw new ApplicationException(
            SystemException.CODE_INSUFFICIENT_BALANCE,
            "[Cashout] OPERATOR(id="
                + operator.getId()
                + ") insufficient balance[commission balance,cashout balance,payout balance].");
      }

      // ==============
      // deduct the money from balance order by [1)Commission balance
      // 2)Payout balance 3)Cash-out balance]
      BigDecimal commissionDeducted = new BigDecimal("0");
      BigDecimal payoutDeducted = new BigDecimal("0");
      BigDecimal cashoutDeducted = new BigDecimal("0");

      BigDecimal cashoutAmountTemp = operator.getCommisionBalance().subtract(cashoutAmount);
      if (cashoutAmountTemp.doubleValue() >= 0) {
        commissionDeducted = cashoutAmount;
      } else {
        // negative value
        if (operator.getCommisionBalance().doubleValue() < 0
            && operator.getPayoutCreditLevel().doubleValue() < 0) {
          cashoutDeducted = cashoutAmount;
        } else if (operator.getCommisionBalance().doubleValue() < 0) {
          // deducted account only (payout balance)
          if (operator.getPayoutCreditLevel().subtract(cashoutAmount).doubleValue() > 0) {
            payoutDeducted = cashoutAmount;
          } else {
            payoutDeducted = operator.getPayoutCreditLevel();
            cashoutDeducted = (cashoutAmount.subtract(payoutDeducted));
          }
        } else {
          // deducted account (commission balance + payout balance)
          if ((operator.getCommisionBalance().add(operator.getPayoutCreditLevel()))
                  .subtract(cashoutAmount)
                  .doubleValue()
              >= 0) {
            commissionDeducted = operator.getCommisionBalance();
            payoutDeducted = cashoutAmount.subtract(commissionDeducted);
          } else {
            if ((operator
                        .getCommisionBalance()
                        .add(operator.getPayoutCreditLevel())
                        .add(operator.getCashoutBalance()))
                    .subtract(cashoutAmount)
                    .doubleValue()
                >= 0) {
              commissionDeducted = operator.getCommisionBalance();
              payoutDeducted = operator.getPayoutCreditLevel();
              cashoutDeducted =
                  (cashoutAmount.subtract(commissionDeducted)).subtract(payoutDeducted);
            }
          }
        }
      }

      if (logger.isDebugEnabled()) {
        logger.debug(
            "[Cashout] current operator :operator_id:"
                + cashoutOperatorid
                + ",deducted money balance:commissionDeducted="
                + commissionDeducted.toPlainString()
                + ";payoutdeducted:"
                + payoutDeducted
                + ";cashoutdeducted:"
                + cashoutDeducted);
      }

      // set 2 decimals place
      commissionDeducted.setScale(
          MLotteryContext.getInstance().getInt(MLotteryContext.COMMISSION_BALANCE_PRECISION),
          BigDecimal.ROUND_HALF_UP);
      payoutDeducted.setScale(2, BigDecimal.ROUND_HALF_UP);
      cashoutDeducted.setScale(2, BigDecimal.ROUND_HALF_UP);
      this.operatorDao.deductBalanceByOperator(
          commissionDeducted, payoutDeducted, cashoutDeducted, cashoutOperatorid);
      // ADD BALANCE_TRANSACTION RECORD
      addBalanceTransactionRecord(
          respCtx,
          new BigDecimal(String.valueOf(cashoutAmount.doubleValue())),
          transType,
          cashoutOperatorid,
          BalanceTransactions.OWNER_TYPE_OPERATOR,
          BalanceTransactions.PAYMENT_TYPE_DEDUCTING_MONEY,
          new BigDecimal("0"),
          new BigDecimal("0"));

      // assemble the Json obj
      gcoo.setOperatorMerchantType(BalanceTransactions.OWNER_TYPE_OPERATOR);
      gcoo.setOperatorMerchantid(cashoutOperatorid);
      gcoo.setOperatorid(cashoutOperatorid);
      gcoo.setTotalAmount(cashoutAmount);
      gcoo.setCommission(commissionDeducted);
      gcoo.setPayout(payoutDeducted);
      gcoo.setCashout(cashoutDeducted);

    } else if (operator.getCreditType() == Merchant.CREDIT_TYPE_USE_PARENT) {
      // lookup the merchant
      Merchant originmerchant = getMerchantByOperator(cashoutOperatorid, false);
      Merchant finalMerchant =
          this.merchantDao.findDistributeMerchantByMerchantId(originmerchant.getId());
      if (finalMerchant == null) {
        throw new ApplicationException(
            SystemException.CODE_NO_MERCHANT,
            "operator(id=" + cashoutOperatorid + ") doesn't exist parent merchant.");
      }
      // check merchant balance
      BigDecimal totalBalance = new BigDecimal("0");
      totalBalance = totalBalance.add(finalMerchant.getCommisionBalance());
      totalBalance = totalBalance.add(finalMerchant.getCashoutBalance());
      totalBalance = totalBalance.add(finalMerchant.getPayoutCreditLevel());

      if (logger.isDebugEnabled()) {
        logger.debug(
            "current merchant :final_merchant_id:"
                + finalMerchant.getId()
                + ",totalbalance="
                + totalBalance.toPlainString());
      }

      // judge the balance whether or not sufficient
      if (totalBalance.compareTo(cashoutAmount) < 0) {
        throw new ApplicationException(
            SystemException.CODE_INSUFFICIENT_BALANCE,
            "MERCHANT(id="
                + finalMerchant.getId()
                + ") insufficient balance[commission balance,cashout balance,payout balance].");
      }

      // ==============
      // deduct the money from balance order by [1)Commission balance
      // 2)Payout balance 3)Cash-out balance]
      BigDecimal commissionDeducted = new BigDecimal("0");
      BigDecimal payoutDeducted = new BigDecimal("0");
      BigDecimal cashoutDeducted = new BigDecimal("0");

      BigDecimal cashoutAmountTemp = finalMerchant.getCommisionBalance().subtract(cashoutAmount);
      if (cashoutAmountTemp.doubleValue() >= 0) {
        commissionDeducted = cashoutAmount;
      } else {
        // negative value
        if (finalMerchant.getCommisionBalance().doubleValue() < 0
            && finalMerchant.getPayoutCreditLevel().doubleValue() < 0) {
          cashoutDeducted = cashoutAmount;
        } else if (finalMerchant.getCommisionBalance().doubleValue() < 0) {
          // deducted account only (payout balance)
          if (finalMerchant.getPayoutCreditLevel().subtract(cashoutAmount).doubleValue() > 0) {
            payoutDeducted = cashoutAmount;
          } else {
            payoutDeducted = finalMerchant.getPayoutCreditLevel();
            cashoutDeducted = (cashoutAmount.subtract(payoutDeducted));
          }
        } else {
          // deducted account (commission balance + payout balance)
          if ((finalMerchant.getCommisionBalance().add(finalMerchant.getPayoutCreditLevel()))
                  .subtract(cashoutAmount)
                  .doubleValue()
              >= 0) {
            commissionDeducted = finalMerchant.getCommisionBalance();
            payoutDeducted = cashoutAmount.subtract(commissionDeducted);
          } else {
            if ((finalMerchant
                        .getCommisionBalance()
                        .add(finalMerchant.getPayoutCreditLevel())
                        .add(finalMerchant.getCashoutBalance()))
                    .subtract(cashoutAmount)
                    .doubleValue()
                >= 0) {
              commissionDeducted = finalMerchant.getCommisionBalance();
              payoutDeducted = finalMerchant.getPayoutCreditLevel();
              cashoutDeducted =
                  (cashoutAmount.subtract(commissionDeducted)).subtract(payoutDeducted);
            }
          }
        }
      }

      if (logger.isDebugEnabled()) {
        logger.debug(
            "[Cashout] current merchant :merchant_id:"
                + finalMerchant.getId()
                + ",deducted money balance:commissionDeducted="
                + commissionDeducted.toPlainString()
                + ";payoutdeducted:"
                + payoutDeducted
                + ";cashoutdeducted:"
                + cashoutDeducted);
      }

      commissionDeducted.setScale(
          MLotteryContext.getInstance().getInt(MLotteryContext.COMMISSION_BALANCE_PRECISION),
          BigDecimal.ROUND_HALF_UP);
      payoutDeducted.setScale(2, BigDecimal.ROUND_HALF_UP);
      cashoutDeducted.setScale(2, BigDecimal.ROUND_HALF_UP);
      this.merchantDao.deductBalanceByMerchant(
          commissionDeducted, payoutDeducted, cashoutDeducted, finalMerchant.getId());

      // ADD BALANCE_TRANSACTION RECORD
      addBalanceTransactionRecord(
          respCtx,
          new BigDecimal(String.valueOf(cashoutAmount.doubleValue())),
          transType,
          String.valueOf(finalMerchant.getId()),
          BalanceTransactions.OWNER_TYPE_MERCHANT,
          BalanceTransactions.PAYMENT_TYPE_DEDUCTING_MONEY,
          new BigDecimal("0"),
          new BigDecimal("0"));

      // assemble the Json obj
      gcoo.setOperatorMerchantType(BalanceTransactions.OWNER_TYPE_MERCHANT);
      gcoo.setOperatorMerchantid(String.valueOf(finalMerchant.getId()));
      gcoo.setOperatorid(cashoutOperatorid);
      gcoo.setTotalAmount(cashoutAmount);
      gcoo.setCommission(commissionDeducted);
      gcoo.setPayout(payoutDeducted);
      gcoo.setCashout(cashoutDeducted);
    }

    // update 'CASHOUT_PASS' the field 'cashout_te_transaction_id'
    // increase the tried times add 1
    if (cashoutpass != null) {
      cashoutpass.setId(cashoutpass.getId());
      cashoutpass.setTriedTimes(cashoutpass.getTriedTimes());
      cashoutpass.setCashoutTeTransactionId(respCtx.getTransaction().getId());
      cashoutpass.setUpdateBy(respCtx.getOperatorId());
      cashoutpass.setUpdateTime(net.mpos.fk.util.DateUtils.getCurrentDate());
      this.cashoutPassDao.update(cashoutpass);
    }
    // ==========================
    // //add cash out balance & commission to self operator
    String commissionOperatorId = respCtx.getOperatorId();
    Operator commisionOperator = this.operatorDao.findById(Operator.class, commissionOperatorId);
    if (commisionOperator == null) {
      throw new ApplicationException(
          SystemException.CODE_NO_OPERATOR,
          "[CashoutByPassword] commisionOperator(id=" + commissionOperatorId + ") doesn't exist.");
    }

    // credit
    if (commisionOperator.getCreditType() == Merchant.CREDIT_TYPE_DEFINITIVEVALUE) {
      BigDecimal cashoutrate = commisionOperator.getCashoutRate();
      BigDecimal cashoutamount = cashoutAmount;
      // BigDecimal commissionAmount = cashoutamount.multiply(cashoutrate);
      BigDecimal commissionAmount =
          SimpleToolkit.mathMultiple(
              cashoutamount,
              cashoutrate,
              MLotteryContext.getInstance().getInt(MLotteryContext.COMMISSION_BALANCE_PRECISION));

      cashoutamount.setScale(2, BigDecimal.ROUND_HALF_UP);
      this.operatorDao.addCashoutAndCommissionToOperator(
          cashoutamount, commissionAmount, commissionOperatorId);

      // insert record into 'BALANCE_TRANSACTIONS'
      // ADD BALANCE_TRANSACTION RECORD
      addBalanceTransactionRecord(
          respCtx,
          cashoutAmount,
          transType,
          commissionOperatorId,
          BalanceTransactions.OWNER_TYPE_OPERATOR,
          BalanceTransactions.PAYMENT_TYPE_PLUSING_MONEY,
          commissionAmount,
          cashoutrate);
      // assemble the Json obj
      gcoo.setPlusOperatorMerchantType(BalanceTransactions.OWNER_TYPE_OPERATOR);
      gcoo.setPlusOperatorid(commissionOperatorId);
      gcoo.setPlusOperatorCashoutBalance(cashoutamount);
      gcoo.setPlusOperatorCommissionBalance(commissionAmount);
      gcoo.setPlusOperatorCommissionRate(cashoutrate);
    } else if (commisionOperator.getCreditType() == Merchant.CREDIT_TYPE_USE_PARENT) {
      // lookup the merchant
      Merchant originmerchant = getMerchantByOperator(commissionOperatorId, false);
      Merchant finalMerchant =
          this.merchantDao.findDistributeMerchantByMerchantId(originmerchant.getId());
      if (finalMerchant == null) {
        throw new ApplicationException(
            SystemException.CODE_NO_MERCHANT,
            "commission operator(id=" + commissionOperatorId + ") doesn't exist parent merchant.");
      }

      // use operator cash out rate
      BigDecimal cashoutrate = commisionOperator.getCashoutRate();
      BigDecimal cashoutamount = cashoutAmount;
      // BigDecimal commissionOperatorAmount = cashoutamount.multiply(cashoutrate);
      BigDecimal commissionOperatorAmount =
          SimpleToolkit.mathMultiple(
              cashoutamount,
              cashoutrate,
              MLotteryContext.getInstance().getInt(MLotteryContext.COMMISSION_BALANCE_PRECISION));

      // merchant cash out rate
      // BigDecimal finalcashoutrate = finalMerchant.getCashoutRate();
      // BigDecimal finalcashoutamount = cashoutAmount;
      // BigDecimal commissionMerchantAmount = finalcashoutamount.multiply(finalcashoutrate);

      cashoutamount.setScale(2, BigDecimal.ROUND_HALF_UP);
      this.merchantDao.addCashoutAndCommissionToMerchant(
          cashoutamount, null, finalMerchant.getId());
      // ADD BALANCE_TRANSACTION RECORD
      addBalanceTransactionRecord(
          respCtx,
          cashoutAmount,
          transType,
          commissionOperatorId,
          BalanceTransactions.OWNER_TYPE_OPERATOR,
          BalanceTransactions.PAYMENT_TYPE_PLUSING_MONEY,
          commissionOperatorAmount,
          cashoutrate);

      addBalanceTransactionRecord(
          respCtx,
          cashoutAmount,
          transType,
          String.valueOf(finalMerchant.getId()),
          BalanceTransactions.OWNER_TYPE_MERCHANT,
          BalanceTransactions.PAYMENT_TYPE_PLUSING_MONEY,
          new BigDecimal("0"),
          new BigDecimal("0"));

      // assemble the Json obj
      gcoo.setPlusOperatorMerchantType(BalanceTransactions.OWNER_TYPE_OPERATOR);
      gcoo.setPlusOperatorid(commissionOperatorId);
      gcoo.setPlusOperatorCashoutBalance(cashoutamount);
      gcoo.setPlusOperatorCommissionBalance(commissionOperatorAmount);
      gcoo.setPlusOperatorCommissionRate(cashoutrate);

      gcoo.setPlusOperatorMerchantType(BalanceTransactions.OWNER_TYPE_MERCHANT);
      gcoo.setPlusMerchantid(String.valueOf(finalMerchant.getId()));
      gcoo.setPlusMerchantCashoutBalance(cashoutamount);
      gcoo.setPlusMerchantCommissionBalance(new BigDecimal("0"));
      gcoo.setPlusMerchantCommissionRate(new BigDecimal("0"));
    }

    // DESTINATION_OPEATOR
    respCtx.getTransaction().setDestinationOpeator(cashoutOperatorid);
    respCtx.getTransaction().setTotalAmount(cashoutAmount);

    // write transaction message for reversal.
    // add record to te_transaction_msg
    // assemble request message use JSON
    String reqmsg = new Gson().toJson(gcoo);
    TransactionMessage msg = new TransactionMessage();
    msg.setTransactionId(respCtx.getTransaction().getId());
    msg.setRequestMsg(reqmsg);
    respCtx.getTransaction().setTransMessage(msg);
  }
Esempio n. 7
0
  @Override
  public CashOutByOperatorPassDto cashoutOperatorByPass(
      Context respCtx, Context responseCtx, CashOutByOperatorPassDto cashoutDto)
      throws ApplicationException {
    // tried times add 1
    this.cashoutPassDao.increaseTriedTimes(cashoutDto.getBarcode());

    // lookup the 'CASHOUT_PASS' according to field 'BARCODE' & 'password'
    CashoutPass cashoutpass = this.cashoutPassDao.findByBarcode(cashoutDto.getBarcode());
    if (cashoutpass == null || cashoutpass.getId() == null || "".equals(cashoutpass.getId())) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_NO_EXIST_BARCODE,
      // "[CashoutByPassword](barcode="
      // + cashoutDto.getBarcode() + ") not exist the barcode].");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_NO_EXIST_BARCODE);
      logger.error("======================================");
      logger.error(
          "[CashoutByPassword](barcode=" + cashoutDto.getBarcode() + ") not exist the barcode].");
      logger.error("======================================");
      return null;
    }

    // check whether or not used
    if (cashoutpass.getCashoutTeTransactionId() != null
        && !"".equals(cashoutpass.getCashoutTeTransactionId())) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_ALREADY_USED,
      // "[CashoutByPassword](barcode="
      // + cashoutDto.getBarcode() + ") is already used].");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_ALREADY_USED);
      logger.error("======================================");
      logger.error(
          "[CashoutByPassword](barcode=" + cashoutDto.getBarcode() + ") is already used].");
      logger.error("======================================");
      return null;
    }

    // check expired time
    if (new Date().compareTo(cashoutpass.getExpireTime()) > 0) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_EXPIRETIME,
      // "[CashoutByPassword] The cashout password is expiry !");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_EXPIRETIME);
      logger.error("======================================");
      logger.error("[CashoutByPassword] The cashout password is expiry !");
      logger.error("======================================");
      return null;
    }

    // check max tried times
    SysConfiguration sysConf = this.getSysConfigurationDao().getSysConfiguration();
    int maxiumtimes = sysConf.getMaxiumTimesOfCashoutPass();
    if ((cashoutpass.getTriedTimes()) > maxiumtimes) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_EXCEED_MAXTIMES,
      // "[CashoutByPassword] The cashout by password is exceed max tried times !");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_EXCEED_MAXTIMES);
      logger.error("======================================");
      logger.error("[CashoutByPassword] The cashout by password is exceed max tried times !");
      logger.error("======================================");
      return null;
    }

    // check password whether or not correct
    if (!cashoutpass.getCashoutPassword().equals(cashoutDto.getPassword())) {
      // throw new ApplicationException(SystemException.CODE_CASHOUTPASS_INCORRECT,
      // "[CashoutByPassword](barcode="
      // + cashoutDto.getBarcode() + ") password is incorrect].");
      responseCtx.setResponseCode(SystemException.CODE_CASHOUTPASS_INCORRECT);
      logger.error("======================================");
      logger.error(
          "[CashoutByPassword](barcode=" + cashoutDto.getBarcode() + ") password is incorrect].");
      logger.error("======================================");
      return null;
    }

    // main logic for cash out
    cashoutLogic(
        respCtx,
        cashoutpass,
        cashoutpass.getOperatorId(),
        cashoutpass.getCashoutAmount(),
        TransactionType.CASH_OUT_OPERATOR_PASS.getRequestType());

    // ==========================

    // assemble response bean
    CashOutByOperatorPassDto respCashoutPassDto = new CashOutByOperatorPassDto();
    respCashoutPassDto.setAmount(cashoutpass.getCashoutAmount());
    respCashoutPassDto.setOperatorId(cashoutpass.getOperatorId());

    return respCashoutPassDto;
  }
Esempio n. 8
0
  @Override
  public CashOutPassDto getCashoutPass(Context respCtx, CashOutPassDto cashoutDto)
      throws ApplicationException {
    String cashoutOperatorid = respCtx.getOperatorId();
    Operator operator = this.operatorDao.findById(Operator.class, cashoutOperatorid);
    if (operator == null) {
      throw new ApplicationException(
          SystemException.CODE_NO_OPERATOR,
          "operator(id=" + cashoutOperatorid + ") doesn't exist.");
    }

    // cashout amount must greater than 0
    if (cashoutDto.getAmount().doubleValue() <= 0) {
      throw new ApplicationException(
          SystemException.CODE_CASHOUT_AMOUNT_LESSTHAN_ZERO,
          "GetCashoutPass,OPERATOR(id="
              + operator.getId()
              + ") can't accept cashout amount less or equal 0");
    }

    if (operator.getCreditType() == Merchant.CREDIT_TYPE_DEFINITIVEVALUE) {
      // check operator balance
      BigDecimal totalBalance = new BigDecimal("0");
      totalBalance = totalBalance.add(operator.getCommisionBalance());
      totalBalance = totalBalance.add(operator.getCashoutBalance());
      totalBalance = totalBalance.add(operator.getPayoutCreditLevel());

      if (logger.isDebugEnabled()) {
        logger.debug(
            "current operator :operator_id:"
                + operator.getId()
                + ",totalbalance="
                + totalBalance.toPlainString());
      }

      // judge the balance whether or not sufficient
      if (totalBalance.compareTo(cashoutDto.getAmount()) < 0) {
        throw new ApplicationException(
            SystemException.CODE_INSUFFICIENT_BALANCE,
            "OPERATOR(id="
                + operator.getId()
                + ") insufficient balance[commission balance,cashout balance,payout balance].");
      }

    } else if (operator.getCreditType() == Merchant.CREDIT_TYPE_USE_PARENT) {
      // lookup the merchant
      Merchant originmerchant = getMerchantByOperator(cashoutOperatorid, false);
      Merchant finalMerchant =
          this.merchantDao.findDistributeMerchantByMerchantId(originmerchant.getId());
      if (finalMerchant == null) {
        throw new ApplicationException(
            SystemException.CODE_NO_MERCHANT,
            "operator(id=" + cashoutOperatorid + ") doesn't exist parent merchant.");
      }
      // check merchant balance
      BigDecimal totalBalance = new BigDecimal("0");
      totalBalance = totalBalance.add(finalMerchant.getCommisionBalance());
      totalBalance = totalBalance.add(finalMerchant.getCashoutBalance());
      totalBalance = totalBalance.add(finalMerchant.getPayoutCreditLevel());

      if (logger.isDebugEnabled()) {
        logger.debug(
            "current merchant :final_merchant_id:"
                + finalMerchant.getId()
                + ",totalbalance="
                + totalBalance.toPlainString());
      }

      // judge the balance whether or not sufficient
      if (totalBalance.compareTo(cashoutDto.getAmount()) < 0) {
        throw new ApplicationException(
            SystemException.CODE_INSUFFICIENT_BALANCE,
            "MERCHANT(id="
                + finalMerchant.getId()
                + ") insufficient balance[commission balance,cashout balance,payout balance].");
      }
    }

    // Get sys_configuration
    SysConfiguration sysConf = this.getSysConfigurationDao().getSysConfiguration();

    // successful record the data to 'CASHOUT_PASS'
    // MAX_EXPIRE_TIME_CASHOUT_PASS (unit: minute)
    String teTransactionID = respCtx.getTransaction().getId();

    CashoutPass cashoutpass = new CashoutPass();
    String generalid = this.getUuidManager().getGeneralID();
    cashoutpass.setId(generalid);
    cashoutpass.setOperatorId(cashoutOperatorid);
    cashoutpass.setCashoutAmount(cashoutDto.getAmount());
    cashoutpass.setCashoutPassword(cashoutDto.getPassword());
    cashoutpass.setExpireTime(
        DateUtils.addMinute(new Date(), sysConf.getMaxExpireTimeCashoutPass()));
    cashoutpass.setTriedTimes(0);
    cashoutpass.setTeTransactionId(teTransactionID);
    cashoutpass.setCashoutBarCode(new Barcoder(0, generalid).getBarcode()); // barcode
    cashoutpass.setCreateBy(respCtx.getOperatorId());
    cashoutpass.setCreateTime(net.mpos.fk.util.DateUtils.getCurrentDate());

    this.cashoutPassDao.insert(cashoutpass);

    // assemble the response bean
    CashOutPassDto respCashoutDto = new CashOutPassDto();
    respCashoutDto.setAmount(cashoutDto.getAmount());
    respCashoutDto.setExpireTime(
        net.mpos.fk.util.DateUtils.convertTimestampToString(cashoutpass.getExpireTime()));
    respCashoutDto.setBarcode(cashoutpass.getCashoutBarCode());

    return respCashoutDto;
  }
Esempio n. 9
0
 @RequestMap("{transType:501}")
 public void lookupWorkingKey(Context request, Context response) throws ApplicationException {
   WorkingKey key = this.getWorkingKeyService().fetchWorkingKey(request.getGpe().getId());
   response.setModel(key);
 }