Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
|
| 4 |
import xml.etree.ElementTree as ET
|
| 5 |
|
| 6 |
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):
|
| 7 |
url = "https://store.onoffkorea.co.kr/payment/index.php"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
data = {
|
| 9 |
"onfftid": onfftid,
|
| 10 |
"tot_amt": tot_amt,
|
|
@@ -21,48 +43,52 @@ def card_authorization(onfftid, tot_amt, com_tax_amt, com_free_amt, com_vat_amt,
|
|
| 21 |
"card_user_type": card_user_type,
|
| 22 |
"auth_value": auth_value,
|
| 23 |
"password": password,
|
| 24 |
-
"card_nm": card_nm,
|
| 25 |
-
"order_no": order_no,
|
| 26 |
-
"pay_type": pay_type
|
| 27 |
}
|
|
|
|
| 28 |
response = requests.post(url, data=data)
|
| 29 |
if response.status_code == 200:
|
| 30 |
try:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
else:
|
| 43 |
-
return {"error": "
|
| 44 |
|
| 45 |
with gr.Blocks() as app:
|
| 46 |
with gr.Tab("์นด๋ ๊ฒฐ์ ์น์ธ ์์ฒญ"):
|
| 47 |
with gr.Row():
|
| 48 |
with gr.Column(scale=1):
|
| 49 |
onfftid = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID", value="OFPT000000011017")
|
| 50 |
-
tot_amt = gr.Number(label="๊ฒฐ์ ๊ธ์ก
|
| 51 |
-
com_tax_amt = gr.Number(label="๊ณผ์ธ์น์ธ๊ธ์ก
|
| 52 |
-
com_free_amt = gr.Number(label="๋น๊ณผ์ธ์น์ธ๊ธ์ก
|
| 53 |
-
com_vat_amt = gr.Number(label="๋ถ๊ฐ์ธ
|
| 54 |
-
card_no = gr.Textbox(label="์นด๋๋ฒํธ",
|
| 55 |
-
install_period = gr.Dropdown([str(i).zfill(2) for i in range(13)], label="ํ ๋ถ๊ธฐ๊ฐ ์ ํ", value="00")
|
| 56 |
-
user_nm = gr.Textbox(label="๊ฒฐ์ ์๋ช
",
|
| 57 |
-
user_phone2 = gr.Textbox(label="๊ฒฐ์ ์ ์ฐ๋ฝ์ฒ",
|
| 58 |
-
product_nm = gr.Textbox(label="์ํ๋ช
",
|
| 59 |
-
expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)",
|
| 60 |
cert_type = gr.Radio(choices=["0 - ์ธ์ฆ", "1 - ๋น์ธ์ฆ"], label="์ธ์ฆ์ฌ๋ถ ์ ํ", value="0 - ์ธ์ฆ")
|
| 61 |
card_user_type = gr.Radio(choices=["0 - ๊ฐ์ธ์นด๋", "1 - ๋ฒ์ธ์นด๋"], label="์นด๋์ ํ ์ ํ", value="0 - ๊ฐ์ธ์นด๋")
|
| 62 |
-
auth_value = gr.Textbox(label="์ธ์ฆ๋ฒํธ
|
| 63 |
-
password = gr.Textbox(label="์นด๋ ๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ
|
| 64 |
-
card_nm = gr.Textbox(label="์นด๋์ฌ๋ช
|
| 65 |
-
order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ
|
| 66 |
pay_type = gr.Textbox(label="๊ฒฐ์ ํ์
", value="card")
|
| 67 |
|
| 68 |
submit_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import xml.etree.ElementTree as ET
|
| 4 |
|
| 5 |
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):
|
| 6 |
url = "https://store.onoffkorea.co.kr/payment/index.php"
|
| 7 |
+
|
| 8 |
+
# ํ์ ํ๋ผ๋ฏธํฐ ํ์ธ
|
| 9 |
+
if not all([onfftid, tot_amt, card_no, install_period, user_nm, user_phone2, product_nm, expire_date, cert_type, card_user_type]):
|
| 10 |
+
return {"error": "ํ์ ํ๋ผ๋ฏธํฐ๊ฐ ๋๋ฝ๋์์ต๋๋ค."}
|
| 11 |
+
|
| 12 |
+
# ์ธ์ฆ ๊ด๋ จ ํ๋ผ๋ฏธํฐ ์ฒ๋ฆฌ
|
| 13 |
+
if cert_type == "0 - ์ธ์ฆ":
|
| 14 |
+
if not auth_value or not password:
|
| 15 |
+
return {"error": "์ธ์ฆ ๊ฒฐ์ ์ ์ธ์ฆ๋ฒํธ์ ๋น๋ฐ๋ฒํธ๋ ํ์์
๋๋ค."}
|
| 16 |
+
cert_type = "0"
|
| 17 |
+
elif cert_type == "1 - ๋น์ธ์ฆ":
|
| 18 |
+
cert_type = "1"
|
| 19 |
+
else:
|
| 20 |
+
return {"error": "์๋ชป๋ ์ธ์ฆ ์ ํ์
๋๋ค."}
|
| 21 |
+
|
| 22 |
+
# ์นด๋ ์ ํ ์ฒ๋ฆฌ
|
| 23 |
+
if card_user_type == "0 - ๊ฐ์ธ์นด๋":
|
| 24 |
+
card_user_type = "0"
|
| 25 |
+
elif card_user_type == "1 - ๋ฒ์ธ์นด๋":
|
| 26 |
+
card_user_type = "1"
|
| 27 |
+
else:
|
| 28 |
+
return {"error": "์๋ชป๋ ์นด๋ ์ ํ์
๋๋ค."}
|
| 29 |
+
|
| 30 |
data = {
|
| 31 |
"onfftid": onfftid,
|
| 32 |
"tot_amt": tot_amt,
|
|
|
|
| 43 |
"card_user_type": card_user_type,
|
| 44 |
"auth_value": auth_value,
|
| 45 |
"password": password,
|
| 46 |
+
"card_nm": card_nm or '',
|
| 47 |
+
"order_no": order_no or '',
|
| 48 |
+
"pay_type": pay_type or 'card'
|
| 49 |
}
|
| 50 |
+
|
| 51 |
response = requests.post(url, data=data)
|
| 52 |
if response.status_code == 200:
|
| 53 |
try:
|
| 54 |
+
root = ET.fromstring(response.text)
|
| 55 |
+
result = {}
|
| 56 |
+
for child in root:
|
| 57 |
+
result[child.tag] = child.text
|
| 58 |
+
|
| 59 |
+
# ๊ฒฐ๊ณผ ์ฝ๋ ํ์ธ
|
| 60 |
+
if result.get('result_cd') == '0000':
|
| 61 |
+
result['status'] = '์ฑ๊ณต'
|
| 62 |
+
else:
|
| 63 |
+
result['status'] = '์คํจ'
|
| 64 |
+
|
| 65 |
+
return result
|
| 66 |
+
except ET.ParseError:
|
| 67 |
+
return {"error": "์๋ต ํ์ฑ ์ค๋ฅ", "details": response.text}
|
| 68 |
else:
|
| 69 |
+
return {"error": "์์ฒญ ์คํจ", "status_code": response.status_code}
|
| 70 |
|
| 71 |
with gr.Blocks() as app:
|
| 72 |
with gr.Tab("์นด๋ ๊ฒฐ์ ์น์ธ ์์ฒญ"):
|
| 73 |
with gr.Row():
|
| 74 |
with gr.Column(scale=1):
|
| 75 |
onfftid = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID", value="OFPT000000011017")
|
| 76 |
+
tot_amt = gr.Number(label="๊ฒฐ์ ๊ธ์ก", required=True)
|
| 77 |
+
com_tax_amt = gr.Number(label="๊ณผ์ธ์น์ธ๊ธ์ก")
|
| 78 |
+
com_free_amt = gr.Number(label="๋น๊ณผ์ธ์น์ธ๊ธ์ก")
|
| 79 |
+
com_vat_amt = gr.Number(label="๋ถ๊ฐ์ธ")
|
| 80 |
+
card_no = gr.Textbox(label="์นด๋๋ฒํธ", required=True)
|
| 81 |
+
install_period = gr.Dropdown(choices=[f"{str(i).zfill(2)} - {i if i > 0 else '์ผ์๋ถ'}๊ฐ์" for i in range(13)], label="ํ ๋ถ๊ธฐ๊ฐ ์ ํ", value="00 - ์ผ์๋ถ")
|
| 82 |
+
user_nm = gr.Textbox(label="๊ฒฐ์ ์๋ช
", required=True)
|
| 83 |
+
user_phone2 = gr.Textbox(label="๊ฒฐ์ ์ ์ฐ๋ฝ์ฒ", required=True)
|
| 84 |
+
product_nm = gr.Textbox(label="์ํ๋ช
", required=True)
|
| 85 |
+
expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)", required=True)
|
| 86 |
cert_type = gr.Radio(choices=["0 - ์ธ์ฆ", "1 - ๋น์ธ์ฆ"], label="์ธ์ฆ์ฌ๋ถ ์ ํ", value="0 - ์ธ์ฆ")
|
| 87 |
card_user_type = gr.Radio(choices=["0 - ๊ฐ์ธ์นด๋", "1 - ๋ฒ์ธ์นด๋"], label="์นด๋์ ํ ์ ํ", value="0 - ๊ฐ์ธ์นด๋")
|
| 88 |
+
auth_value = gr.Textbox(label="์ธ์ฆ๋ฒํธ (์ธ์ฆ ์ ํ์)")
|
| 89 |
+
password = gr.Textbox(label="์นด๋ ๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ (์ธ์ฆ ์ ํ์)")
|
| 90 |
+
card_nm = gr.Textbox(label="์นด๋์ฌ๋ช
")
|
| 91 |
+
order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ")
|
| 92 |
pay_type = gr.Textbox(label="๊ฒฐ์ ํ์
", value="card")
|
| 93 |
|
| 94 |
submit_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ")
|