public IHttpActionResult PostProcessPayment(webModel.PaymentCallbackParameters callback) { if (callback != null && callback.Parameters != null && callback.Parameters.Any(param => param.Key == "orderid")) { var orderId = callback.Parameters.First(param => param.Key == "orderid").Value; //some payment method require customer number to be passed and returned. First search customer order by number var order = _customerOrderService.GetByOrderNumber(orderId, CustomerOrderResponseGroup.Full); //if order not found by order number search by order id if (order == null) order = _customerOrderService.GetById(orderId, CustomerOrderResponseGroup.Full); var store = _storeService.GetById(order.StoreId); var parameters = new NameValueCollection(); foreach (var param in callback.Parameters) { parameters.Add(param.Key, param.Value); } var paymentMethod = store.PaymentMethods.Where(x => x.IsActive).FirstOrDefault(x => x.ValidatePostProcessRequest(parameters).IsSuccess); if (paymentMethod != null) { var paymentOuterId = paymentMethod.ValidatePostProcessRequest(parameters).OuterId; var payment = order.InPayments.FirstOrDefault(x => string.IsNullOrEmpty(x.OuterId) || x.OuterId == paymentOuterId); if (payment == null) { throw new NullReferenceException("appropriate paymentMethod not found"); } var context = new PostProcessPaymentEvaluationContext { Order = order, Payment = payment, Store = store, OuterId = paymentOuterId, Parameters = parameters }; var retVal = paymentMethod.PostProcessPayment(context); if (retVal != null) { _customerOrderService.Update(new CustomerOrder[] { order }); } return Ok(retVal); } } return Ok(new PostProcessPaymentResult { ErrorMessage = "cancel payment" }); }
public IHttpActionResult UpdateFulfillmentCenter(webModel.FulfillmentCenter center) { var retVal = _commerceService.UpsertFulfillmentCenter(center.ToCoreModel()); return Ok(retVal); }