/// <summary> /// Executes the workflow to validate tender line. /// </summary> /// <param name="request">Instance of <see cref="ValidateTenderLineForAddRequest"/>.</param> /// <returns>Instance of <see cref="NullResponse"/>.</returns> protected override NullResponse Process(ValidateTenderLineForAddRequest request) { ThrowIf.Null(request, "request"); // Get the sales transaction SalesTransaction salesTransaction = CartWorkflowHelper.LoadSalesTransaction(this.Context, request.CartId); if (salesTransaction == null) { throw new CartValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_CartNotFound, request.CartId); } var validateRequest = new ValidateTenderLineForAddServiceRequest(salesTransaction, request.TenderLine); this.Context.Execute <NullResponse>(validateRequest); return(new NullResponse()); }
/// <summary> /// Validates the tender line. /// </summary> /// <param name="request">The request.</param> /// <returns>An empty service response when validation succeeds.</returns> /// <exception cref="DataValidationException">Validation failed.</exception> private static NullResponse ValidateTenderLine(ValidateTenderLineForAddServiceRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.TenderType == null) { request.TenderType = GetTenderType(request.RequestContext, request.TenderLine.TenderTypeId); // Update tender lines with amounts and exchange rates for channel and company currencies. CalculateTenderLineCurrencyAmounts(request.TenderLine, request.RequestContext); } ValidateTenderLineLimits(request.RequestContext, request.Transaction, request.TenderLine, request.TenderType); ValidateTransactionLimits(request.Transaction, request.TenderLine, request.TenderType); return(new NullResponse()); }
/// <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); }