/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public virtual VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var paymentMethod = LoadPaymentMethodBySystemName(voidPaymentRequest.Order.PaymentMethodSystemName); if (paymentMethod == null) { throw new NasException("Payment method couldn't be loaded"); } return(paymentMethod.Void(voidPaymentRequest)); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); result.AddError("Void method not supported"); return result; }
/// <summary> /// Voids order (from admin panel) /// </summary> /// <param name="order">Order</param> /// <returns>Voided order</returns> public virtual IList<string> Void(Order order) { if (order == null) throw new ArgumentNullException("order"); if (!CanVoid(order)) throw new NasException("Cannot do void for order."); var request = new VoidPaymentRequest(); VoidPaymentResult result = null; try { request.Order = order; result = _paymentService.Void(request); if (result.Success) { //update order info order.PaymentStatus = result.NewPaymentStatus; _orderService.UpdateOrder(order); //add a note order.OrderNotes.Add(new OrderNote() { Note = "Order has been voided", DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); //check order status CheckOrderStatus(order); } } catch (Exception exc) { if (result == null) result = new VoidPaymentResult(); result.AddError(string.Format("Error: {0}. Full exception: {1}", exc.Message, exc.ToString())); } //process errors string error = ""; for (int i = 0; i < result.Errors.Count; i++) { error += string.Format("Error {0}: {1}", i, result.Errors[i]); if (i != result.Errors.Count - 1) error += ". "; } if (!String.IsNullOrEmpty(error)) { //add a note order.OrderNotes.Add(new OrderNote() { Note = string.Format("Unable to voiding order. {0}", error), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); //log it string logError = string.Format("Error voiding order #{0}. Error: {1}", order.Id, error); _logger.InsertLog(LogLevel.Error, logError, logError); } return result.Errors; }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public virtual VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var paymentMethod = LoadPaymentMethodBySystemName(voidPaymentRequest.Order.PaymentMethodSystemName); if (paymentMethod == null) throw new NasException("Payment method couldn't be loaded"); return paymentMethod.Void(voidPaymentRequest); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); string transactionId = voidPaymentRequest.Order.AuthorizationTransactionId; if (String.IsNullOrEmpty(transactionId)) transactionId = voidPaymentRequest.Order.CaptureTransactionId; var req = new DoVoidReq(); req.DoVoidRequest = new DoVoidRequestType(); req.DoVoidRequest.Version = GetApiVersion(); req.DoVoidRequest.AuthorizationID = transactionId; using (var service2 = new PayPalAPIAASoapBinding()) { if (!_paypalDirectPaymentSettings.UseSandbox) service2.Url = "https://api-3t.paypal.com/2.0/"; else service2.Url = "https://api-3t.sandbox.paypal.com/2.0/"; service2.RequesterCredentials = new CustomSecurityHeaderType(); service2.RequesterCredentials.Credentials = new UserIdPasswordType(); service2.RequesterCredentials.Credentials.Username = _paypalDirectPaymentSettings.ApiAccountName; service2.RequesterCredentials.Credentials.Password = _paypalDirectPaymentSettings.ApiAccountPassword; service2.RequesterCredentials.Credentials.Signature = _paypalDirectPaymentSettings.Signature; service2.RequesterCredentials.Credentials.Subject = ""; DoVoidResponseType response = service2.DoVoid(req); string error = ""; bool success = PaypalHelper.CheckSuccess(response, out error); if (success) { result.NewPaymentStatus = PaymentStatus.Voided; //result.VoidTransactionID = response.RefundTransactionID; } else { result.AddError(error); } } return result; }