Li
Delete
Are you sure you want to delete this?
EasyPayModel
-
Date
-
20211007
-
Target
-
C_012
-
Title
-
toss asp.net 결제 생성 요청 코드
-
Contents
-
public partial class tossPay : System.Web.UI.Page
{
public string tel;
public string name;
public string address;
public string email;
public string totalprice;
public string barre;
protected void Page_Load(object sender, EventArgs e)
{
// 에러 Could not create SSL/TLS secure channel. 가 나서 아래 세 줄을 출처 : https://www.codeproject.com/Questions/1255767/Could-not-create-SSL-TLS-secure-channel 에서 참고하여 추가함. 추가 후 에러 없음
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
// tel = Request.QueryString["tel"];
// name = Request.QueryString["name"];
// address = Request.QueryString["address"];
// email = Request.QueryString["email"];
totalprice = Request.QueryString["totalprice"];
barre = Request.QueryString["barre"];
var url = "https://pay.toss.im/api/v2/payments";
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/json";
var data = @"{
""orderNo"":""11"",
""amount"":10000,
""amountTaxFree"":0,
""productDesc"":""테스트결제"",
""apiKey"":""sk_test_e3kWlxRR21e3kW4abL21"",
""autoExecute"":true,
""resultCallback"":""https://temp.tanz.co.kr/PaymentMethod/toss/callback.html"",
""callbackVersion"":""V2"",
""retUrl"": ""https://temp.tanz.co.kr/PaymentMethod/toss/tossOrderComplete.html"",
""retCancelUrl"": ""https://temp.tanz.co.kr/PaymentMethod/toss/tossOrderCancel.html""
}";
using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{
streamWriter.Write(data);
}
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
HttpContext.Current.Response.Write(result); // 이 값이 결제 생성 코드를 가져온다. 성공!!! 변수 result를 분해해서 asp에서처럼 리다이렉트 하면 된다.
}
//Console.WriteLine(httpResponse.StatusCode);
HttpContext.Current.Response.Write(httpResponse.StatusCode);
}
}