import gradio as gr import requests def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm, card_user_type, card_no, expire_date, auth_value, password, tot_amt): url = "https://store.onoffkorea.co.kr/fix/index.php" payload = { "onfftid": onfftid, "pay_type": pay_type, "method": method, "cert_type": cert_type, "order_no": order_no, "user_nm": user_nm, "user_phone2": user_phone2, "product_nm": product_nm, "card_user_type": card_user_type, "card_no": card_no, "expire_date": expire_date, "auth_value": auth_value, "password": password, "tot_amt": tot_amt } response = requests.post(url, data=payload) if response.status_code == 200: return response.json() else: return f"Error: {response.status_code} - {response.text}" def request_payment(onfftid, fix_key, tot_amt, card_user_type, auth_value, install_period, user_nm, user_phone2, product_nm, pay_type, method, order_no): url = "https://store.onoffkorea.co.kr/fix/index.php" payload = { "onfftid": onfftid, "fix_key": fix_key, "tot_amt": tot_amt, "card_user_type": card_user_type, "auth_value": auth_value, "install_period": install_period, "user_nm": user_nm, "user_phone2": user_phone2, "product_nm": product_nm, "pay_type": pay_type, "method": method, "order_no": order_no } response = requests.post(url, data=payload) if response.status_code == 200: return response.json() else: return f"Error: {response.status_code} - {response.text}" with gr.Blocks() as demo: gr.Markdown("# API 연동 테스트") with gr.Tab("카드 배치키 발급 요청"): onfftid = gr.Textbox(label="온오프코리아 TID") pay_type = gr.Textbox(label="결제 타입", value="fixKey") method = gr.Textbox(label="메소드", value="request") cert_type = gr.Radio(["0", "1"], label="인증 여부", value="0") order_no = gr.Textbox(label="주문번호") user_nm = gr.Textbox(label="주문자 이름") user_phone2 = gr.Textbox(label="주문자 연락처") product_nm = gr.Textbox(label="상품명") card_user_type = gr.Radio(["0", "1"], label="카드 타입", value="0") card_no = gr.Textbox(label="카드번호") expire_date = gr.Textbox(label="유효기간(YYMM)") auth_value = gr.Textbox(label="주민(사업자)등록번호") password = gr.Textbox(label="카드비밀번호 앞 2자리") tot_amt = gr.Number(label="결제금액") batch_key_button = gr.Button("배치키 발급 요청") batch_key_output = gr.JSON(label="응답 결과") batch_key_button.click( request_batch_key, inputs=[onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm, card_user_type, card_no, expire_date, auth_value, password, tot_amt], outputs=batch_key_output ) with gr.Tab("카드 배치키 결제 승인 요청"): onfftid_pay = gr.Textbox(label="온오프코리아 TID") fix_key = gr.Textbox(label="카드 배치 키") tot_amt_pay = gr.Number(label="결제금액") card_user_type_pay = gr.Radio(["0", "1"], label="카드 타입", value="0") auth_value_pay = gr.Textbox(label="주민(사업자)등록번호") install_period = gr.Dropdown(["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"], label="할부기간") user_nm_pay = gr.Textbox(label="고객명") user_phone2_pay = gr.Textbox(label="고객연락처") product_nm_pay = gr.Textbox(label="상품명") pay_type_pay = gr.Textbox(label="결제 타입", value="fixKey") method_pay = gr.Textbox(label="메소드", value="authTran") order_no_pay = gr.Textbox(label="주문번호") payment_button = gr.Button("결제 승인 요청") payment_output = gr.JSON(label="응답 결과") payment_button.click( request_payment, inputs=[onfftid_pay, fix_key, tot_amt_pay, card_user_type_pay, auth_value_pay, install_period, user_nm_pay, user_phone2_pay, product_nm_pay, pay_type_pay, method_pay, order_no_pay], outputs=payment_output ) demo.launch()