File size: 4,982 Bytes
ac8e3c3 ba1d708 a4cbdf0 9e93a27 57feab7 570234d 9e93a27 ac8e3c3 9e93a27 b7c24d3 9e93a27 ac8e3c3 9e93a27 ac8e3c3 57feab7 ac8e3c3 57feab7 9e93a27 f905452 57feab7 9e93a27 57feab7 ac8e3c3 9e93a27 a4cbdf0 c720614 57feab7 c720614 570234d c720614 a4cbdf0 57feab7 a4cbdf0 9e93a27 a4cbdf0 9e93a27 d9a9bca ac8e3c3 a4cbdf0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
import gradio as gr
import requests
import xml.etree.ElementTree as ET
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"
# ํ์ ํ๋ผ๋ฏธํฐ ํ์ธ
if not all([onfftid, tot_amt, card_no, install_period, user_nm, user_phone2, product_nm, expire_date, cert_type, card_user_type]):
return {"error": "ํ์ ํ๋ผ๋ฏธํฐ๊ฐ ๋๋ฝ๋์์ต๋๋ค."}
# ์ธ์ฆ ๊ด๋ จ ํ๋ผ๋ฏธํฐ ์ฒ๋ฆฌ
if cert_type == "0 - ์ธ์ฆ":
if not auth_value or not password:
return {"error": "์ธ์ฆ ๊ฒฐ์ ์ ์ธ์ฆ๋ฒํธ์ ๋น๋ฐ๋ฒํธ๋ ํ์์
๋๋ค."}
cert_type = "0"
elif cert_type == "1 - ๋น์ธ์ฆ":
cert_type = "1"
else:
return {"error": "์๋ชป๋ ์ธ์ฆ ์ ํ์
๋๋ค."}
# ์นด๋ ์ ํ ์ฒ๋ฆฌ
if card_user_type == "0 - ๊ฐ์ธ์นด๋":
card_user_type = "0"
elif card_user_type == "1 - ๋ฒ์ธ์นด๋":
card_user_type = "1"
else:
return {"error": "์๋ชป๋ ์นด๋ ์ ํ์
๋๋ค."}
# ํ ๋ถ๊ธฐ๊ฐ ์ฒ๋ฆฌ
install_period = install_period.split(' - ')[0] # "00 - ์ผ์๋ถ"์์ "00"๋ง ์ถ์ถ
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 or '',
"order_no": order_no or '',
"pay_type": pay_type or 'card'
}
response = requests.post(url, data=data)
if response.status_code == 200:
try:
root = ET.fromstring(response.text)
result = {}
for child in root:
result[child.tag] = child.text
# ๊ฒฐ๊ณผ ์ฝ๋ ํ์ธ
if result.get('result_cd') == '0000':
result['status'] = '์ฑ๊ณต'
else:
result['status'] = '์คํจ'
return result
except ET.ParseError:
return {"error": "์๋ต ํ์ฑ ์ค๋ฅ", "details": response.text}
else:
return {"error": "์์ฒญ ์คํจ", "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="์นด๋๋ฒํธ")
install_period = gr.Dropdown(
choices=[f"{str(i).zfill(2)} - {'์ผ์๋ถ' if i == 0 else f'{i}๊ฐ์'}" for i in range(13)],
label="ํ ๋ถ๊ธฐ๊ฐ ์ ํ",
value="00 - ์ผ์๋ถ"
)
user_nm = gr.Textbox(label="๊ฒฐ์ ์๋ช
")
user_phone2 = gr.Textbox(label="๊ฒฐ์ ์ ์ฐ๋ฝ์ฒ")
product_nm = gr.Textbox(label="์ํ๋ช
")
expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)")
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="์ธ์ฆ๋ฒํธ (์ธ์ฆ ์ ํ์)")
password = gr.Textbox(label="์นด๋ ๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ (์ธ์ฆ ์ ํ์)")
card_nm = gr.Textbox(label="์นด๋์ฌ๋ช
")
order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ")
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() |