/// <summary> /// Gets the change. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A response containing the change tender line. /// </returns> private static GetChangePaymentServiceResponse GetChange(GetChangePaymentServiceRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (string.IsNullOrWhiteSpace(request.ChangeTenderTypeId)) { throw new PaymentException(PaymentErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidPaymentRequest, "request.TenderTypeId is null or empty."); } var changeTenderLine = new TenderLine { Amount = decimal.Negate(request.ChangeAmount), // change tender line must have negative amount Currency = request.CurrencyCode, TenderLineId = Guid.NewGuid().ToString("N"), TenderTypeId = request.ChangeTenderTypeId, Status = TenderLineStatus.Committed, IsVoidable = true, IsChangeLine = true }; return(new GetChangePaymentServiceResponse(changeTenderLine)); }
/// <summary> /// Gets the change. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A response containing the change tender line. /// </returns> private static GetChangePaymentServiceResponse GetChange(GetChangePaymentServiceRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.ChangeTenderTypeId == null) { throw new ArgumentException("request.TenderType is null", "request"); } string creditMemoId = IssueCreditMemo(request.RequestContext, request.ChangeAmount, request.CurrencyCode, request.Transaction.Id, request.Transaction.ReceiptId); var changeTenderLine = new TenderLine { CreditMemoId = creditMemoId, Amount = decimal.Negate(request.ChangeAmount), // change tender line must have negative amount Currency = request.CurrencyCode, TenderLineId = Guid.NewGuid().ToString("N"), TenderTypeId = request.ChangeTenderTypeId, Status = TenderLineStatus.Committed, IsVoidable = false, IsChangeLine = true }; return(new GetChangePaymentServiceResponse(changeTenderLine)); }
/// <summary> /// Gets the change. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A response containing the change tender line. /// </returns> private static GetChangePaymentServiceResponse GetChange(GetChangePaymentServiceRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (string.IsNullOrWhiteSpace(request.PaymentTenderTypeId)) { throw new PaymentException(PaymentErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidPaymentRequest, "request.TenderTypeId is null or empty."); } TenderType overtenderTenderType = GetTenderType(request.RequestContext, request.PaymentTenderTypeId); if (overtenderTenderType == null) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, string.Format("Tender type with id '{0}' not found", request.PaymentTenderTypeId)); } string changeTenderTypeId; if (overtenderTenderType.AboveMinimumChangeAmount != decimal.Zero && Math.Abs(request.ChangeAmount) > Math.Abs(overtenderTenderType.AboveMinimumChangeAmount) && !string.IsNullOrWhiteSpace(overtenderTenderType.AboveMinimumChangeTenderTypeId)) { // Use "above minimum change tender type" if amount exceeds configured value. changeTenderTypeId = overtenderTenderType.AboveMinimumChangeTenderTypeId; } else { changeTenderTypeId = overtenderTenderType.ChangeTenderTypeId; } if (string.IsNullOrWhiteSpace(changeTenderTypeId)) { // If change tender type is not configured using tender type of last payment (ePOS behavior) changeTenderTypeId = overtenderTenderType.TenderTypeId; } TenderType changeTenderType = GetTenderType(request.RequestContext, changeTenderTypeId); if (changeTenderType == null) { // If change tender type is not configured using tender type of last payment (ePOS behavior) changeTenderType = overtenderTenderType; } request.ChangeTenderTypeId = changeTenderType.TenderTypeId; // Round change amount. request.ChangeAmount = RoundAmountByTenderType(request.RequestContext, request.ChangeTenderTypeId, request.ChangeAmount, isChange: true); IRequestHandler paymentService = ResolvePaymentService(request.RequestContext, request.GetType(), request.ChangeTenderTypeId); GetChangePaymentServiceResponse response = request.RequestContext.Runtime.Execute <GetChangePaymentServiceResponse>(request, request.RequestContext, paymentService); // Update tender lines with amounts and exchange rates for channel and company currencies. CalculateTenderLineCurrencyAmounts(response.TenderLine, request.RequestContext); return(response); }
/// <summary> /// Gets the change. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A response containing the change tender line. /// </returns> private static GetChangePaymentServiceResponse GetChange(GetChangePaymentServiceRequest request) { // Change cannot be given to customer account. throw new FeatureNotSupportedException(FeatureNotSupportedErrors.Microsoft_Dynamics_Commerce_Runtime_ChangeTenderTypeNotSupported, string.Format(CultureInfo.InvariantCulture, "Request '{0}' is not supported. Verify change tender type settings.", request.GetType())); }
/// <summary> /// Gets the change. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A response containing the change tender line. /// </returns> private static GetChangePaymentServiceResponse GetChange(GetChangePaymentServiceRequest request) { // Change cannot be given in loyalty cards because loyalty card balance is meansured using loyalty points. throw new FeatureNotSupportedException(FeatureNotSupportedErrors.Microsoft_Dynamics_Commerce_Runtime_ChangeTenderTypeNotSupported, string.Format(CultureInfo.InvariantCulture, "Request '{0}' is not supported.", request.GetType())); }
/// <summary> /// Gets the change. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A response containing the change tender line. /// </returns> private static GetChangePaymentServiceResponse GetChange(GetChangePaymentServiceRequest request) { // Change cannot be given in gift cards because it requires manual card number input. throw new FeatureNotSupportedException(FeatureNotSupportedErrors.Microsoft_Dynamics_Commerce_Runtime_ChangeTenderTypeNotSupported, string.Format("Request '{0}' is not supported. Verify change tender type settings.", request.GetType())); }