Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从我的asp.net网站重定向到授权的.net支付网关的支付表单_C#_Asp.net - Fatal编程技术网

C# 如何从我的asp.net网站重定向到授权的.net支付网关的支付表单

C# 如何从我的asp.net网站重定向到授权的.net支付网关的支付表单,c#,asp.net,C#,Asp.net,我创建了一个asp.net网络表单。当我点击按钮时,表单上有一个按钮,我需要用金额重定向超额支付表单授权支付网关,并需要用交易id捕获响应,但我不知道如何通过网关重定向 我阅读了他们的开发人员文档,了解到需要通过URL传递令牌,并生成令牌,它需要客户配置文件id。因此,我需要了解如何生成适当的令牌 我正在使用此代码生成令牌: //build a path to IframeCommunicator from the calling page string communicatorPath = S

我创建了一个asp.net网络表单。当我点击按钮时,表单上有一个按钮,我需要用金额重定向超额支付表单授权支付网关,并需要用交易id捕获响应,但我不知道如何通过网关重定向

我阅读了他们的开发人员文档,了解到需要通过URL传递令牌,并生成令牌,它需要客户配置文件id。因此,我需要了解如何生成适当的令牌

我正在使用此代码生成令牌:

//build a path to IframeCommunicator from the calling page
string communicatorPath = String.Format("{0}://{1}:{2}", callingPage.Scheme, callingPage.Host, callingPage.Port);
string[] segments = callingPage.Segments;
//replace the very last entry with contentx/IframeCommunicator.html
segments[segments.GetUpperBound(0)] = "/contentx/IframeCommunicator.html";
foreach(string s in segments)
communicatorPath += s;

string requestXML = String.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
 "<getHostedProfilePageRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" +
 "<merchantAuthentication>" +
 "<name>{0}</name>" +
 "<transactionKey>{1}</transactionKey>" +
 "</merchantAuthentication>" +
 "<customerProfileId>{2}</customerProfileId>" +
 "<hostedProfileSettings>" +
 "<setting>" +
 "<settingName>hostedProfilePageBorderVisible</settingName>" +
 "<settingValue>false</settingValue>" +
 "</setting>" +
 "<setting>" +
 "<settingName>hostedProfileIFrameCommunicatorUrl</settingName>" +
 "<settingValue>{3}</settingValue>" +
 "</setting>" +
 "</hostedProfileSettings>" +
 "</getHostedProfilePageRequest>",
 "API_LOGIN_ID", "TRANSACTION_KEY", CustomerProfileId, communicatorPath);

string XMLURL = "https://apitest.authorize.net/xml/v1/request.api";
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create(XMLURL);
req.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
req.KeepAlive = false;
req.Timeout = 30000; //30 seconds
req.Method = "POST";
byte[] byte1 = null;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte1 = encoding.GetBytes(requestXML);
req.ContentType = "text/xml";
req.ContentLength = byte1.Length;
System.IO.Stream reqStream = req.GetRequestStream();
reqStream.Write(byte1, 0, byte1.Length);
reqStream.Close();

System.Net.WebResponse resp = req.GetResponse();
System.IO.Stream read = resp.GetResponseStream();
System.IO.StreamReader io = new System.IO.StreamReader(read, new System.Text.ASCIIEncoding());
string data = io.ReadToEnd();
resp.Close();

