__init__.py
6.52 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from opensipkd.base.models import Departemen, User
from opensipkd.base.tools.api import auth_from_rpc, check_token_rpc, update_token, JsonRpcParameterNotFound
from pyramid_rpc.jsonrpc import jsonrpc_method
from opensipkd.pasar.models import DepartemenProduk, Produk, PartnerProduk
from opensipkd.pasar.models import ProdukCategory
from opensipkd.base.views import BaseView
@jsonrpc_method(method='get_product', endpoint='api-merchant')
def get_product(request, token, data ):
"""
Digunakan untuk mendapatkan daftar produk
:param request:
:param data:
{
product_kd: string, //optional
page:integer, //optional
length:integer, //optional
category:string, //optional
search:string //optional
}
:return: [
{
product_kd:string,
product_nm:string,
harga:integer
}
]
"""
auth_from_rpc(request)
i =0
qry = DepartemenProduk.query() \
.filter(Departemen.kode == '100000')
for dat in data:
page = 'page' in dat and dat['page'] or 1
length = 'length' in dat and dat['length'] or 5
product_kd = 'product_kd' in dat and dat['product_kd'] or None
search = 'search' in dat and dat['search'] or None
category = 'category' in dat and dat['category'] or None
if product_kd :
rst = qry.join(Produk).filter(Produk.kode == product_kd)
elif search:
rst = qry.join(Produk).filter(Produk.nama.ilike("".join(['%',search,'%' ])))
elif category:
rst = qry.join(Produk).join(ProdukCategory) \
.filter(ProdukCategory.nama.ilike("".join(['%',category,'%' ])))
else:
rst = qry
rst = rst.limit(length).offset((page-1)*length)
result = []
for row in rst.all():
result.append(dict(product_kd=row.produk.kode,
produk_nm=row.produk.nama,
harga=row.harga ))
r_data = dat
r_data.update(dict(data=result))
data[i]=r_data
i += 1
return data
@jsonrpc_method(method='get_biaya', endpoint='api-merchant')
def get_biaya(request, data, token=None):
"""
Digunakan untuk mencari methode pembayaran dan biaya layanan
:param request:
:param data:
{
biaya_kd: string,
harga:integer,
cname:string,
cid:string,
cvv:string, optional
}
:param token:
user_token
:return:
{
product_kd:string,
product_nm:string,
harga:integer
}
"""
user = auth_from_rpc(request, token)
i =0
qry = DepartemenProduk.query() \
.filter(Departemen.kode == '100000')
for dat in data:
product_kd = 'biaya_kd' in dat and dat['biaya_kd'] or None
cid = 'cid' in dat and dat['cid'] or None
if not product_kd :
raise JsonRpcParameterNotFound(message='Paramter product_kd wajib di isi')
rst = qry.join(Produk).filter(Produk.kode == product_kd)
result = []
for row in rst.all():
if row.is_cid and not cid:
raise JsonRpcParameterNotFound(message="Parameter cid wajib di isi")
if row.produk.fixed:
harga = row.harga
else:
harga = dat['harga']*row.harga
result.append(dict(biaya_kd=row.produk.kode,
produk_nm=row.produk.nama,
harga=harga))
r_data = dat
r_data.update(dict(data=result))
data[i]=r_data
i += 1
return data
@jsonrpc_method(method='inquiry', endpoint='api-merchant')
def inquiry(request, token, data ):
"""
Digunakan untuk mendapatkan daftar produk
:param request:
:param data:
{
product_kd: string, //optional
cid:string //optional
}
:param token:
user_token
:return:
{
product_kd:string,
product_nm:string,
harga:integer,
admin:integer,
discount:integer
}
"""
auth_from_rpc(request)
i =0
qry = DepartemenProduk.query() \
.filter(Departemen.kode == '100000')
dat = data and data is list and data[0] or data
for dat in data:
product_kd = 'product_kd' in dat and dat['product_kd'] or None
cid = 'cid' in dat and dat['cid'] or None
if not product_kd :
raise JsonRpcParameterNotFound(message='Paramter product_kd wajib di isi')
rst = qry.join(Produk).filter(Produk.kode == product_kd)
result = []
for row in rst.all():
if row.is_cid and not cid:
raise JsonRpcParameterNotFound(message="Parameter cid wajib di isi")
result.append(dict(product_kd=row.produk.kode,
produk_nm=row.produk.nama,
harga=row.harga ))
r_data = dat
r_data.update(dict(data=result))
data[i]=r_data
i += 1
return data
@jsonrpc_method(method='payment', endpoint='api-merchant')
def payment(request, token, data):
"""
Digunakan untuk mendapatkan daftar produk
:param request:
:param data:
{
product_kd: string,
cid:string
payment_kd: string optional
}
:param token:
user_token
:return:
{
product_kd:string,
product_nm:string,
harga:integer,
admin:integer,
discount:integer
}
"""
auth_from_rpc(request, token)
i = 0
qry = DepartemenProduk.query() \
.filter(Departemen.kode == '100000')
dat = data and data is list and data[0] or data
for dat in data:
product_kd = 'product_kd' in dat and dat['product_kd'] or None
cid = 'cid' in dat and dat['cid'] or None
if not product_kd:
raise JsonRpcParameterNotFound(message='Paramter product_kd wajib di isi')
rst = qry.join(Produk).filter(Produk.kode == product_kd)
result = []
for row in rst.all():
if row.is_cid and not cid:
raise JsonRpcParameterNotFound(message="Parameter cid wajib di isi")
result.append(dict(product_kd=row.produk.kode,
produk_nm=row.produk.nama,
harga=row.harga))
r_data = dat
r_data.update(dict(data=result))
data[i] = r_data
i += 1
return data