File size: 4,252 Bytes
ac8e3c3
 
d9a9bca
ba1d708
 
a4cbdf0
9e93a27
 
ac8e3c3
9e93a27
b7c24d3
 
 
9e93a27
 
ac8e3c3
 
 
 
9e93a27
 
ac8e3c3
 
9e93a27
 
 
ac8e3c3
9e93a27
 
f905452
 
9e93a27
ba1d708
 
 
 
 
 
 
 
 
9e93a27
 
ac8e3c3
9e93a27
 
 
 
a4cbdf0
44857bd
b7c24d3
 
 
9e93a27
a4cbdf0
9e93a27
 
 
 
a4cbdf0
 
9e93a27
 
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
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"
    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:
            # XML ์‘๋‹ต ์ฒ˜๋ฆฌ
            try:
                root = ET.fromstring(response.text)
                result = {}
                for child in root:
                    result[child.tag] = child.text
                return result
            except ET.ParseError:
                return {"error": "Invalid XML 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()