Пример #1
0
  protected Long updateCreditAvailable(
      Credit credit, final Long offerId, final Long merchantId, final Long locationId) {
    Offer offer = roOfferDao.findById(offerId);
    if (credit.getRedeemCount() + 1 > offer.getRedeemLimit()) {
      // exceed limit, no transaction and credit update
      return null;
    }

    Kikbak kikbak = roKikbakDao.findByOfferId(offerId);
    credit.setValue(kikbak.getValue() + credit.getValue());
    credit.setRedeemCount(credit.getRedeemCount() + 1);

    Transaction txn = new Transaction();
    txn.setAmount(kikbak.getValue());
    txn.setAuthorizationCode("newshare");
    txn.setLocationId(locationId);
    txn.setMerchantId(merchantId);
    txn.setOfferId(offerId);
    txn.setTransactionType((short) TransactionType.Credit.ordinal());
    txn.setVerificationCode("newshare");
    txn.setUserId(credit.getUserId());
    txn.setDate(new Date());

    rwCreditDao.makePersistent(credit);
    rwTransactionDao.makePersistent(txn);

    return credit.getId();
  }