public void Downloadable_Order_Should_Be_Processing_With_Plugin() { Order order = this.PrepareDownloadableOrderForTesting(); _orderProcessingService.CheckOrderStatus(order); Assert.AreEqual(OrderStatus.Processing, order.OrderStatus); }
/// <summary> /// Pending /// </summary> /// <param name="order">Order</param> /// <param name="authorization">Authorization</param> /// <param name="capture">Capture</param> private void MarkOrderAsPending(Core.Domain.Orders.Order order, Authorization authorization = null, Capture capture = null) { order.CaptureTransactionResult = $"{authorization?.Status ?? capture?.Status}. " + $"{authorization?.AuthorizationStatusDetails?.Reason ?? capture?.CaptureStatusDetails?.Reason}"; order.OrderStatus = OrderStatus.Pending; _orderService.UpdateOrder(order); _orderProcessingService.CheckOrderStatus(order); }
public void Downloadable_Order_Should_Be_Complete_Without_Plugin() { // verify baseline Nop behavior Order order = this.PrepareDownloadableOrderForTesting(); _originalOrderProcessingService.CheckOrderStatus(order); Assert.AreEqual(OrderStatus.Complete, order.OrderStatus); }
/// <summary> /// Update order status /// </summary> /// <param name="order">NopCommerce order object</param> /// <param name="fraudLabsProStatus">FraudLAbs Pro status</param> public void UpdateOrerStatus(NopOrder order, string fraudLabsProStatus) { switch (fraudLabsProStatus) { case Order.Action.APPROVE: order.OrderStatusId = _fraudLabsProSettings.ApproveStatusID; break; case Order.Action.REJECT: case Order.Action.REJECT_BLACKLIST: order.OrderStatusId = _fraudLabsProSettings.RejectStatusID; break; } if (!string.IsNullOrEmpty(fraudLabsProStatus)) { _orderService.UpdateOrder(order); _orderProcessingService.CheckOrderStatus(order); } }
public IActionResult QuickCheckoutWebhook() { try { //validate request var isValid = _serviceManager.ValidateWebhookRequest(Request.Form); if (!isValid) { return(BadRequest()); } var orderGuid = Guid.Parse(Request.Form["transaction_id"]); var order = _orderService.GetOrderByGuid(orderGuid); if (order == null && _serviceManager.GetPaymentFlowType() == PaymentFlowType.Inline) { //order isn't placed //try save the Skrill transaction_id for further processing if (int.TryParse(Request.Form["nop_customer_id"].ToString(), out var customerId)) { var customer = _customerService.GetCustomerById(customerId); if (customer != null) { //status 2 - payment transaction was successful if (Request.Form["status"].ToString().ToLower() == "2" && Request.Form.TryGetValue("mb_transaction_id", out var transactionId)) { _genericAttributeService.SaveAttribute(customer, Defaults.PaymentTransactionIdAttribute, transactionId.ToString()); } } } } else { if (order == null) { return(Ok()); } //add order note var details = Request.Form.Aggregate(string.Empty, (message, parameter) => $"{message}{parameter.Key}: {parameter.Value}; "); _orderService.InsertOrderNote(new OrderNote { OrderId = order.Id, Note = $"Webhook details: {Environment.NewLine}{details}", DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); //check transaction status switch (Request.Form["status"].ToString().ToLower()) { //order cancelled case "-3": case "-2": case "-1": if (Enum.TryParse <FailedReasonCode>(Request.Form["failed_reason_code"], out var failedReason)) { _orderService.InsertOrderNote(new OrderNote { OrderId = order.Id, Note = $"Order cancelled. Reason: {failedReason}", DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); } if (_orderProcessingService.CanCancelOrder(order)) { _orderProcessingService.CancelOrder(order, true); } break; //order pending case "0": order.OrderStatus = OrderStatus.Pending; _orderService.UpdateOrder(order); _orderProcessingService.CheckOrderStatus(order); break; //order processed case "2": if (_orderProcessingService.CanMarkOrderAsPaid(order)) { if (Request.Form.TryGetValue("mb_transaction_id", out var transactionId)) { order.CaptureTransactionId = transactionId; } _orderService.UpdateOrder(order); _orderProcessingService.MarkOrderAsPaid(order); } break; } } } catch { } return(Ok()); }
public ActionResult RefundNotify(FormCollection form) { if (!(_paymentPluginManager.LoadPluginBySystemName("Nop.Plugin.Payments.AliPay") is AliPayPaymentProcessor processor) || !_paymentPluginManager.IsPluginActive(processor)) { throw new NopException("插件无法加载"); } var aliPayPaymentSettings = _settingService.LoadSetting <AliPayPaymentSettings>(_storeContext.CurrentStore.Id); var partner = aliPayPaymentSettings.Partner; if (string.IsNullOrEmpty(partner)) { throw new Exception("合作身份者ID 不能为空"); } var key = aliPayPaymentSettings.Key; if (string.IsNullOrEmpty(key)) { throw new Exception("MD5密钥不能为空"); } var sellerEmail = aliPayPaymentSettings.SellerEmail; if (string.IsNullOrEmpty(sellerEmail)) { throw new Exception("卖家Email 不能为空"); } ///↓↓↓↓↓↓↓ 获取支付宝POST过来通知消息,并以“参数名 = 参数值”的形式组成数组↓↓↓↓↓↓↓↓ int i; var coll = Request.Form; var sortedStr = coll.Keys.ToList(); SortedDictionary <string, string> sPara = new SortedDictionary <string, string>(); for (i = 0; i < sortedStr.Count; i++) { sPara.Add(sortedStr[i], Request.Form[sortedStr[i]]); } ///↑↑↑↑↑↑↑ 获取支付宝POST过来通知消息,并以“参数名 = 参数值”的形式组成数组↑↑↑↑↑↑↑↑ if (sPara.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(partner: partner, key: key, input_charset: "utf-8", sign_type: sPara["sign_type"]); var notify_type = Request.Form["notify_type"]; var notify_id = Request.Form["notify_id"]; var sign = Request.Form["sign"]; bool verifyResult = aliNotify.Verify(sPara, notify_id, sign); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //批次号 string batch_no = Request.Form["batch_no"]; //批量退款数据中转账成功的笔数 string success_num = Request.Form["success_num"]; //批量退款数据中的详细信息 string result_details = Request.Form["result_details"]; //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓业务处理↓↓↓↓↓↓↓↓↓↓↓↓↓↓ try { string create_time = batch_no.Substring(0, 8); var refundInfo = _refundInfoService.GetRefundInfoByBatch_no(batch_no); if (refundInfo != null && refundInfo.OrderId > 0) { if (refundInfo.RefundStatus == RefundStatus.refund || notify_id == refundInfo.Notify_Id) { return(Content("success")); } var result_list = result_details.Split('#'); var item = result_list[0]; refundInfo.Notify_Id = notify_id; refundInfo.Notify_Type = notify_type; var obj = item.Split('^'); var out_Trade_No = obj[0]; //交易号 var AmountToRefund = decimal.Parse(obj[1]); //退款金额 var note = obj[2]; //退款说明 var order = _orderService.GetOrderById(refundInfo.OrderId); var paymentInfo = _paymentInfoService.GetByOrderId(refundInfo.OrderId); if (order != null) { if (note.ToUpper() == "SUCCESS") { if (AmountToRefund >= 0 && AmountToRefund == refundInfo.AmountToRefund) { #region 成功 order.OrderNotes.Add(new OrderNote { Note = string.Format("支付宝退款成功,退款编号:{0},退款金额:{1},交易号:{2},说明:{3}", batch_no, AmountToRefund, out_Trade_No, note), DisplayToCustomer = true, CreatedOnUtc = DateTime.UtcNow }); ////总退款 decimal totalAmountRefunded = Math.Abs(order.RefundedAmount) + AmountToRefund; order.RefundedAmount = totalAmountRefunded; if (paymentInfo.Total > order.RefundedAmount) { order.PaymentStatus = PaymentStatus.PartiallyRefunded; } else { order.PaymentStatus = PaymentStatus.Refunded; } _orderService.UpdateOrder(order); ///改变订单状态 _orderProcessingService.CheckOrderStatus(order); //修改退款记录为退款成功 refundInfo.RefundStatusId = (int)RefundStatus.refund; refundInfo.RefundOnUtc = DateTime.Now; refundInfo.Result_Details = result_details; _refundInfoService.Update(refundInfo); ///通知 var orderRefundedStoreOwnerNotificationQueuedEmailId = _workflowMessageService.SendOrderRefundedStoreOwnerNotification(order, AmountToRefund, _localizationSettings.DefaultAdminLanguageId); if (orderRefundedStoreOwnerNotificationQueuedEmailId.Count > 0 && orderRefundedStoreOwnerNotificationQueuedEmailId[0] > 0) { order.OrderNotes.Add(new OrderNote { Note = string.Format("\"订单退款\" email (to store owner) has been queued. Queued email identifier: {0}.", orderRefundedStoreOwnerNotificationQueuedEmailId), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); } var orderRefundedCustomerNotificationQueuedEmailId = _workflowMessageService.SendOrderRefundedCustomerNotification(order, AmountToRefund, order.CustomerLanguageId); if (orderRefundedCustomerNotificationQueuedEmailId.Count > 0 && orderRefundedCustomerNotificationQueuedEmailId[0] > 0) { order.OrderNotes.Add(new OrderNote { Note = string.Format("\"订单退款\" email (to customer) has been queued. Queued email identifier: {0}.", orderRefundedCustomerNotificationQueuedEmailId), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); } //已退款事件 _eventPublisher.Publish(new OrderRefundedEvent(order, AmountToRefund)); return(Content("success")); #endregion } else { #region 错误 //退款异常 refundInfo.RefundStatusId = (int)RefundStatus.error; _refundInfoService.Update(refundInfo); order.OrderNotes.Add(new OrderNote { Note = string.Format("支付宝退款异常,退款编号:{0},退款金额:{1},交易号:{2},说明:{3}", batch_no, AmountToRefund, out_Trade_No, "退款金额错误"), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); return(Content("success")); #endregion } } } } throw new Exception(string.Format("支付宝退款通知异常,退款编号:{0},退款金额:{1},交易号:{2},说明:{3}", batch_no, refundInfo.AmountToRefund, refundInfo.Out_Trade_No, "非正常处理")); } catch (Exception ex) { _logger.Error(ex.Message); return(Content("fail")); } //↑↑↑↑↑↑↑↑↑↑↑↑↑↑业务处理↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ///结束业务处理 return(Content("success"));//请不要修改或删除 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { return(Content("fail")); } } else { return(Content("无通知参数")); } return(Content("")); }
/// <summary> /// Checks order status /// </summary> /// <param name="order">Order</param> /// <returns>Validated order</returns> public void CheckOrderStatus(Order order) { _orderProcessingService.CheckOrderStatus(order); }
public IActionResult CaptureOrder([ModelBinder(typeof(JsonModelBinder <OrderCaptureDto>))] Delta <OrderCaptureDto> order) { if (order.Dto.Id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var orderCaptureRootObject = new OrdersCaptureRootObject(); Order orderToCapture = _orderApiService.GetOrderById(order.Dto.Id); if (orderToCapture == null) { return(Error(HttpStatusCode.NotFound, "order", "not found")); } var orderNote = LocalizationService.GetResource("Plugins.Api.Orders.Capture"); var captureStatus = "OK"; var sb = new StringBuilder(); var orderCaptured = false; if (order.Dto.Amount < orderToCapture.OrderTotal || order.Dto.Amount < orderToCapture.OrderTotal) { captureStatus = LocalizationService.GetResource("Plugins.Api.Orders.CaptureStatus.Error"); var messageText = $"Beløbet ({order.Dto.Amount.ToString()}) i Admind matcher ikke beløbet i webordren. Tryk på Ordredetaljer for at rette totalerne i nopShop"; orderCaptureRootObject.Messages.Add(new OrdersCaptureRootObject.Message { MessageType = "Error", MessageText = messageText }); } else { orderCaptured = _orderProcessingService.CanCapture(orderToCapture); if (orderCaptured) { orderToCapture.ShippingStatus = ShippingStatus.Shipped; var errors = _orderProcessingService.Capture(orderToCapture); if (errors.Count > 0) { orderCaptured = false; captureStatus = LocalizationService.GetResource("Plugins.Api.Orders.CaptureStatus.Error"); orderCaptureRootObject.Messages.Add(new OrdersCaptureRootObject.Message { MessageType = "Error", MessageText = $"NopCommerce capture errors: {string.Join(";", errors)}" }); orderCaptureRootObject.Captured = false; sb.AppendLine(string.Format(orderNote, captureStatus)); } else { orderCaptured = true; captureStatus = LocalizationService.GetResource("Plugins.Api.Orders.CaptureStatus.Ok"); orderCaptureRootObject.Messages.Add(new OrdersCaptureRootObject.Message { MessageType = "Info", MessageText = $"Capture succesful" }); orderCaptureRootObject.Captured = true; sb.AppendLine(string.Format(orderNote, captureStatus)); } CustomerActivityService.InsertActivity("EditOrder", LocalizationService.GetResource("ActivityLog.EditOrder"), orderToCapture); } else { captureStatus = LocalizationService.GetResource("Plugins.Api.Orders.CaptureStatus.Error"); sb.AppendLine(string.Format(orderNote, captureStatus)); orderCaptureRootObject.Messages.Add(new OrdersCaptureRootObject.Message { MessageType = "Error", MessageText = $"NopCommerce capture error. Order not capturable, check order and payment status: " }); orderCaptureRootObject.Captured = false; sb.AppendLine(LocalizationService.GetResource("Plugins.Api.Orders.CaptureStatus.CannotCapture")); } } // order note update orderToCapture.OrderNotes.Add( new OrderNote() { Note = sb.ToString(), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); this._orderService.UpdateOrder(orderToCapture); _orderProcessingService.CheckOrderStatus(orderToCapture); return(Ok(orderCaptureRootObject)); }