-
Notifications
You must be signed in to change notification settings - Fork 38
/
pay.py
128 lines (112 loc) · 3.34 KB
/
pay.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = 'adison'
# @Time : 2018/12/18
def _get_pay(config):
import_me = config['pay_type']
from . import pay_type
try:
pay_obj = getattr(pay_type, import_me)
except AttributeError:
raise ImportError("%s is not a valid PAY TYPE" % (
import_me))
return pay_obj(config)
class Pay(object):
def __init__(self, config):
self.pay = _get_pay(config)
def trade_wap_pay(self, pay_order, **kwargs):
"""
手机网站支付
:param pay_order:
:param kwargs:
:return:
"""
kwargs = dict(pay_order.data, **kwargs)
return self.pay.trade_wap_pay(**kwargs)
def trade_app_pay(self, pay_order, **kwargs):
"""
APP支付
:param pay_order:
:param kwargs:
:return:
"""
kwargs = dict(pay_order.data, **kwargs)
return self.pay.trade_app_pay(**kwargs)
def trade_page_pay(self, pay_order, **kwargs):
"""
电脑网站支付
:param pay_order:
:param kwargs:
:return:
"""
kwargs = dict(pay_order.data, **kwargs)
return self.pay.trade_page_pay(**kwargs)
def trade_js_pay(self, pay_order, **kwargs):
"""
js支付
:param pay_order:
:param kwargs:
:return:
"""
from wx import WxPay
from pay_error import PayError
if not isinstance(self.pay, WxPay):
raise PayError('%s have not a valid method'.format(self.pay))
kwargs = dict(pay_order.data, **kwargs)
return self.pay.trade_js_pay(**kwargs)
def parse_and_verify_result(self, args):
"""
异步通知校验
:param args: 对应平台返回的原始数据
:return:
"""
return self.pay.verify(args)
def trade_query(self, pay_response, **kwargs):
"""
交易查询
:param pay_response:
:param kwargs:
:return:
"""
kwargs = dict(pay_response.data, **kwargs)
return self.pay.trade_query(**kwargs)
def trade_refund(self, pay_response, **kwargs):
"""
退款
:param pay_response:
:param kwargs:
:return:
"""
kwargs = dict(pay_response.data, **kwargs)
return self.pay.trade_refund(**kwargs)
def trade_refund_query(self, pay_response, **kwargs):
"""
退款查询
:param pay_response:
:param kwargs:
:return:
"""
kwargs = dict(pay_response.data, **kwargs)
return self.pay.trade_refund_query(**kwargs)
def trade_cancel(self, pay_response, **kwargs):
"""
交易取消
:param pay_response:
:param kwargs:
:return:
"""
kwargs = dict(pay_response.data, **kwargs)
return self.pay.trade_cancel(**kwargs)
def enterprise_pay(self, pay_order, **kwargs):
"""
微信企业付款到零钱
:param pay_order:
:param kwargs:
:return:
"""
kwargs = dict(pay_order.data, **kwargs)
from wx import WxPay
from pay_error import PayError
if not isinstance(self.pay, WxPay):
raise PayError('%s have not a valid method'.format(self.pay))
return self.pay.enterprise_pay(**kwargs)