//parse out value
XmlDocument doc = new XmlDocument();
doc.LoadXml(data);
XmlNodeList m_AccessToken = doc.GetElementsByTagName("token");
return m_AccessToken[0].InnerText;
//从调用页构建到IframeCommunicator的路径
string communicatorPath=string.Format(“{0}://{1}:{2}”,callingPage.Scheme,callingPage.Host,callingPage.Port);
string[]segments=callingPage.segments;
//将最后一个条目替换为contentx/IframeCommunicator.html
段[segments.GetUpperBound(0)]=“/contentx/IframeCommunicator.html”;
foreach(段中的字符串)
通信路径+=s;
string requestXML=string.Format(“”)+
"" +
"" +
"{0}" +
"{1}" +
"" +
"{2}" +
"" +
"" +
“hostedProfilePageBorderVisible”+
“假”+
"" +
"" +
“HostedProfileFrameCommunicationorURL”+
"{3}" +
"" +
"" +
"",
“API\u登录ID”、“交易密钥”、CustomerProfileId、通信或路径);
字符串XMLURL=”https://apitest.authorize.net/xml/v1/request.api";
System.Net.HttpWebRequest req=(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(XMLURL);
req.CachePolicy=new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
req.KeepAlive=false;
请求超时=30000//30秒
请求方法=“POST”;
字节[]字节1=null;
System.Text.asciencoding encoding=新的System.Text.asciencoding();
byte1=encoding.GetBytes(requestXML);
req.ContentType=“text/xml”;
req.ContentLength=字节1.长度;
System.IO.Stream reqStream=req.GetRequestStream();
请求流写入(字节1,0,字节1.长度);
reqStream.Close();
System.Net.WebResponse resp=req.GetResponse();
System.IO.Stream read=resp.GetResponseStream();
System.IO.StreamReader IO=new System.IO.StreamReader(read,new System.Text.ascienceoding());
字符串数据=io.ReadToEnd();
分别关闭();
//解析出值
XmlDocument doc=新的XmlDocument();
doc.LoadXml(数据);
XmlNodeList m_AccessToken=doc.GetElementsByTagName(“token”);
返回m_AccessToken[0]。InnerText;
要生成客户配置文件id,我使用以下代码:

 // set whether to use the sandbox environment, or production enviornment
 ApiOperationBase < ANetApiRequest, ANetApiResponse > .RunEnvironment = AuthorizeNet.Environment.SANDBOX;

 // define the merchant information (authentication / transaction id)
 ApiOperationBase < ANetApiRequest, ANetApiResponse > .MerchantAuthentication = new merchantAuthenticationType() {

  name = ApiLoginID,
   ItemElementName = ItemChoiceType.transactionKey,
   Item = ApiTransactionKey,
 };

 //standard api call to retrieve response
 paymentType cc = new paymentType {
  Item = "Credit Card"
 };
 paymentType echeck = new paymentType {
  Item = "Credit Card"
 };

 List < customerPaymentProfileType > paymentProfileList = new List < customerPaymentProfileType > ();
 customerPaymentProfileType ccPaymentProfile = new customerPaymentProfileType();
 ccPaymentProfile.payment = cc;

 customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
 echeckPaymentProfile.payment = echeck;

 paymentProfileList.Add(ccPaymentProfile);
 paymentProfileList.Add(echeckPaymentProfile);

 List < customerAddressType > addressInfoList = new List < customerAddressType > ();
 customerAddressType homeAddress = new customerAddressType();
 homeAddress.address = "10900 NE 8th St";
 homeAddress.city = "Seattle";
 homeAddress.zip = "98006";


 customerAddressType officeAddress = new customerAddressType();
 officeAddress.address = "1200 148th AVE NE";
 officeAddress.city = "NorthBend";
 officeAddress.zip = "92101";

 addressInfoList.Add(homeAddress);
 addressInfoList.Add(officeAddress);


 customerProfileType customerProfile = new customerProfileType();
 // customerProfile.merchantCustomerId = "22";
 customerProfile.email = emailId;
 customerProfile.paymentProfiles = paymentProfileList.ToArray();
 //customerProfile.shipToList = addressInfoList.ToArray();

 var request = new createCustomerProfileRequest {
  profile = customerProfile, validationMode = validationModeEnum.none
 };

 //instantiate the controller that will call the service
 var controller = new createCustomerProfileController(request);
 controller.Execute();
 //get the response from the service (errors contained if any)
 createCustomerProfileResponse response = controller.GetApiResponse();

 // validate response 
 if (response != null) {
  if (response.messages.resultCode == messageTypeEnum.Ok) {
   if (response.messages.message != null) {

    Console.WriteLine("Customer Profile ID: " + response.customerProfileId);
    Console.WriteLine("Payment Profile ID: " + response.customerPaymentProfileIdList[0]);
    Console.WriteLine("Shipping Profile ID: " + response.customerShippingAddressIdList[0]);
   }
  } else {
   Console.WriteLine("Customer Profile Creation Failed.");
   Console.WriteLine("Error Code: " + response.messages.message[0].code);
   Console.WriteLine("Error message: " + response.messages.message[0].text);
  }
 } else {
  if (controller.GetErrorResponse().messages.message.Length > 0) {
   Console.WriteLine("Customer Profile Creation Failed.");
   Console.WriteLine("Error Code: " + response.messages.message[0].code);
   Console.WriteLine("Error message: " + response.messages.message[0].text);
  } else {
   Console.WriteLine("Null Response.");
  }
 }

 return response;
//设置是使用沙箱环境还是使用生产环境
ApiOperationBase.RunEnvironment=AuthorizeNet.Environment.SANDBOX;
//定义商户信息(身份验证/交易id)
ApiOperationBase.MerchantAuthentication=new-merchantAuthenticationType(){
名称=ApiLoginID,
ItemElementName=ItemChoiceType.transactionKey,
Item=ApiTransactionKey,
};
//检索响应的标准api调用
paymentType cc=新的paymentType{
Item=“信用卡”
};
paymentType echeck=新的paymentType{
Item=“信用卡”
};
列表paymentProfileList=新列表();
customerPaymentProfileType ccPaymentProfile=新customerPaymentProfileType();
ccPaymentProfile.payment=cc;
customerPaymentProfileType echeckPaymentProfile=新customerPaymentProfileType();
echeckPaymentProfile.payment=echeck;
paymentProfileList.Add(ccPaymentProfile);
paymentProfileList.Add(echeckPaymentProfile);
列表addressInfoList=新列表();
customerAddressType homeAddress=新customerAddressType();
homeAddress.address=“10900东北第八街”;
homeAddress.city=“西雅图”;
homeAddress.zip=“98006”;
customerAddressType officeAddress=新customerAddressType();
officeAddress.address=“东北第148大街1200号”;
officeAddress.city=“北本德”;
officeAddress.zip=“92101”;
addressInfoList.Add(家庭地址);
addressInfoList.Add(officeAddress);
customerProfileType customerProfile=新的customerProfileType();
//customerProfile.merchantCustomerId=“22”;
customerProfile.email=emailId;
customerProfile.paymentProfiles=paymentProfileList.ToArray();
//customerProfile.shipToList=addressInfoList.ToArray();
var请求=新建createCustomerProfileRequest{
profile=customerProfile,validationMode=validationModeEnum.none
};
//实例化将调用服务的控制器

var控制器=新的createCustomerProfileController(请求); controller.Execute(); //从服务获取响应(如果有错误,则包含错误) createCustomerProfileResponse=controller.GetApiResponse(); //验证响应 if(响应!=null){ if(response.messages.resultCode==messageTypeEnum.Ok){ if(response.messages.message!=null){ Console.WriteLine(“客户配置文件ID:+response.customerProfileId”); Console.WriteLine(“支付配置文件ID:+response.customerPaymentProfileIdList[0]); Console.WriteLine(“发货配置文件ID:+response.CustomerShippingAddressId[0]); } }否则{ Console.WriteLine(“客户配置文件创建失败”); Console.WriteLine(“错误代码:“+response.messages.message[0].Code”); Console.WriteLine(“错误消息:+response.messages.message[0].text”); } }否则{ if(controller.GetErrorResponse().messages.message.Length>0){ Console.WriteLine(“客户配置文件创建失败”); Console.WriteLine(“错误代码:“+response.messages.message[0].Code”); Console.WriteLine(“错误消息:+response.messages.message[0].text”); }否则{ 控制台.WriteLine(“空响应”); } } 返回响应;

但代码不起作用。

错误是在第二个方法中抛出的,我实现了第二个方法来获取客户配置文件id。它显示了生成XML时的错误。但是我不明白我做错了什么。这个问题的格式很糟糕,另外,你哈