Ejemplo n.º 1
0
        /// <summary>
        /// Create a new payment against an existing contract in EazyCustomerManager
        /// </summary>
        ///
        /// <param name="Contract">The GUID of the contact a payment will be made against</param>
        /// <param name="PaymentAmount">The total amount to be collected from the new payment</param>
        /// <param name="CollectionDate">The desired start date of the new contract. This must be x working days in the future, where x is the agreed amount of working days with Eazy Collect.</param>
        /// <param name="Comment">A comment related to the new payment/param>
        ///
        /// <OptionalParams>
        /// <param name="IsCredit">If you have your own SUN and you have made prior arrangements with Eazy Collect, this may be passed to issue a credit to a customer.By default, it is set to false.</param>
        /// </OptionalParams>
        /// <example>
        /// Payment("42217d45-cf22-4430-ab02-acc1f8a2d020", "10.00", "2019-05-07", "A new payment")
        /// </example>
        ///
        /// <returns>
        /// Confirmation string
        /// </returns>
        public string Payment(string Contract, string PaymentAmount, string CollectionDate, string Comment, bool IsCredit = false)
        {
            if (Contract == "" || PaymentAmount == "" || CollectionDate == "" || Comment == "")
            {
                throw new Exceptions.EmptyRequiredParameterException(
                          "One or more required parameters are empty. Please double check all required parameters are filled and re-submit."
                          );
            }

            // Create a new dictionary of parameters
            Parameters = new Dictionary <string, string>();

            PaymentChecks = new Utilities.PaymentPostChecks();
            bool   _PaymentAmountNotNegative = PaymentChecks.CheckPaymentAmount(PaymentAmount);
            string TrueCollectionDate        = PaymentChecks.CheckPaymentDate(CollectionDate, Settings);
            bool   IsCreditAllowed           = PaymentChecks.CheckIfCreditIsAllowed(Settings);


            // Add method arguments to the parameters only if they are not empty
            try
            {
                Parameters.Add("amount", PaymentAmount);
                Parameters.Add("date", TrueCollectionDate);
                Parameters.Add("comment", Comment);
            }
            catch (ArgumentException)
            {
                throw new Exceptions.InvalidParameterException("There was an error adding one or more parameters to the call. Please try again, or contact [email protected]");
            }

            if (!IsCreditAllowed)
            {
                if (IsCredit)
                {
                    throw new Exceptions.InvalidParameterException("Is Credit is not allowed.");
                }
            }
            else
            {
                if (IsCredit)
                {
                    Parameters.Add("isCredit", IsCredit.ToString());
                }
            }


            var CreateRequest = Handler.Session(Settings);
            var SendRequest   = CreateRequest.Post(string.Format("contract/{0}/payment", Contract), Parameters);

            if (SendRequest.Contains("Contract not found"))
            {
                throw new Exceptions.InvalidParameterException("The specified contract could not be found in EazyCustomerManager");
            }

            // Pass the return string to the handler. This will throw an exception if it is not what we expect
            Handler.GenericExceptionCheck(SendRequest);
            return(SendRequest);
        }
        /// <summary>
        /// Modify the regular collection amount of a contract in EazyCustomerManager
        /// </summary>
        ///
        /// <remarks>
        /// It is important to note that if the contract is already within the cut-off date for the next collection, the regular collection amount will not be amended until the following month.
        /// </remarks>
        ///
        /// <param name="Contract">The GUID of an existing contract within EazyCustomerManager</param>
        /// <param name="PaymentAmount">The new regular collection amount the existing contract</param>
        /// <param name="Comment">A comment to describe the actions performed when modifying the regular collection amount of the existing contract</param>
        ///
        /// <example>ContractAmount("36bb4f4f-9a7f-4ead-82dc-9295c6fb9e8b", "10.50", "Added x product");</example>
        /// <returns></returns>
        public string ContractAmount(string Contract, string PaymentAmount, string Comment)
        {
            if (PaymentAmount == "" || Comment == "")
            {
                throw new Exceptions.EmptyRequiredParameterException(
                          "One or more required parameters are empty. Please double check all required parameters are filled and re-submit."
                          );
            }

            PaymentChecks = new Utilities.PaymentPostChecks();
            // Perform several basic checks to ensure the information provided for the customer is fit for use
            PaymentChecks.CheckPaymentAmount(PaymentAmount);

            // Create a new dictionary of parameters
            Parameters = new Dictionary <string, string>();

            // Add method arguments to the parameters only if they are not empty
            try
            {
                Parameters.Add("amount", PaymentAmount);
                Parameters.Add("comment", Comment);
            }
            catch (ArgumentException)
            {
                throw new Exceptions.InvalidParameterException("There was an error adding one or more parameters to the call. Please try again, or contact [email protected]");
            }

            var CreateRequest = Handler.Session(Settings);
            var SendRequest   = CreateRequest.Patch(string.Format("contract/{0}/amount", Contract), _Parameters: Parameters);

            Handler.GenericExceptionCheck(SendRequest);

            // If no customers were returned
            if (SendRequest.Contains("Contract updated"))
            {
                return(string.Format("The contract {0} has been updated with the new regular collection amount of {1}", Contract, PaymentAmount));
            }
            else if (SendRequest.Contains("Contract not found"))
            {
                throw new Exceptions.ResourceNotFoundException(string.Format("The contract {0} could not be found within EazyCustomerManager", Contract));
            }
            else
            {
                return(SendRequest);
            }
        }