Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subscription"/> class.
 /// If the activated date is before the start date, a pro-rated amount is calculated.
 /// If the activated date is after the start date, they are swapped and a pro-rated amount is calculated.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="start">The starting date.</param>
 /// <param name="end">The ending date.</param>
 /// <param name="activated">The activated date.</param>
 /// <param name="billingPeriod">The billing period.</param>
 /// <param name="billingAmount">The billing amount.</param>
 /// <param name="trialPeriod">The trial period.</param>
 public Subscription(string name, DateTime start, DateTime end, DateTime activated, Period billingPeriod,
                     Money billingAmount, Period trialPeriod)
     : this(name, start, end, billingPeriod, billingAmount)
 {
     ApplyTrialPeriod(trialPeriod, 1);
     ApplyProratedAmount(start, billingAmount, activated);
 }
        /// <summary>
        /// Captures the specified amount.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="card">The card.</param>
        /// <param name="transactionId">The transaction id.</param>
        /// <returns></returns>
        public AuthorizeNetResult Capture(Money amount, CreditCard card, string transactionId)
        {
            var uri = GetCreditCardUri(this);

            return RequestWithMoneyCreditCardAndTransaction(CreditCardTransactionType.Capture, amount, card,
                                                            transactionId, uri);
        }
Esempio n. 3
0
        public void Cannot_add_different_currencies()
        {
            var left = new Money(Currency.CAD, 10);
            var right = new Money(Currency.USD, 20);

            Assert.Throws(typeof (ArithmeticException), () =>
                                                            {
                                                                var total = left + right;
                                                                Console.WriteLine(total);
                                                            });
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subscription"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="start">The starting date.</param>
 /// <param name="billingPeriod">The billing period.</param>
 /// <param name="billingAmount">The billing amount.</param>
 /// <param name="trialPeriod">The trial period.</param>
 public Subscription(string name, DateTime start, Period billingPeriod, Money billingAmount, Period trialPeriod)
     : this(name, start, billingPeriod, billingAmount)
 {
     ApplyTrialPeriod(trialPeriod, 1);
 }
Esempio n. 5
0
        private void ApplyTrialPeriod(Period trialPeriod, Money? trialAmount, int occurrences)
        {
            TrialAmount = trialAmount;
            TrialPeriod = trialPeriod;

            SetPaymentStartDateByTrialPeriod(occurrences);
        }
Esempio n. 6
0
        private void ApplyProratedAmount(DateTime start, Money billingAmount, DateTime activated)
        {
            if (activated == start)
            {
                return;
            }

            if (activated > start)
            {
                var temp = activated;
                activated = start;
                start = temp;
            }

            var payments = PaymentDates.ToArray();
            if (payments.Length < 2)
            {
                return;
            }

            var secondPayment = payments[1];
            var offsetDays = DateSpan.GetDifference(DateInterval.Days, activated, start);
            var periodDays = DateSpan.GetDifference(DateInterval.Days, PaymentStartDate, secondPayment);
            if (periodDays == 0)
            {
                return;
            }

            var percentage = Convert.ToDouble(offsetDays)/Convert.ToDouble(periodDays);
            var prorated = billingAmount*percentage;

            ProratedAmount = prorated;
            ProratedStartDate = activated;
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subscription"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="start">The starting date.</param>
 /// <param name="billingPeriod">The billing period.</param>
 /// <param name="billingAmount">The billing amount.</param>
 public Subscription(string name, DateTime start, Period billingPeriod, Money billingAmount)
 {
     Name = name;
     PeriodStartDate = start;
     Period = billingPeriod;
     PaymentAmount = billingAmount;
     PaymentStartDate = start;
     TrialAmount = null;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subscription"/> class.
 /// If the activated date is before the start date, a pro-rated amount is calculated.
 /// If the activated date is after the start date, they are swapped and a pro-rated amount is calculated.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="start">The starting date.</param>
 /// <param name="activated">The activated date.</param>
 /// <param name="billingPeriod">The billing period.</param>
 /// <param name="billingAmount">The billing amount.</param>
 /// <param name="trialPeriod">The trial period.</param>
 /// <param name="trialAmount">The trial amount.</param>
 /// <param name="trialOccurrences">The number of trial period occurrences.</param>
 public Subscription(string name, DateTime start, DateTime activated, Period billingPeriod, Money billingAmount,
                     Period trialPeriod, Money trialAmount, int trialOccurrences)
     : this(name, start, billingPeriod, billingAmount)
 {
     ApplyTrialPeriod(trialPeriod, trialAmount, trialOccurrences);
     ApplyProratedAmount(start, billingAmount, activated);
 }
Esempio n. 9
0
        public void Can_multiply_non_identity_without_casting()
        {
            var left = new Money(4.00);
            var right = new Money(4.00);

            var total = right*left;
            Assert.AreEqual(16.00, (double) total);
        }
Esempio n. 10
0
        public void Can_multiply_money()
        {
            var left = new Money(10.00);
            var right = new Money(20.00);

            var total = right*left;
            Assert.AreEqual(200.00, (double) total);
        }
Esempio n. 11
0
        public void Can_divide_money_by_positive_identity()
        {
            var left = new Money(1);
            var right = new Money(1);

            var total = right/left;
            Assert.AreEqual(1, total);
        }
Esempio n. 12
0
        /// <summary>
        /// Implements the operator *.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static Money operator *(Money left, Money right)
        {
            EnsureSameCurrency(left, right);

            HarmonizeDecimalPlaces(ref left, ref right);

            var product = Convert.ToDouble(left._units)*Convert.ToDouble(right._units);

            var factor = Math.Pow(10, left._places*2);

            product /= factor;

            var result = new Money(left._currencyInfo, product);

            return result;
        }
Esempio n. 13
0
        /// <summary>
        /// Implements the operator /.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static Money operator /(Money left, Money right)
        {
            EnsureSameCurrency(left, right);

            HarmonizeDecimalPlaces(ref left, ref right);

            var quotient = Convert.ToDouble(left._units)/Convert.ToDouble(right._units);

            var result = new Money(left._currencyInfo, quotient);

            return result;
        }
        /// <summary>
        /// Credits the specified amount.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="card">The card.</param>
        /// <param name="transactionId">The transaction id.</param>
        /// <returns></returns>
        public AuthorizeNetResult Credit(Money amount, CreditCard card, string transactionId)
        {
            ValidateAmountTransaction(amount, transactionId);

            _creditCard = card;
            _creditCardTransactionType = CreditCardTransactionType.Credit;
            _info.TransactionId = transactionId;
            _info.TransactionAmount = amount;

            var uri = GetCreditCardUri(this);

            return Request(_info, uri);
        }
        /// <summary>
        /// Authorizes the specified amount.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="card">The card.</param>
        /// <returns></returns>
        public AuthorizeNetResult Authorize(Money amount, CreditCard card)
        {
            var uri = GetCreditCardUri(this);

            return RequestWithMoneyAndCard(CreditCardTransactionType.PreAuthorization, amount, card, uri);
        }