Li

Delete

Are you sure you want to delete this?

EasyPayModel


Date
20211011
Target
C_031
Title
kakaopay, 카카오페이 결제준비 코드와 적용 그리고 실행결과 // 테스트 CID : TC0ONETIME
Contents
결제준비 Request : kakaoPay기술문서 https://developers.kakao.com/docs/latest/ko/kakaopay/single-payment 로 부터 curl -v -X POST "https://kapi.kakao.com/v1/payment/ready" \ -H "Authorization: KakaoAK {APP_ADMIN_KEY}" \ --data-urlencode "cid=TC0ONETIME" \ --data-urlencode "partner_order_id=partner_order_id" \ --data-urlencode "partner_user_id=partner_user_id" \ --data-urlencode "item_name=초코파이" \ --data-urlencode "quantity=1" \ --data-urlencode "total_amount=2200" \ --data-urlencode "vat_amount=200" \ --data-urlencode "tax_free_amount=0" \ --data-urlencode "approval_url=https://developers.kakao.com/success" \ --data-urlencode "fail_url=https://developers.kakao.com/fail" \ --data-urlencode "cancel_url=https://developers.kakao.com/cancel" 를 토대로 아래와 같이 탄쯔사에 맞추어 curl요청을 정리하였다. 이 정리에는 -H "Authorization: KakaoAK {APP_ADMIN_KEY}" \ 부분에서 KakaoAK {APP_ADMIN_KEY} 를 쓰는 것이 관건이다. APP_ADMIN_KEY는 카카오로부터 받은 CID 로 부터 시작된다. 현재 아래 적용한 cid, TC0ONETIME는 테스트 용으로 사용된다. KakaoAK {APP_ADMIN_KEY} 는 아래와 같이 사용한다. curl -v -X POST "https://kapi.kakao.com/v1/payment/ready" \ -H "Authorization: KakaoAK 9261028b91067ae7775c5a347df58f76" \ --data-urlencode "cid=TC0ONETIME" \ --data-urlencode "partner_order_id=partner_order_id" \ --data-urlencode "partner_user_id=partner_user_id" \ --data-urlencode "item_name=초코파이" \ --data-urlencode "quantity=1" \ --data-urlencode "total_amount=2200" \ --data-urlencode "vat_amount=200" \ --data-urlencode "tax_free_amount=0" \ --data-urlencode 'approval_url=https://www.tanz.co.kr/PaymentMethod/kakaoPay' \ --data-urlencode 'fail_url=https://www.tanz.co.kr/PaymentMethod/kakaoPay' \ --data-urlencode 'cancel_url=https://www.tanz.co.kr/PaymentMethod/kakaoPay' 답변 at Mac terminal Note: Unnecessary use of -X or --request, POST is already inferred. * Trying 203.133.166.33... * TCP_NODELAY set * Connected to kapi.kakao.com (203.133.166.33) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Client hello (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Client hello (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 * ALPN, server accepted to use http/1.1 * Server certificate: * subject: C=KR; ST=Jeju-do; L=Jeju-si; O=Kakao Corp.; CN=kapi.kakao.com * start date: Sep 27 00:00:00 2021 GMT * expire date: Sep 30 23:59:59 2022 GMT * subjectAltName: host "kapi.kakao.com" matched cert's "kapi.kakao.com" * issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=Thawte TLS RSA CA G1 * SSL certificate verify ok. > POST /v1/payment/ready HTTP/1.1 > Host: kapi.kakao.com > User-Agent: curl/7.54.0 > Accept: */* > Authorization: KakaoAK 9e23f09fa2d36ff44c6acd990a7cb908 > Content-Length: 390 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 390 out of 390 bytes < HTTP/1.1 200 OK < Date: Wed, 13 Oct 2021 06:49:32 GMT < Server: Apache < Quota-Type: INC_AND_CHECK < Content-Type: application/json;charset=UTF-8 < Content-Length: 791 < * Connection #0 to host kapi.kakao.com left intact {"tid":"T2952598340618657034","tms_result":false,"next_redirect_app_url":"https://mockup-pg-web.kakao.com/v1/88b6bc8d2668587dc2085fa5891c2c3ffd8e165fad32195d25e32f5a9f3d5fb7/aInfo","next_redirect_mobile_url":"https://mockup-pg-web.kakao.com/v1/88b6bc8d2668587dc2085fa5891c2c3ffd8e165fad32195d25e32f5a9f3d5fb7/mInfo","next_redirect_pc_url":"https://mockup-pg-web.kakao.com/v1/88b6bc8d2668587dc2085fa5891c2c3ffd8e165fad32195d25e32f5a9f3d5fb7/info","android_app_scheme":"kakaotalk://kakaopay/pg?url=https://mockup-pg-web.kakao.com/v1/88b6bc8d2668587dc2085fa5891c2c3ffd8e165fad32195d25e32f5a9f3d5fb7/order","ios_app_scheme":"kakaotalk://kakaopay/pg?url=https://mockup-pg-web.kakao.com/v1/88b6bc8d2668587dc2085fa5891c2c3ffd8e165fad32195d25e32f5a9f3d5fb7/order","created_at":"2021-10-13T15:49:32"}BYUNGILs-Mac-mini:~ byungillee$ 결제준비 코드 변환 C#/.NET var url = "https://kapi.kakao.com/v1/payment/ready"; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.Headers["Authorization"] = "KakaoAK 9e23f09fa2d36ff44c6acd990a7cb908"; httpRequest.ContentType = "application/x-www-form-urlencoded"; var data = "cid=TC0ONETIME&partner_order_id=partner_order_id&partner_user_id=partner_user_id&item_name=초코파이&quantity=1&total_amount=2200&vat_amount=200&tax_free_amount=0&approval_url=https://www.tanz.co.kr/PaymentMethod/kakaoPay&fail_url=https://www.tanz.co.kr/PaymentMethod/kakaoPay&cancel_url=https://www.tanz.co.kr/PaymentMethod/kakaoPay"; 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(); } Console.WriteLine(httpResponse.StatusCode);