Li

Delete

Are you sure you want to delete this?

EasyPayModel


Date
20211011
Target
C_025
Title
toss 결제상태확인 - tossPayStatus
Contents
결제상태확인 요청 https://temp.tanz.co.kr/paymentmethod/toss/tosspayStatus.aspx?payToken=8VXZS7ZgBdMFxxYK0kk764 결과 {"code":0,"payToken":"8VXZS7ZgBdMFxxYK0kk764","orderNo":"10102021191527","payStatus":"PAY_COMPLETE","payMethod":"TOSS_MONEY","amount":745000,"discountedAmount":0,"paidPoint":0,"paidAmount":745000,"refundableAmount":745000,"amountTaxable":677272,"amountTaxFree":0,"amountVat":67728,"amountServiceFee":0,"transactions":[{"stepType":"PAY","transactionId":"7714a262-3f93-4411-8aed-d514fdcbd838","paidAmount":745000,"transactionAmount":745000,"discountAmount":0,"pointAmount":0,"regTs":"2021-10-10 19:16:37"}],"createdTs":"2021-10-10 19:15:25","paidTs":"2021-10-10 19:16:37"} 결제 요청 curl: -payToken과 apiKey가 필요하다. curl "https://pay.toss.im/api/v2/status" \ -H "Content-Type: application/json" \ -d '{ "payToken":"example-payToken", "apiKey":"sk_test_w5lNQylNqa5lNQe013Nq" }' tossPayStatus.aspx.cs public partial class tossPayStatus : System.Web.UI.Page { public string payToken; protected void Page_Load(object sender, EventArgs e) { payToken = Request.QueryString["payToken"]; var url = "https://pay.toss.im/api/v2/status"; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.ContentType = "application/json"; var data = @"{ ""payToken"":""" + payToken + @""", //""payToken"":""example-payToken"", <<- 이런식으로 주석을 달면 에러가 발생한다. ""apiKey"":""sk_test_e3kWlxRR21e3kW4abL21"" }"; 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); } HttpContext.Current.Response.Write(httpResponse.StatusCode); } } 요청 https://temp.tanz.co.kr/paymentMethod/toss/tossPayStatus.aspx?payToken=1A5rTjpnrddupp8G3RDB2b 결과 The request was aborted: Could not create SSL/TLS secure channel. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. Source Error: Line 41: } Line 42: Line 43: var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); Line 44: using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) Line 45: { 해결 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; 추가하여 해결