Я создал веб-форму asp. net. Одна кнопка появляется в форме, когда я нажимаю на кнопку, мне нужно перенаправить авторизованный платежный шлюз формы переплаты с суммой, и мне нужно получить ответ с идентификатором транзакции, но я не понимаю, как перенаправить через шлюз.
Я прочитал их документ разработчика и узнал, что необходимо передать токен с URL-адресом, а для генерации токена ему нужен идентификатор профиля клиента. поэтому мне нужно понять, как создать правильный токен.
Я использую этот код для создания токена:
//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;
и для генерации идентификатора профиля клиента я использую следующий код:
// 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;
но код не работает.