/// <summary> /// Release an order that was deferred /// </summary> /// <param name="orderGuid">Order guid</param> /// <param name="orderTotal">Order total</param> /// <returns></returns> public ReleaseTransactionResult ReleaseTransaction(String orderGuid, decimal orderTotal) { var result = new ReleaseTransactionResult(); var transx = _sagePayServerTransactionService.GetSagePayServerTransactionByVendorTxCode(orderGuid); if (transx == null) { result.Message = String.Format("SagePay Server vendor transaction code {0} does not exist.", orderGuid); return(result); } var webClient = new WebClient(); var data = new QueryStringNameValueCollection { { "VPSProtocol", SagePayHelper.GetProtocol() }, { "TxType", "RELEASE" }, { "Vendor", _sagePayServerPaymentSettings.VendorName }, { "VendorTxCode", orderGuid.ToString() }, { "VPSTxId", transx.VpsTxId }, { "SecurityKey", transx.SecurityKey }, { "TxAuthNo", transx.TxAuthNo }, { "ReleaseAmount", orderTotal.ToString("F2", CultureInfo.InvariantCulture) } }; var postUrl = SagePayHelper.GetSageSystemUrl(_sagePayServerPaymentSettings.ConnectTo, "release"); string strResponse; try { var responseData = webClient.UploadValues(postUrl, data); strResponse = Encoding.ASCII.GetString(responseData); } catch (WebException ex) { result.Message = (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.Message = (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.Success = true; result.Message = strStatusDetail; break; case "MALFORMED": result.Message = (string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); break; case "INVALID": result.Message = (string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); break; default: result.Message = (string.Format("Error ({0}: {1})", strStatus, strStatusDetail)); break; } return(result); }
/// <summary> /// Release an order that was deferred /// </summary> /// <param name="orderGuid">Order guid</param> /// <param name="orderTotal">Order total</param> /// <returns></returns> public ReleaseTransactionResult ReleaseTransaction(String orderGuid, decimal orderTotal) { var result = new ReleaseTransactionResult(); var transx = _sagePayServerTransactionService.GetSagePayServerTransactionByVendorTxCode(orderGuid); if (transx == null) { result.Message = String.Format("SagePay Server vendor transaction code {0} does not exist.", orderGuid); return result; } var webClient = new WebClient(); var data = new QueryStringNameValueCollection { {"VPSProtocol", SagePayHelper.GetProtocol()}, {"TxType", "RELEASE"}, {"Vendor", _sagePayServerPaymentSettings.VendorName}, {"VendorTxCode", orderGuid.ToString()}, {"VPSTxId", transx.VpsTxId}, {"SecurityKey", transx.SecurityKey}, {"TxAuthNo", transx.TxAuthNo}, { "ReleaseAmount", orderTotal.ToString("F2", CultureInfo.InvariantCulture) } }; var postUrl = SagePayHelper.GetSageSystemUrl(_sagePayServerPaymentSettings.ConnectTo, "release"); string strResponse; try { var responseData = webClient.UploadValues(postUrl, data); strResponse = Encoding.ASCII.GetString(responseData); } catch (WebException ex) { result.Message = (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.Message = (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.Success = true; result.Message = strStatusDetail; break; case "MALFORMED": result.Message = (string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); break; case "INVALID": result.Message = (string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); break; default: result.Message = (string.Format("Error ({0}: {1})", strStatus, strStatusDetail)); break; } return result; }