Search in sources :

Example 1 with ReferralPayment

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);
}
Also used : ReferralPayment(io.lumeer.api.model.ReferralPayment) Document(org.bson.Document)

Example 2 with ReferralPayment

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));
    }
}
Also used : ReferralPayment(io.lumeer.api.model.ReferralPayment)

Aggregations

ReferralPayment (io.lumeer.api.model.ReferralPayment)2 Document (org.bson.Document)1