/// <summary> /// This method allows you void an authorized but not captured payment. In this case a Void button will be visible on the /// order details page in admin area. Note that an order should be authorized and SupportVoid property should return true. /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); Order order = voidPaymentRequest.Order; if (int.TryParse(order.AuthorizationTransactionId, out int transactionNumber)) { PayexInterface payex = GetPayexInterface(); CancelResult cancelResult = payex.Cancel(transactionNumber).GetAwaiter().GetResult(); if (cancelResult.IsRequestSuccessful) { result.NewPaymentStatus = PaymentStatus.Voided; } else { result.AddError(cancelResult.GetErrorDescription()); } } else { result.AddError( string.Format( "The order did not contain a valid TransactionNumber in the AuthorizationTransactionId field ('{0}').", order.AuthorizationTransactionId)); } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { VoidPaymentResult result = new VoidPaymentResult(); if (ePayPaymentSettings.UseRemoteInterface) { int epayresponse = -1; try { dk.ditonlinebetalingssystem.ssl.Payment payment = new dk.ditonlinebetalingssystem.ssl.Payment(); payment.delete(Convert.ToInt32(ePayPaymentSettings.MerchantId), Convert.ToInt32(voidPaymentRequest.Order.AuthorizationTransactionId), "", ePayPaymentSettings.RemotePassword, ref epayresponse); if (epayresponse == -1) { result.NewPaymentStatus = PaymentStatus.Voided; } else { result.AddError("Could not void: epayresponse:" + epayresponse); } } catch (Exception error) { result.AddError("Could not void: " + error.Message); } } else { result.AddError("Remote interface is not activated."); } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var bpManager = new BluePayManager { AccountId = _bluePayPaymentSettings.AccountId, UserId = _bluePayPaymentSettings.UserId, SecretKey = _bluePayPaymentSettings.SecretKey, IsSandbox = _bluePayPaymentSettings.UseSandbox, MasterId = !string.IsNullOrEmpty(voidPaymentRequest.Order.AuthorizationTransactionId) ? voidPaymentRequest.Order.AuthorizationTransactionId : voidPaymentRequest.Order.CaptureTransactionId }; bpManager.Void(); if (bpManager.IsSuccessful) { result.NewPaymentStatus = PaymentStatus.Voided; } else { result.AddError(bpManager.Message); } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public Task <VoidPaymentResult> VoidAsync(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); result.AddError("Void method not supported"); return(Task.FromResult(result)); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); PrepareAuthorizeNet(); var maskedCreditCardNumberDecrypted = _encryptionService.DecryptText(voidPaymentRequest.Order.MaskedCreditCardNumber); if (String.IsNullOrEmpty(maskedCreditCardNumberDecrypted) || maskedCreditCardNumberDecrypted.Length < 4) { result.AddError("Last four digits of Credit Card Not Available"); return(result); } var lastFourDigitsCardNumber = maskedCreditCardNumberDecrypted.Substring(maskedCreditCardNumberDecrypted.Length - 4); var expirationDate = voidPaymentRequest.Order.CardExpirationMonth + voidPaymentRequest.Order.CardExpirationYear; if (!expirationDate.Any() && _authorizeNetPaymentSettings.UseSandbox) { expirationDate = DateTime.Now.ToString("MMyyyy"); } var creditCard = new creditCardType { cardNumber = lastFourDigitsCardNumber, expirationDate = expirationDate }; var codes = (string.IsNullOrEmpty(voidPaymentRequest.Order.CaptureTransactionId) ? voidPaymentRequest.Order.AuthorizationTransactionCode : voidPaymentRequest.Order.CaptureTransactionId).Split(','); var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.voidTransaction.ToString(), refTransId = codes[0], payment = new paymentType { Item = creditCard } }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the contoller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); //validate if (GetErrors(response, result.Errors)) { return(result); } result.NewPaymentStatus = PaymentStatus.Voided; return(result); }
/// <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 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; var service = GetService(); DoVoidResponseType response = service.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); }
public async Task <VoidPaymentResult> Void(PaymentTransaction paymentTransaction) { var result = new VoidPaymentResult(); result.AddError("Void method not supported"); return(await Task.FromResult(result)); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { VoidPaymentResult voidPay = new VoidPaymentResult(); voidPay.AddError("Void method not supported."); return(voidPay); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var config = new HpsServicesConfig(); config.SecretApiKey = _secureSubmitPaymentSettings.SecretApiKey; config.DeveloperId = "002914"; config.VersionNumber = "1513"; var creditService = new HpsCreditService(config); try { if (string.IsNullOrEmpty(voidPaymentRequest.Order.CaptureTransactionId)) { creditService.Void(Convert.ToInt32(voidPaymentRequest.Order.AuthorizationTransactionId)); } else { creditService.Void(Convert.ToInt32(voidPaymentRequest.Order.CaptureTransactionId)); } result.NewPaymentStatus = PaymentStatus.Voided; } catch (HpsException ex) { result.AddError(ex.Message); } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public override VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); result.AddError(_localizationService.GetResource("Common.Payment.NoVoidSupport")); return(result); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { // Cancel Autorised Payment VoidPaymentResult Vres = new VoidPaymentResult(); string lang = _workContext.WorkingLanguage.UniqueSeoCode; string trID = voidPaymentRequest.Order.AuthorizationTransactionId; Debug("start Void of:" + voidPaymentRequest.Order.OrderTotal.ToString()); // Void transaction string url = _TbcPaymentSettings.ServiceURL; string certPath = $@"{HttpContext.Current.Request.PhysicalApplicationPath}Plugins\Payments.TBCBankCard\KeyStore\{_TbcPaymentSettings.CertificatePath}"; Code.Merchant merchant = new Code.Merchant(certPath, _TbcPaymentSettings.SecretPass, url, 30000); string res = ""; Code.CommandParams param = new Code.CommandParams(lang) { trans_id = trID, amount = voidPaymentRequest.Order.OrderTotal }; try { res = merchant.SendReversal(param); } catch (Exception ex) { _logger.Error("TBC payment error - Reversal:" + ex.Message); Vres.AddError("TBC Reversal error."); return(Vres); } Code.StatusResult CheckResult = null; CheckResult = new Code.StatusResult(res); if (CheckResult.RESULT_CODE == "400") { // success Vres.NewPaymentStatus = PaymentStatus.Voided; } else { _logger.Error("TBC Reversal failed: " + res); Vres.AddError("Reversal failed: " + res); } return(Vres); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var cardknoxFacade = PrepareCardknoxFacade(); var cardknoxRequest = new CardknoxSDK.Actions.Void.Request() { RefNum = voidPaymentRequest.Order.AuthorizationTransactionId }; var response = cardknoxFacade.Void(cardknoxRequest) .GetAwaiter().GetResult(); //validate if (response == null) { return(result); } switch (response.ResponseType) { case CardknoxSDK.Infra.ResponseTypes.Accepted: result.NewPaymentStatus = PaymentStatus.Voided; break; case CardknoxSDK.Infra.ResponseTypes.Declined: result.AddError($"Payment void declined. Error code: {response.ErrorCode} - Error Message: {response.ErrorMessage}"); break; case CardknoxSDK.Infra.ResponseTypes.Error: result.AddError($"Payment void error. Error code: {response.ErrorCode} - Error Message: {response.ErrorMessage}"); break; case CardknoxSDK.Infra.ResponseTypes.Timeout: result.AddError($"Payment void timeout. Please try again. Error code: {response.ErrorCode} - Error Message: {response.ErrorMessage}"); break; case CardknoxSDK.Infra.ResponseTypes.HttpException: result.AddError($"Communication error. Please try again. Error code: {response.ErrorCode} - Error Message: {response.ErrorMessage}"); break; } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var apiPayment = new Models.PaymentOrderMechantUpdate { apiId = _manualPaymentSettings.AppId, merch_Id = _manualPaymentSettings.MerchantUniqueId, merch_orderId = voidPaymentRequest.Order.OrderGuid.ToString(), order_status = "CANCELLED" }; using (var client = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(apiPayment)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (var res = client.PostAsync(String.Format("{0}api/v1/SecurePayment/UpdateOrder", _manualPaymentSettings.AppUrl), content)) { res.Wait(); if (res.Result.IsSuccessStatusCode) { var data = res.Result.Content.ReadAsStringAsync(); var ret = JsonConvert.DeserializeObject <Models.ApiResponse>(data.Result.ToString()); switch (ret.responseCode.ToUpper()) { case "APPROVED": result.NewPaymentStatus = Core.Domain.Payments.PaymentStatus.Voided; break; default: result.AddError(ret.responseText); break; } } else { result.AddError("Unable to process your request, Please try again later."); } } } return(result); }
/// <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); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); try { var apiContext = PaypalHelper.GetApiContext(_paypalDirectPaymentSettings); var authorization = Authorization.Get(apiContext, voidPaymentRequest.Order.AuthorizationTransactionId); authorization = authorization.Void(apiContext); result.NewPaymentStatus = GetPaymentStatus(authorization.state); } catch (PayPal.PayPalException exc) { if (exc is PayPal.ConnectionException) { var error = JsonFormatter.ConvertFromJson <Error>((exc as PayPal.ConnectionException).Response); if (error != null) { result.AddError(string.Format("PayPal error: {0} ({1})", error.message, error.name)); if (error.details != null) { error.details.ForEach(x => result.AddError(string.Format("{0} {1}", x.field, x.issue))); } } } //if there are not the specific errors add exception message if (result.Success) { result.AddError(exc.InnerException != null ? exc.InnerException.Message : exc.Message); } } return(result); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var voidRequest = new VoidTransactionRequest() { Amount = (int)(Math.Round(voidPaymentRequest.Order.OrderTotal, 2) * 100), TransactionId = voidPaymentRequest.Order.AuthorizationTransactionId }; var voidResponse = _paylikeTransactionService.VoidTransaction(voidRequest); if (voidResponse.IsError) { result.AddError(voidResponse.ErrorMessage); result.AddError(voidResponse.ErrorContent); } else { result.NewPaymentStatus = PaymentStatus.Voided; } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var voidResult = _sagePayServerWorkflowService.VoidTransaction(voidPaymentRequest.Order.OrderGuid.ToString()); if (!voidResult.Success) { result.AddError(voidResult.Message); } else { result.NewPaymentStatus = PaymentStatus.Voided; } return(result); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); try { _refundService.Create(voidPaymentRequest.Order.AuthorizationTransactionId); result.NewPaymentStatus = PaymentStatus.Voided; return(result); } catch (StripeException exception) { result.AddError(!string.IsNullOrEmpty(exception.StripeError.Code) ? $"{exception.StripeError.Message} Error code: {exception.StripeError.Code}" : exception.StripeError.Message); return(result); } }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public override VoidPaymentResult Void(VoidPaymentRequest request) { var result = new VoidPaymentResult() { NewPaymentStatus = request.Order.PaymentStatus }; string transactionId = request.Order.AuthorizationTransactionId; var settings = CommonServices.Settings.LoadSetting <TSetting>(request.Order.StoreId); if (String.IsNullOrEmpty(transactionId)) { transactionId = request.Order.CaptureTransactionId; } var req = new DoVoidReq(); req.DoVoidRequest = new DoVoidRequestType(); req.DoVoidRequest.Version = PayPalHelper.GetApiVersion(); req.DoVoidRequest.AuthorizationID = transactionId; using (var service = new PayPalAPIAASoapBinding()) { service.Url = PayPalHelper.GetPaypalServiceUrl(settings); service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(settings); DoVoidResponseType response = service.DoVoid(req); string error = ""; bool success = PayPalHelper.CheckSuccess(_helper, response, out error); if (success) { result.NewPaymentStatus = PaymentStatus.Voided; //result.VoidTransactionID = response.RefundTransactionID; } else { result.AddError(error); } } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); CheckoutCancelRequest outrequest = new CheckoutCancelRequest { checkout_id = voidPaymentRequest.Order.AuthorizationTransactionId, cancel_reason = "Cancel payment for Order #" + voidPaymentRequest.Order.OrderGuid }; WebClientResponse wcresponse = ProcessWebClient(outrequest); foreach (string error in wcresponse.Errors) { result.AddError(error); } if (result.Errors.Count <= 0 && wcresponse.state == "cancelled") { result.NewPaymentStatus = PaymentStatus.Voided; } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public override VoidPaymentResult Void(VoidPaymentRequest request) { var result = new VoidPaymentResult { NewPaymentStatus = request.Order.PaymentStatus }; var settings = Services.Settings.LoadSetting <TSetting>(request.Order.StoreId); var transactionId = request.Order.AuthorizationTransactionId; if (transactionId.IsEmpty()) { transactionId = request.Order.CaptureTransactionId; } var req = new DoVoidReq(); req.DoVoidRequest = new DoVoidRequestType(); req.DoVoidRequest.Version = ApiVersion; req.DoVoidRequest.AuthorizationID = transactionId; using (var service = GetApiAaService(settings)) { var response = service.DoVoid(req); var error = ""; var success = IsSuccess(response, out error); if (success) { result.NewPaymentStatus = PaymentStatus.Voided; //result.VoidTransactionID = response.RefundTransactionID; } else { result.AddError(error); } } return(result); }
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var order = voidPaymentRequest.Order; var result = new VoidPaymentResult(); try { _klarnaCheckoutPaymentService.CancelPayment(order.AuthorizationTransactionId, order.Customer); result.NewPaymentStatus = PaymentStatus.Voided; order.OrderNotes.Add(new OrderNote { Note = string.Format(CultureInfo.CurrentCulture, "KlarnaCheckout: The payment has been voided. Reservation: {0}", order.AuthorizationTransactionId), CreatedOnUtc = DateTime.UtcNow, DisplayToCustomer = false }); _orderService.UpdateOrder(order); } catch (KlarnaCheckoutException kce) { order.OrderNotes.Add(new OrderNote { Note = "KlarnaCheckout: An error occurred when voiding the payment. See the error log for more information.", CreatedOnUtc = DateTime.UtcNow, DisplayToCustomer = false }); _orderService.UpdateOrder(order); _logger.Error(string.Format(CultureInfo.CurrentCulture, "KlarnaCheckout: Error voiding payment. Order Id: {0}; Reservation: {1}", order.Id, order.AuthorizationTransactionId), exception: kce, customer: order.Customer); result.AddError("An error occurred while voiding the order. See the error log for more information."); } return result; }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var codes = voidPaymentRequest.Order.CaptureTransactionId == null ? voidPaymentRequest.Order.AuthorizationTransactionCode.Split(',') : voidPaymentRequest.Order.CaptureTransactionId.Split(','); _httpClient.DefaultRequestHeaders.Add("developer-id", _paySafePaymentSettings.DeveloperId); _httpClient.DefaultRequestHeaders.Add("user-id", _paySafePaymentSettings.UserId); _httpClient.DefaultRequestHeaders.Add("user-api-key", _paySafePaymentSettings.UserApiKey); var json = JsonConvert.SerializeObject(new { transaction = new Dictionary <string, string> { { "action", "void" } } }); var data = new StringContent(json, Encoding.UTF8, "application/json"); try { var response = _httpClient.PutAsync($"{GetUrl()}/{codes[0]}", data).Result; var paySafeResponse = JsonConvert.DeserializeObject <PaySafeResponse>(response.Content.ReadAsStringAsync().Result); var transactionResult = paySafeResponse.Transaction; if (response.IsSuccessStatusCode) { result.NewPaymentStatus = PaymentStatus.Voided; } } catch (Exception exception) { _logger.Error("PaySafe Error", exception); result.AddError("Exception Occurred: " + exception.Message); return(result); } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var orderGuid = voidPaymentRequest.Order.OrderGuid; if (orderGuid == Guid.NewGuid()) { result.AddError("Order Unique identifier code does not exist!"); return(result); } var transx = _sagePayServerTransactionService.GetSagePayServerTransactionByVendorTxCode(orderGuid.ToString()); if (transx == null) { result.AddError(String.Format("SagePay Server vendor transaction code {0} does not exist.", orderGuid.ToString())); return(result); } var webClient = new WebClient(); var data = new NVPCodec(); data.Add("VPSProtocol", SagePayHelper.GetProtocol()); data.Add("TxType", "VOID"); data.Add("Vendor", _sagePayServerPaymentSettings.VendorName); var voidGuid = Guid.NewGuid(); data.Add("VendorTxCode", voidGuid.ToString()); data.Add("VPSTxId", transx.VPSTxId); data.Add("SecurityKey", transx.SecurityKey); data.Add("TxAuthNo", transx.TxAuthNo); var postURL = SagePayHelper.GetSageSystemUrl(_sagePayServerPaymentSettings.ConnectTo, "void"); string strResponse = string.Empty; try { Byte[] responseData = webClient.UploadValues(postURL, data); strResponse = Encoding.ASCII.GetString(responseData); } catch (WebException ex) { result.AddError(String.Format( @"Your server was unable to release this transaction with Sage Pay. Check that you do not have a firewall restricting the POST and that your server can correctly resolve the address {0}. <br/> The Status Number is: {1}<br/> The Description given is: {2}", postURL, ex.Status, ex.Message)); return(result); } if (string.IsNullOrWhiteSpace(strResponse)) { result.AddError(String.Format( @"Your server was unable to register this transaction with Sage Pay. Check that you do not have a firewall restricting the POST and that your server can correctly resolve the address {0}.", postURL)); return(result); } var strStatus = SagePayHelper.FindField("Status", strResponse); var strStatusDetail = SagePayHelper.FindField("StatusDetail", strResponse); switch (strStatus) { case "OK": result.NewPaymentStatus = PaymentStatus.Voided; break; case "MALFORMED": result.AddError(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); return(result); case "INVALID": result.AddError(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); return(result); default: result.AddError(string.Format("Error ({0}: {1})", strStatus, strStatusDetail)); return(result); } return(result); }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); var webClient = new WebClient(); var form = new NameValueCollection(); form.Add("x_login", _authorizeNetPaymentSettings.LoginId); form.Add("x_tran_key", _authorizeNetPaymentSettings.TransactionKey); form.Add("x_delim_data", "TRUE"); form.Add("x_delim_char", "|"); form.Add("x_encap_char", ""); form.Add("x_version", GetApiVersion()); form.Add("x_relay_response", "FALSE"); form.Add("x_method", "CC"); form.Add("x_currency_code", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); string[] codes = voidPaymentRequest.Order.CaptureTransactionId == null? voidPaymentRequest.Order.AuthorizationTransactionCode.Split(',') : voidPaymentRequest.Order.CaptureTransactionId.Split(','); //x_trans_id. When x_test_request (sandbox) is set to a positive response, //or when Test mode is enabled on the payment gateway, this value will be "0". form.Add("x_trans_id", codes[0]); string maskedCreditCardNumberDecrypted = _encryptionService.DecryptText(voidPaymentRequest.Order.MaskedCreditCardNumber); if (String.IsNullOrEmpty(maskedCreditCardNumberDecrypted) || maskedCreditCardNumberDecrypted.Length < 4) { result.AddError("Last four digits of Credit Card Not Available"); return(result); } var lastFourDigitsCardNumber = maskedCreditCardNumberDecrypted.Substring(maskedCreditCardNumberDecrypted.Length - 4); form.Add("x_card_num", lastFourDigitsCardNumber); // only last four digits are required for doing a credit form.Add("x_type", "VOID"); // Send Request to Authorize and Get Response var responseData = webClient.UploadValues(GetAuthorizeNetUrl(), form); var reply = Encoding.ASCII.GetString(responseData); if (!String.IsNullOrEmpty(reply)) { string[] responseFields = reply.Split('|'); switch (responseFields[0]) { case "1": result.NewPaymentStatus = PaymentStatus.Voided; break; case "2": result.AddError(string.Format("Declined ({0}: {1})", responseFields[2], responseFields[3])); break; case "3": result.AddError(string.Format("Error: {0}", reply)); break; } } else { result.AddError("Authorize.NET unknown error"); } return(result); }