示例#1
0
    it('should build the correct quote for easy values [DOLLARS -> CENTS]', function() {
        var QuoteBuilder = require('app/payout/quote/builder');
        var QuoteValue  = require('app/payout/quote/value');
        var Quote = require('app/payout/quote/quote');
        var BigNumber = require('bignumber.js');

        var totalValue = new QuoteValue(new BigNumber(100), QuoteValue.DOLLARS);
        var quoteBuilder = new QuoteBuilder(totalValue);

        quoteBuilder.addFee('Google Fee', new BigNumber(30), new QuoteValue(new BigNumber(0), QuoteValue.DOLLARS));
        quoteBuilder.addFee('Admin Fee', new BigNumber(5), new QuoteValue(new BigNumber(0), QuoteValue.DOLLARS));

        var quote = quoteBuilder.build();

        assert.equal(quote.getQuoteValueByTitle(Quote.TOTAL_TITLE).getValue(QuoteValue.CENTS).toFixed(0), '10000');
        assert.equal(quote.getQuoteValueByTitle(Quote.PAYOUT_TITLE).getValue(QuoteValue.CENTS).toFixed(0), '6500');
        assert.equal(quote.getQuoteValueByTitle('Google Fee').getValue(QuoteValue.CENTS).toFixed(0), '3000');
        assert.equal(quote.getQuoteValueByTitle('Admin Fee').getValue(QuoteValue.CENTS).toFixed(0), '500');
    });
示例#2
0
    it('should throw QuoteError if fee is equal to total', function() {
        var QuoteBuilder = require('app/payout/quote/builder');
        var QuoteValue  = require('app/payout/quote/value');
        var BigNumber = require('bignumber.js');

        var totalValue = new QuoteValue(new BigNumber(1), QuoteValue.DOLLARS);
        var quoteBuilder = new QuoteBuilder(totalValue);

        quoteBuilder.addFee('Google Fee', new BigNumber(0), new QuoteValue(new BigNumber(100), QuoteValue.CENTS));

        assert.throws(quoteBuilder.build.bind(quoteBuilder), QuoteError);
    });
示例#3
0
    it('should not throw any error if fee is 1 cent under total', function() {
        var QuoteBuilder = require('app/payout/quote/builder');
        var QuoteValue  = require('app/payout/quote/value');
        var Quote = require('app/payout/quote/quote');
        var BigNumber = require('bignumber.js');

        var totalValue = new QuoteValue(new BigNumber(1), QuoteValue.DOLLARS);
        var quoteBuilder = new QuoteBuilder(totalValue);

        quoteBuilder.addFee('Google Fee', new BigNumber(0), new QuoteValue(new BigNumber(99), QuoteValue.CENTS));

        var quote = quoteBuilder.build();

        assert.equal(quote.getQuoteValueByTitle(Quote.TOTAL_TITLE).getValue(QuoteValue.DOLLARS).toFixed(2), '1.00');
        assert.equal(quote.getQuoteValueByTitle(Quote.PAYOUT_TITLE).getValue(QuoteValue.DOLLARS).toFixed(2), '0.01');
    });
示例#4
0
        function(results, callback) {
            var product = results['product'];
            var fees = results['fees'];

            var quoteBuilder = new QuoteBuilder(new QuoteValue(product.getValue(), QuoteValue.CENTS));
            quoteBuilder.addFees(fees.getMandatoryFees());

            var payoutFee = fees.getFeeByCode(payoutOption);
            var payoutFeePercent = new BigNumber(payoutFee['percent']);
            var payoutFeeFlat = new QuoteValue(new BigNumber(payoutFee['flat']), QuoteValue.CENTS);
            quoteBuilder.addFee(payoutFee['title'], payoutFeePercent, payoutFeeFlat);

            var quote = null;
            try {
                quote = quoteBuilder.build();
            } catch (err) {
                return callback(err);
            }

            callback(null, quote)
        }