/// <summary>
            /// Authorizes the payment.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the authorized tender line.</returns>
            private static AuthorizePaymentServiceResponse AuthorizePayment(AuthorizePaymentServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                TenderType tenderType = GetTenderType(request.RequestContext, request.TenderLine.TenderTypeId);

                // Resolve payment service.
                IRequestHandler paymentService = ResolvePaymentService(request.RequestContext, request.GetType(), request.TenderLine.TenderTypeId);

                // Calculate amount to be authorized (some tender type like currency and credit memo do not have amount set on tender line).
                CalculatePaymentAmountServiceRequest  calculateAmountRequest  = new CalculatePaymentAmountServiceRequest(request.TenderLine);
                CalculatePaymentAmountServiceResponse calculateAmountResponse = request.RequestContext.Execute <CalculatePaymentAmountServiceResponse>(calculateAmountRequest, paymentService);

                request.TenderLine = calculateAmountResponse.TenderLine;

                if (!request.TenderLine.IsPreProcessed)
                {
                    request.TenderLine.Amount = RoundAmountByTenderType(request.RequestContext, request.TenderLine.TenderTypeId, request.TenderLine.Amount, isChange: false);
                }

                // Update tender lines with amounts and exchange rates for channel and company currencies.
                CalculateTenderLineCurrencyAmounts(request.TenderLine, request.RequestContext);

                if (request.TenderLine.Amount == 0)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidAmount, "An amount of zero is not allowed on the tenderline.");
                }

                // Do amount validation.
                if (!request.SkipLimitValidation)
                {
                    var validateRequest = new ValidateTenderLineForAddServiceRequest(request.Transaction, request.TenderLine, tenderType);
                    request.RequestContext.Execute <NullResponse>(validateRequest);
                }

                // Check tender line status
                AuthorizePaymentServiceResponse response;

                if (request.TenderLine.Status == TenderLineStatus.PendingCommit ||
                    request.TenderLine.Status == TenderLineStatus.Committed ||
                    request.TenderLine.Status == TenderLineStatus.Voided)
                {
                    // Return the tender line directly if already authorized
                    response = new AuthorizePaymentServiceResponse(request.TenderLine);
                }
                else
                {
                    // Process authorization.
                    response = request.RequestContext.Execute <AuthorizePaymentServiceResponse>(request, paymentService);
                }

                // If we have cashback amount set on the tender line, we add it to the amount on the tender line after authorization
                // and set the cashback amount on the tender line to 0. This is because we do not cashback field in the
                // RetailTransactionPaymentTrans table. We are doing this at this point to mimic EPOS.
                if (response.TenderLine.CashBackAmount != 0)
                {
                    CalculateAmountsWithCashBack(response.TenderLine, request.RequestContext);
                }

                return(response);
            }
            /// <summary>
            /// Calculate amount to do be paid.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the updated tender line.</returns>
            private static CalculatePaymentAmountServiceResponse CalculatePaymentAmount(CalculatePaymentAmountServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                // All currency calculations are handled by PaymentManagerService.
                return(new CalculatePaymentAmountServiceResponse(request.TenderLine));
            }
Beispiel #3
0
            /// <summary>
            /// Calculate amount to do be paid.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the updated tender line.</returns>
            private static CalculatePaymentAmountServiceResponse CalculatePaymentAmount(CalculatePaymentAmountServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                // no calculation required.
                return(new CalculatePaymentAmountServiceResponse(request.TenderLine));
            }
            /// <summary>
            /// Calculate amount to do be paid.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the updated tender line.</returns>
            private static CalculatePaymentAmountServiceResponse CalculatePaymentAmount(CalculatePaymentAmountServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                if (request.TenderLine.Amount > 0)
                {
                    throw new PaymentException(PaymentErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidPaymentRequest, "Amount cannot be specified when paying with credit memo. Only full credit memo amount can be used by setting amount to zero.");
                }

                // for refunds amount is provided by client and doesn't have to be calculated
                if (request.TenderLine.Amount == 0)
                {
                    CreditMemo creditMemo = GetCreditMemo(request.RequestContext, request.TenderLine.CreditMemoId);
                    request.TenderLine.Amount = creditMemo.Balance; // set tender line amount to credit memo
                }

                return(new CalculatePaymentAmountServiceResponse(request.TenderLine));
            }