Esempio n. 1
0
            /// <summary>
            /// Customer account deposit transactions cannot be tendered with the 'On Account' payment method.
            /// </summary>
            /// <param name="context">The context.</param>
            /// <param name="transaction">The transaction.</param>
            /// <param name="tenderLineBase">The tender line.</param>
            public static void ValidateCustomerAccountDepositPaymentRestrictions(RequestContext context, SalesTransaction transaction, TenderLineBase tenderLineBase)
            {
                if (transaction.CartType != CartType.AccountDeposit)
                {
                    return;
                }

                var        getChannelTenderTypesDataRequest = new GetChannelTenderTypesDataRequest(context.GetPrincipal().ChannelId, QueryResultSettings.AllRecords);
                var        tenderTypes = context.Runtime.Execute <EntityDataServiceResponse <TenderType> >(getChannelTenderTypesDataRequest, context).PagedEntityCollection.Results;
                TenderType tenderType  = tenderTypes.Single(t => t.TenderTypeId.Equals(tenderLineBase.TenderTypeId));

                // It should not be allowed to pay with and deposit to the same customer account.
                if (tenderType.OperationType == RetailOperation.PayCustomerAccount &&
                    tenderLineBase.CustomerId.Equals(transaction.CustomerId))
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_CannotPayForCustomerAccountDepositWithCustomerAccountPaymentMethod, "Customer account deposit transactions cannot be tendered with the 'On Account' payment method.");
                }
            }
            /// <summary>
            /// Adds the or update reason code lines.
            /// </summary>
            /// <param name="tenderLine">The tender line.</param>
            /// <param name="cartTenderLine">The cart tender line.</param>
            /// <param name="transactionId">The transaction id.</param>
            public static void AddOrUpdateReasonCodeLinesOnTenderLine(TenderLine tenderLine, TenderLineBase cartTenderLine, string transactionId)
            {
                ThrowIf.Null(tenderLine, "tenderLine");
                ThrowIf.Null(cartTenderLine, "cartTenderLine");

                if (cartTenderLine.ReasonCodeLines != null &&
                    cartTenderLine.ReasonCodeLines.Any())
                {
                    AddOrUpdateReasonCodeLinesHelper(
                        reasonCodeLinesToUpdate: tenderLine.ReasonCodeLines,
                        reasonCodeLines: cartTenderLine.ReasonCodeLines,
                        transactionId: transactionId,
                        parentLineId: tenderLine.TenderLineId,
                        reasonCodeLineType: ReasonCodeLineType.Payment);
                }
            }