use of io.lumeer.api.model.ReferralPayment in project engine by Lumeer.
the class ReferralPaymentCodec method decode.
@Override
public ReferralPayment decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
Document bson = documentCodec.decode(bsonReader, decoderContext);
String id = bson.getObjectId(ID).toHexString();
String referral = bson.getString(REFERRAL);
Long amount = bson.getLong(AMOUNT);
String currency = bson.getString(CURRENCY);
Boolean paid = bson.getBoolean(PAID);
return new ReferralPayment(id, referral, amount, currency, paid);
}
use of io.lumeer.api.model.ReferralPayment in project engine by Lumeer.
the class PaymentFacade method storeReferralPayment.
private void storeReferralPayment(final Payment payment) {
final long months = getPaymentMonthsDuration(payment);
if (months >= 12) {
final String referral = payment.getReferral();
final String userId = Utils.str36toHex(referral);
final boolean isAffiliate = userFacade.isUserAffiliate(userId);
final long amount = Math.round(((double) payment.getAmount() / months) * 12);
final long commission = Math.round(isAffiliate ? amount * 0.1 : amount * 0.05);
referralPaymentDao.createReferralPayment(new ReferralPayment(null, payment.getReferral(), commission, payment.getCurrency(), false));
}
}
Aggregations