aiqtech commited on
Commit
57feab7
ยท
verified ยท
1 Parent(s): ba1d708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -30
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
- return response.json()
32
- except ValueError:
33
- # XML ์‘๋‹ต ์ฒ˜๋ฆฌ
34
- try:
35
- root = ET.fromstring(response.text)
36
- result = {}
37
- for child in root:
38
- result[child.tag] = child.text
39
- return result
40
- except ET.ParseError:
41
- return {"error": "Invalid XML response", "details": response.text}
 
 
 
42
  else:
43
- return {"error": "Request failed", "status_code": response.status_code}
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="์นด๋“œ๋ฒˆํ˜ธ", placeholder="์นด๋“œ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")
55
- install_period = gr.Dropdown([str(i).zfill(2) for i in range(13)], label="ํ• ๋ถ€๊ธฐ๊ฐ„ ์„ ํƒ", value="00")
56
- user_nm = gr.Textbox(label="๊ฒฐ์ œ์ž๋ช…", placeholder="๊ฒฐ์ œ์ž์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”")
57
- user_phone2 = gr.Textbox(label="๊ฒฐ์ œ์ž ์—ฐ๋ฝ์ฒ˜", placeholder="์—ฐ๋ฝ์ฒ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")
58
- product_nm = gr.Textbox(label="์ƒํ’ˆ๋ช…", placeholder="์ƒํ’ˆ๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š”")
59
- expire_date = gr.Textbox(label="์œ ํšจ๊ธฐ๊ฐ„(YYMM)", placeholder="์˜ˆ: 2306")
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="์ธ์ฆ๋ฒˆํ˜ธ", placeholder="๊ฐœ์ธ์€ ์ฃผ๋ฏผ๋ฒˆํ˜ธ ์•ž 6์ž๋ฆฌ, ๋ฒ•์ธ์€ ์‚ฌ์—…์ž๋“ฑ๋ก๋ฒˆํ˜ธ")
63
- password = gr.Textbox(label="์นด๋“œ ๋น„๋ฐ€๋ฒˆํ˜ธ ์•ž 2์ž๋ฆฌ", placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์•ž 2์ž๋ฆฌ")
64
- card_nm = gr.Textbox(label="์นด๋“œ์‚ฌ๋ช… (ํ•„์š”์‹œ ์ž…๋ ฅ)", placeholder="์นด๋“œ์‚ฌ๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š”")
65
- order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒˆํ˜ธ (ํ•„์š”์‹œ ์ž…๋ ฅ)", placeholder="์ฃผ๋ฌธ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")
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("๊ฒฐ์ œ ์Šน์ธ ์š”์ฒญ")