public ProviderActionResult AddPaymentProvider(OrderInfo order, int paymentProviderId, string paymentProviderMethodId, ILocalization store) { if (ChangeOrderToIncompleteAndReturnTrueIfNotAllowed(order)) { return(ProviderActionResult.NotPermitted); } if (paymentProviderId == 0) { Log.Instance.LogError("AddPaymentProvider AddPaymentMethod ProviderActionResult.ProviderIdZero"); return(ProviderActionResult.ProviderIdZero); } var paymentProvider = PaymentProviderHelper.GetPaymentProvidersForOrder(order).SingleOrDefault(x => x.Id == paymentProviderId); if (paymentProvider == null) { Log.Instance.LogError("AddPaymentProvider AddPaymentMethod paymentProvider == null"); return(ProviderActionResult.NoCorrectInput); } order.PaymentInfo.Id = paymentProviderId; order.PaymentInfo.Title = paymentProvider.Title; order.PaymentInfo.PaymentType = paymentProvider.Type; var paymentMethod = paymentProvider.PaymentProviderMethods.SingleOrDefault(x => x.Id == paymentProviderMethodId); if (paymentMethod == null) { Log.Instance.LogError("AddPaymentProvider AddPaymentMethod paymentMethod == null"); return(ProviderActionResult.NoCorrectInput); } order.PaymentInfo.MethodId = paymentProviderMethodId; order.PaymentInfo.MethodTitle = paymentMethod.Title; if (paymentMethod.AmountType == PaymentProviderAmountType.Amount) { order.PaymentProviderAmount = paymentMethod.PriceInCents; } else { order.PaymentProviderOrderPercentage = paymentMethod.PriceInCents; } order.ResetDiscounts(); return(ProviderActionResult.Success); }
/// <summary> /// Returns Payment Providers for this order /// </summary> /// <returns></returns> public static List <PaymentProvider> GetPaymentProvidersForOrder(bool useCountry = true) { return(PaymentProviderHelper.GetPaymentProvidersForOrder(useCountry)); }
public List <OrderValidationError> ValidatePayment(OrderInfo orderInfo) { try { if (orderInfo == null) { throw new ArgumentNullException("orderInfo", "Geen order?!"); } if (orderInfo.PaymentInfo == null) { throw new NullReferenceException("orderInfo.PaymentInfo"); } var errors = new List <OrderValidationError>(); if (orderInfo.PaymentInfo.Id != 0) { var paymentProvider = PaymentProvider.GetPaymentProvider(orderInfo.PaymentInfo.Id); if (paymentProvider == null) { throw new NullReferenceException("paymentProvider"); } if (paymentProvider.Zones == null) { throw new NullReferenceException("paymentProvider.Zones"); } if ((paymentProvider.Type != PaymentProviderType.OfflinePaymentAtCustomer && paymentProvider.Type != PaymentProviderType.OfflinePaymentInStore) && !paymentProvider.Zones.SelectMany(x => x.CountryCodes).Contains(orderInfo.CustomerInfo.CountryCode)) { // country code for customer does not match zones for payment provider. Log.Instance.LogWarning("ORDERVALIDATIONERROR: CUSTOMER COUNTRY DOES NOT MATCH PAYMENT PROVIDER"); errors.Add(new OrderValidationError { Id = orderInfo.PaymentInfo.Id, Key = "ValidationCustomerCountryPaymentProviderMismatch", Value = "The Customer Country Does Not Match Countries Allowed For The Chosen Payment Provider" }); } errors.AddRange(PaymentProviderHelper.GetPaymentValidationResults(orderInfo).Where(e => e.Id == orderInfo.PaymentInfo.Id)); } if (orderInfo.ConfirmValidationFailed && (orderInfo.PaymentInfo.Id == 0 && PaymentProviderHelper.GetPaymentProvidersForOrder(orderInfo).Count > 0)) { Log.Instance.LogWarning("ORDERVALIDATIONERROR: PAYMENT PROVIDERS AVAILABLE BUT NOT CHOSEN"); errors.Add(new OrderValidationError { Id = 0, Key = "ValidationNoPaymentProviderChosen", Value = "No Payment Provider Chosen" }); } return(errors); } catch (Exception) { return(new List <OrderValidationError>()); } }
/// <summary> /// Returns Payment Providers for this order /// </summary> /// <returns></returns> public static List <PaymentProvider> PaymentProviders() { return(PaymentProviderHelper.GetPaymentProvidersForOrder()); }