| import gradio as gr | |
| import requests | |
| def card_authorization(onfftid, tot_amt, com_tax_amt, com_free_amt, com_vat_amt, card_no, install_period, user_nm, user_phone2, product_nm, expire_date, cert_type, card_user_type, auth_value, password, card_nm, order_no, pay_type): | |
| url = "https://store.onoffkorea.co.kr/payment/index.php" | |
| data = { | |
| "onfftid": onfftid, | |
| "tot_amt": tot_amt, | |
| "com_tax_amt": com_tax_amt if com_tax_amt is not None else '', | |
| "com_free_amt": com_free_amt if com_free_amt is not None else '', | |
| "com_vat_amt": com_vat_amt if com_vat_amt is not None else '', | |
| "card_no": card_no, | |
| "install_period": install_period, | |
| "user_nm": user_nm, | |
| "user_phone2": user_phone2, | |
| "product_nm": product_nm, | |
| "expire_date": expire_date, | |
| "cert_type": cert_type, | |
| "card_user_type": card_user_type, | |
| "auth_value": auth_value, | |
| "password": password, | |
| "card_nm": card_nm, | |
| "order_no": order_no, | |
| "pay_type": pay_type | |
| } | |
| response = requests.post(url, data=data) | |
| if response.status_code == 200: | |
| try: | |
| return response.json() | |
| except ValueError: | |
| return {"error": "Non-JSON response", "details": response.text} | |
| else: | |
| return {"error": "Request failed", "status_code": response.status_code} | |
| with gr.Blocks() as app: | |
| with gr.Tab("์นด๋ ๊ฒฐ์ ์น์ธ ์์ฒญ"): | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| onfftid = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID", value="OFPT000000011017") | |
| tot_amt = gr.Number(label="๊ฒฐ์ ๊ธ์ก (๊ธ์ก์ ์ ๋ ฅํ์ธ์)") | |
| com_tax_amt = gr.Number(label="๊ณผ์ธ์น์ธ๊ธ์ก (ํ์์ ์ ๋ ฅ)") | |
| com_free_amt = gr.Number(label="๋น๊ณผ์ธ์น์ธ๊ธ์ก (ํ์์ ์ ๋ ฅ)") | |
| com_vat_amt = gr.Number(label="๋ถ๊ฐ์ธ (ํ์์ ์ ๋ ฅ)") | |
| card_no = gr.Textbox(label="์นด๋๋ฒํธ", placeholder="์นด๋๋ฒํธ๋ฅผ ์ ๋ ฅํ์ธ์") | |
| install_period = gr.Dropdown([str(i).zfill(2) for i in range(13)], label="ํ ๋ถ๊ธฐ๊ฐ ์ ํ", value="00") | |
| user_nm = gr.Textbox(label="๊ฒฐ์ ์๋ช ", placeholder="๊ฒฐ์ ์์ ์ด๋ฆ์ ์ ๋ ฅํ์ธ์") | |
| user_phone2 = gr.Textbox(label="๊ฒฐ์ ์ ์ฐ๋ฝ์ฒ", placeholder="์ฐ๋ฝ์ฒ๋ฅผ ์ ๋ ฅํ์ธ์") | |
| product_nm = gr.Textbox(label="์ํ๋ช ", placeholder="์ํ๋ช ์ ์ ๋ ฅํ์ธ์") | |
| expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)", placeholder="์: 2306") | |
| cert_type = gr.Radio(choices=["0 - ์ธ์ฆ", "1 - ๋น์ธ์ฆ"], label="์ธ์ฆ์ฌ๋ถ ์ ํ", value="0 - ์ธ์ฆ") | |
| card_user_type = gr.Radio(choices=["0 - ๊ฐ์ธ์นด๋", "1 - ๋ฒ์ธ์นด๋"], label="์นด๋์ ํ ์ ํ", value="0 - ๊ฐ์ธ์นด๋") | |
| auth_value = gr.Textbox(label="์ธ์ฆ๋ฒํธ", placeholder="๊ฐ์ธ์ ์ฃผ๋ฏผ๋ฒํธ ์ 6์๋ฆฌ, ๋ฒ์ธ์ ์ฌ์ ์๋ฑ๋ก๋ฒํธ") | |
| password = gr.Textbox(label="์นด๋ ๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ", placeholder="๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ") | |
| card_nm = gr.Textbox(label="์นด๋์ฌ๋ช (ํ์์ ์ ๋ ฅ)", placeholder="์นด๋์ฌ๋ช ์ ์ ๋ ฅํ์ธ์") | |
| order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ (ํ์์ ์ ๋ ฅ)", placeholder="์ฃผ๋ฌธ๋ฒํธ๋ฅผ ์ ๋ ฅํ์ธ์") | |
| pay_type = gr.Textbox(label="๊ฒฐ์ ํ์ ", value="card") | |
| submit_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ") | |
| result_area = gr.JSON(label="๊ฒฐ๊ณผ") | |
| submit_button.click( | |
| fn=card_authorization, | |
| inputs=[onfftid, tot_amt, com_tax_amt, com_free_amt, com_vat_amt, card_no, install_period, user_nm, user_phone2, product_nm, expire_date, cert_type, card_user_type, auth_value, password, card_nm, order_no, pay_type], | |
| outputs=result_area | |
| ) | |
| app.launch() |