Exemplo n.º 1
0
  protected Long createCredit(
      final Long userId, final Long offerId, final Long merchantId, final Long locationId) {
    Kikbak kikbak = roKikbakDao.findByOfferId(offerId);
    Offer offer = roOfferDao.findById(offerId);
    Credit credit = new Credit();
    credit.setBeginDate(offer.getBeginDate());
    credit.setEndDate(offer.getEndDate());
    credit.setLocationId(locationId);
    credit.setMerchantId(offer.getMerchantId());
    credit.setOfferId(offerId);
    credit.setUserId(userId);
    credit.setValue(kikbak.getValue());
    credit.setRewardType(kikbak.getRewardType());
    credit.setKikbakId(kikbak.getId());
    credit.setRedeemCount(1);
    credit.setCreatedDate(new Date());

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

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

    return credit.getId();
  }
Exemplo n.º 2
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();
  }