__init__.py
17.4 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
import json
import base64
import logging
# Import Library (Mandatory)
from datetime import datetime, timedelta
from opensipkd.base import get_settings
from opensipkd.base.models import Partner
from . import Nicepay
from ..vendor import VendorClass
log = logging.getLogger(__name__)
# setMandatoryParameter
class Vendor(VendorClass): #VendorClass
# def __init__(self, vendor_produk, **kwargs):
# def __init__(self, vendor_produk, **kwargs):
# # VendorClass.__init__(self, vendor_produk, bill_no, **kwargs)
# if not vendor_produk or kwargs is None or not "values" in kwargs:
# return
#
# settings = get_settings()
# self.mid = 'np_mid' in settings and settings['np_mid'] or None
# self.key = 'np_key' in settings and settings['np_key'] or None
# self.url = 'np_url' in settings and settings['np_url'] or None
# Nicepay.merchantKey = self.key
# Nicepay.iMid = self.mid
#
# self.customer = dict(
# barang='GOODSNM',
# nama='BILLING NAME',
# phone='08123456789',
# email='ADETEST01@GMAIL.COM',
# kota='JAKARTA',
# provinsi='JAKARTA',
# kd_pos='14350',
# negara='INDONESIA',
# )
#
def __init__(self, vendor_produk, invoice_det, **kwargs):
VendorClass.__init__(self, vendor_produk, invoice_det=invoice_det)
# id_pel, customer_id, cust_trx, row
settings = get_settings()
self.mid = 'np_mid' in settings and settings['np_mid'] or None
self.key = 'np_key' in settings and settings['np_key'] or None
self.url = 'np_url' in settings and settings['np_url'] or None
self.callback_url = 'np_callback' in settings and settings['np_callback'] or \
'https://www.merchant.com/Notification'
self.notify_url = 'np_notify' in settings and settings['np_notify'] or \
'https://www.merchant.com/Notification'
key = ":".join([self.mid, self.key]).encode()
self.auth = base64.b64encode(key).decode()
# args = kwargs
# self.values = args["values"]
self.v_produk_kd = vendor_produk.kode
customer = self.invoice_det.customer
if customer:
self.cust_kd = customer.kode
# self.cust_inv_no = self.cust_kd + self.invoice_det.cust_inv_no
self.cust_inv_no = self.invoice_det.cust_inv_no
# self.cust_trx = 'REFERENCENO'
# self.pay_method = '01'
self.bank_cd, self.pay_method = self.v_produk_kd.split('-')
self.va_typ = None
# self.notify_url = "dev.agratek.co.id/api/np/notify"
# self.callback_url = "dev.agratek.co.id/api/np/calllback"
self.reccuring = False
self.amt = str(self.invoice_det.amt_sell)
# now = datetime.now()
# self.time_stamp = now.strftime("%Y%m%d%H%M%S")
# tommorow = now + timedelta(days=1)
# self.valid_date = tommorow.strftime("%Y%m%d")
# self.valid_time = "235500"
# self.ip = Nicepay.userIp()
def request_payment(self, response):
Nicepay.requestData={}
Nicepay.set('timeStamp', self.invoice_det.time_stamp)
Nicepay.set('referenceNo', self.cust_inv_no)
Nicepay.set('tXid', response["tXid"])
Nicepay.set('cardNo', self.invoice_det.card_no)
Nicepay.set('cardExpYymm', self.invoice_det.card_exp) # format Yymm '2012'
Nicepay.set('cardCvv', self.invoice_det.card_cvv)
Nicepay.set('recurringToken', '')
Nicepay.set('preauthToken', '')
Nicepay.set('clickPayNo', '')
Nicepay.set('dataField3', '')
Nicepay.set('clickPayToken', '')
Nicepay.set('callBackUrl', self.callback_url)
result = Nicepay.nicePayment()
return result
def set_static_params(self):
if not self.cust_inv_no:
return
Nicepay.set('timeStamp', self.invoice_det.inv_time_stamp) #
Nicepay.set('iMid', self.mid)
Nicepay.set('payMethod', self.pay_method)
Nicepay.set('currency', 'IDR')
# Nicepay.set('amt', self.amt)
Nicepay.set('referenceNo', self.cust_inv_no)
Nicepay.set('userIP', self.invoice_det.inv_cust_ip)
Nicepay.set('dbProcessUrl', self.notify_url)
# Nicepay.set('merchantKey', self.key)
Nicepay.merchantKey = self.key
Nicepay.set('merchantToken', Nicepay.merchantToken())
# Nicepay.set("userLanguage", "en-US")
Nicepay.set("userLanguage", "")
Nicepay.set('reqClientVer', '2.0')
return True
def set_billing_param(self):
if not self.invoice_det:
return
Nicepay.set('goodsNm', self.invoice_det.notes)
Nicepay.set('billingNm', self.invoice_det.inv_cust_nm)
Nicepay.set('billingPhone', self.invoice_det.inv_cust_phone)
Nicepay.set('billingEmail', self.invoice_det.inv_cust_email)
Nicepay.set('billingCity', self.invoice_det.inv_cust_city)
Nicepay.set('billingState', self.invoice_det.inv_cust_state)
Nicepay.set('billingPostCd', self.invoice_det.inv_cust_pos)
Nicepay.set('billingCountry', self.invoice_det.inv_cust_country)
Nicepay.set('amt', str(self.invoice_det.amt_sell))
Nicepay.set('billingAddr', self.invoice_det.inv_cust_addr)
Nicepay.set('description', self.invoice_det.notes)
Nicepay.set('reqDomain', self.invoice_det.domain)
Nicepay.set('reqServerIP', self.invoice_det.server_ip)
Nicepay.set('userAgent', self.invoice_det.inv_cust_agent)
Nicepay.set('userIP', self.invoice_det.inv_cust_ip)
Nicepay.set('userSessionID', self.invoice_det.inv_cust_session)
return True
def set_optional_param(self):
# pass
# setOptionalParameter
Nicepay.set('deliveryNm', self.invoice_det.delivery_nm)
Nicepay.set('deliveryPhone', self.invoice_det.delivery_phone)
Nicepay.set('deliveryAddr', self.invoice_det.delivery_addr)
Nicepay.set('deliveryCity', self.invoice_det.delivery_city)
Nicepay.set('deliveryState', self.invoice_det.delivery_state)
Nicepay.set('deliveryPostCd', self.invoice_det.delivery_pos)
Nicepay.set('deliveryCountry', self.invoice_det.delivery_country)
# print('>>> INVOICE DET:', self.invoice_det.vat, type(self.invoice_det.vat),
# self.invoice_det.fee, type(self.invoice_det.fee),
# self.invoice_det.notax_amt, type(self.invoice_det.notax_amt))
Nicepay.set('vat', self.invoice_det.vat and int(self.invoice_det.vat) > 0 and \
str(self.invoice_det.vat) or '')
Nicepay.set('fee', self.invoice_det.fee and int(self.invoice_det.fee) > 0 and \
str(self.invoice_det.fee) or '')
no_tax_amt = self.invoice_det.notax_amt and int(self.invoice_det.notax_amt) > 0 and\
str(self.invoice_det.notax_amt) or ''
Nicepay.set('notaxAmt', no_tax_amt)
# Nicepay.set('reqDt', self.invoice_det.req_dt) # Format (YYYYMMDD)
# Nicepay.set('reqTm', self.invoice_det.req_tm) # Format (HHiiss)
Nicepay.set('reqDt', '') # Format (YYYYMMDD)
Nicepay.set('reqTm', '') # Format (HHiiss)
Nicepay.set('reqClientVer', '')
Nicepay.set('instmntType', '')
Nicepay.set('instmntMon', '')
Nicepay.set('mRefNo', '')
# result dari nicepay
# Nicepay.set('tXid', '')
# Nicepay.set('transDt', '')
# Nicepay.set('transTm', '')
Nicepay.set('payValidDt', '')
Nicepay.set('payValidTm', '')
Nicepay.set('recurrOpt', '')
def register(self):
Nicepay.requestData = {}
if not self.set_billing_param() or not self.set_static_params():
return
# f9d30f6c972e2b5718751bd087b178534673a91bbac845f8a24e60e8e4abbbc5
# Nicepay.set('merchantToken', 'a20e500ecd7eb786fcda1761765ca59f344a25716ff0b576f3b42ff4ac9f7224')
data = str(json.dumps(self.invoice_det.cart))
# Nicepay.set('cartData', self.invoice_det.cart)
cart_data = data and '{}'.format(data) or '{}'
Nicepay.set('cartData', cart_data)
self.set_optional_param()
# For Credit Card (Don't forgot change payMethod to '01')
if self.pay_method == '01':
# if self.reccuring:
# # For Credit Card Reccuring Only
# Nicepay.set('recurrOpt', '2')
# cc
print('>>>> NP INIT:', self.invoice_det.to_dict())
Nicepay.set('recurrOpt', str(self.invoice_det.recurr_opt))
Nicepay.set('instmntMon', str(self.invoice_det.instmnt_mon) or '')
Nicepay.set('instmntType', str(self.invoice_det.instmnt_type) or '')
# Nicepay.set('payValidDt', self.invoice_det.pay_valid_dt or '')
# Nicepay.set('payValidTm', self.invoice_det.pay_valid_tm or '')
# Nicepay.set('mRefNo', self.invoice_det.m_ref_no or '')
# For Virtual Account (Don't forgot change payMethod to '02')
elif self.pay_method == '02':
Nicepay.set('bankCd', self.bank_cd)
# Nicepay.set('vacctValidDt', self.valid_date) # Format (YYYYMMDD)
# Nicepay.set('vacctValidTm', self.valid_time) # Format (HHiiss)
Nicepay.set('vacctValidDt', self.invoice_det.inv_valid_date)
Nicepay.set('vacctValidTm', self.invoice_det.inv_valid_time)
if self.invoice_det.inv_cust_va:
self.va_typ = 'fixed'
Nicepay.set('merFixAcctId', self.invoice_det.inv_cust_va)
Nicepay.set('vacctValidDt', '')
Nicepay.set('vacctValidTm', '')
else:
self.va_typ = 'float'
Nicepay.set('merFixAcctId', '')
elif self.pay_method in ['03', '05']:
# For CVS,ClickPay or E-Wallet
# (Don't forgot change payMethod to '03'/'04'/'05')
Nicepay.set('mitraCd', self.bank_cd)
# For CVS Only
Nicepay.set('payValidDt', self.invoice_det.inv_valid_date) # Format (YYYYMMDD)
Nicepay.set('payValidTm', self.invoice_det.inv_valid_time) # Format (HHiiss)
elif self.pay_method == '04':
Nicepay.set('mRefNo', self.cust_inv_no)
Nicepay.set('bankCd', self.bank_cd)
elif self.pay_method == '05':
Nicepay.set('mitraCd', self.bank_cd)
elif self.pay_method == '06':
Nicepay.set('recurrOpt', str(self.invoice_det.recurr_opt))
Nicepay.set('instmntMon', str(self.invoice_det.instmnt_mon) or '')
Nicepay.set('instmntType', str(self.invoice_det.instmnt_type) or '')
Nicepay.set('mitraCd', self.bank_cd)
Nicepay.set('payValidDt', self.invoice_det.inv_valid_date) # Format (YYYYMMDD)
Nicepay.set('payValidTm', self.invoice_det.inv_valid_time) # Format (HHiiss)
self.request = Nicepay.requestData
log.info("REQUEST: {}".format(json.dumps(self.request)))
self.save_log('inquiry')
result_data = Nicepay.niceRegister()
response = json.loads(result_data)
self.response = response
log.info("RESPONSE: {}".format(json.dumps(self.response)))
self.response = response
# # Payment Response String Format
if 'resultCd' not in response:
self.result = dict(
error="Connection Timeout. Please Try Again!"
)
return
else:
result = dict()
result_code = int(response['resultCd'])
result["code"] = result_code
result["message"] = response['resultMsg']
if result_code == 0: # or self.pay_method == '01':
result["currency"] = response['currency']
result["tx_id"] = response['tXid']
result['trans_dt'] = response['transDt']
result['trans_tm'] = response['transTm']
result["amount"] = response['amt']
result["invoice_no"] = response['referenceNo']
result["description"] = response['description']
# Jika kartu kredit
# if self.pay_method == '01':
# # C-Card
# # payment = self.request_payment(response)
# elif response['payMethod'] == "02":
result['pay_method'] = self.pay_method
if result['pay_method'] == "01":
result["code"] = 0
result["message"] = 'SUCCESS'
request_data = Nicepay.requestData
settings = get_settings()
call_back_url = settings['switcher_call_back_url']
result.update(dict(
time_stamp=request_data['timeStamp'],
tx_id=result['tx_id'],
merchant_token=request_data['merchantToken'],
call_back_url=call_back_url,
))
# form = """
# <input type="text" name="timeStamp" value="{time_stamp}">
# <input type="text" name="tXid" value="{tx_id}">
# <input type="text" name="merchantToken" value="{merchant_token}">
# <input type="text" name="cardNo" value="{card_no}">
# <input type="text" name="cardExpYymm" value="{card_exp_yymm}">
# <input type="text" name="cardCvv" value="{card_cvv}">
# <input type="text" name="cardHolderNm" value="{card_holder_nm}">
# <input type="text" name="callBackUrl" value="{call_back_url}">
# """.format(
# time_stamp=request_data['timeStamp'],
# tx_id=result['tx_id'],
# merchant_token=request_data['merchantToken'],
# card_no='',
# card_exp_yymm='',
# card_cvv='',
# card_holder_nm='',
# call_back_url=call_back_url,
# )
# result['form'] = form
elif response['payMethod'] == "02":
# VA
result["vacct_no"]=response['vacctNo']
result["bank_cd"]=response['bankCd']
# result["vacct_valid_dt"]=response['vacctValidDt']
# result["vacct_valid_tm"]=response['vacctValidTm']
# result["mer_fix_acct_id"]=response['merFixAcctId']
elif response['payMethod'] == "03":
# CVS
result["pay_no"]=response['payNo']
# result["pay_valid_dt"]=response['payValidDt']
# result["pay_valid_tm"]=response['payValidTm']
elif response['payMethod'] == "04":
# clickpay
result["receipt_code"]=response['receiptCode']
elif response['payMethod'] == "05":
# e-wallet
result["receipt_code"]='receiptCode' in response and response['receiptCode'] or ''
elif response['payMethod'] == "06":
# akulaku
pass
# else:
# result["resultCd"]=response['resultCd']
# result["resultMsg"]=response['resultMsg']
self.result = result
# self.save_log('inquiry')
return dict(data=result)
# https://api.nicepay.co.id/nicepay/direct/v2/registration
# Request Body
"""
{
"deliveryPhone": "62-21-0000-0000",
"mitraCd": "ALMA",
"fee": "0",
"amt": "1000",
"description": "this is test transaction!!",
"notaxAmt": "0",
"reqDomain": "localhost",
"userLanguage": "ko-KR,en-US;q=0.8,ko;q=0.6,en;q=0.4",
"vacctValidDt": "",
"billingEmail": "no-reply@ionpay.net",
"merFixAcctId": "",
"payMethod": "01",
"deliveryAddr": "Jalan Jenderal Gatot Subroto Kav.57",
"billingCountry": "ID",
"userIP": "0:0:0:0:0:0:0:1",
"instmntMon": "1",
"currency": "IDR",
"payValidDt": "",
"deliveryCity": "Jakarta",
"merchantToken": "b5149659e1a2f1271fb0833f8ea20e174b6fd389db26bc6ad036cc0dae6fa797",
"goodsNm": "T-1000",
"referenceNo": "OrdNo2017717942577",
"vat": "0",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/60.0.3112.101 Safari/537.36",
"billingState": "Jakarta",
"userSessionID": "697D6922C961070967D3BA1BA5699C2C",
"instmntType": "1",
"deliveryNm": "HongGilDong",
"deliveryPostCd": "12950",
"reqClientVer": "",
"iMid": "IONPAYTEST",
"billingNm": "HongGilDong",
"timeStamp": "20170822170942",
"dbProcessUrl": "http://127.0.0.1:8080/nicepay/test3/dbProcess.do",
"payValidTm": "",
"cartData": "{“count”: “1”,
“item”: [{“img_url”: “https://www.lecs.com/image/introduction/img_vmd020101.jpg”,
“goods_name”: “Jam Tangan Army - Strap Kulit - Hitam”,
“goods_detail”: “jumlah 1”,
“goods_amt”: “400”}]}",
"deliveryState": "Jakarta",
"deliveryCountry": "ID",
"bankCd": "",
"billingPostCd": "12950",
"billingAddr": "Jalan Jenderal Gatot Subroto Kav.57",
"reqServerIP": "172.29.2.178",
"vacctValidTm": "",
"billingPhone": "021-579-00000",
"billingCity": "Jakarta"
}
// Response Body
{
"resultCd": "0000",
"resultMsg": "SUCCESS",
"tXid": "IONPAYTEST01201708221510237472",
"referenceNo": "OrdNo2017717942577",
"payMethod": "01",
"amt": "1000",
"transDt": "20170822",
"transTm": "171029",
"description": "this is test transaction!!",
"bankCd": null,
"vacctNo": null,
"mitraCd": null,
"payNo": null
….
}
"""