def checkBalance(self, params): if len(params) != 0: if "TOKEN" in params: wrapData = params['DATA'] splitData = wrapData.split(".") data = helper.decrypt(splitData[0], globalVariable.key, splitData[1]) newStr = re.match("(.*?)}", data).group() newStr= json.loads(newStr) no_rekening = newStr.get("no_rekening") token = newStr.get("token") tokenStatus = Authentication.checkValidToken(self, params['TOKEN']) if tokenStatus[0]["status"] == "success": now = datetime.datetime.now() month = now.month year = now.year sql = 'SELECT no_rekening, SUM(IF(transaction_type="K", balance, 0)) as K, SUM(IF(transaction_type="D", balance, 0)) as D, (SUM(IF(transaction_type="K", balance, 0))-SUM(IF(transaction_type="D", balance, 0))) as saldo, created_date FROM db_kmpay.tbl_transaksi WHERE MONTH(created_date)= %s and YEAR(created_date)=%s AND no_rekening = %s AND status_transaksi = "SUCCESS" GROUP BY no_rekening, MONTH(created_date), YEAR(created_date);' cursorKmPay.execute(sql,([month], [year],[no_rekening])) result = cursorKmPay.fetchall() items = [] for row in result: items.append({'sum_kredit': row[1], 'sum_debit': row[2], 'saldo': row[3]}) if not items: return {'status ':"success",'code': 204, "result":items} else: return {'status ':"success",'code': 200, "result":items[0]} else: return tokenStatus[0] else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def checkTransactionByPeriod(self, param): if len(param) != 0: if "TOKEN" in param: wrapData = param['DATA'] splitData = wrapData.split(".") data = helper.decrypt(splitData[0], globalVariable.key, splitData[1]) newStr = re.match("(.*?)}", data).group() newStr= json.loads(newStr) no_rekening = newStr.get("no_rekening") start_period = newStr.get("start_period") end_period = newStr.get("end_period") tokenStatus = Authentication.checkValidToken(self, param['TOKEN']) if tokenStatus[0]["status"] == "success": sql = 'SELECT transaksi_id, transaction_type, description, balance, created_date, status_transaksi FROM tbl_transaksi WHERE no_rekening = %s AND created_date BETWEEN %s AND %s;' cursorKmPay.execute(sql,([no_rekening], [start_period], [end_period])) result = cursorKmPay.fetchall() items = [] for row in result: transaction_date = row[4].strftime('%d-%m-%Y') items.append({'id': row[0], 'transaction_type': row[1], 'description': row[2], 'balance': row[3], 'transaction_date': transaction_date, 'transaction_status':row[5]}) return {'status':'success','code': 200, 'result ': items} else: return tokenStatus else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def topupSaldo(self, param): # insertTblLog = 'INSERT INTO tbl_log_topup topup_id, no_rekening, bank_from, bank_to, balance, status, created_date VALUES (%s, %s, %s, %s, %s, %s, %s, %s)' if len(param) != 0: if "TOKEN" in param: now = datetime.datetime.now() wrapData = param['DATA'] splitData = wrapData.split(".") data = helper.decrypt(splitData[0], globalVariable.key, splitData[1]) newStr = re.match("(.*?)}", data).group() newStr = json.loads(newStr) no_rekening = newStr.get("no_rekening") tokenStatus = Authentication.checkValidToken(self, param['TOKEN']) if tokenStatus[0]["status"] == "success": member_id = getMemberIdbyBankAcc(self, no_rekening) domain = helper.getPrefixDomain(self, newStr.get("domain")) order_number = generateOrderNumber(self, domain['alias']) insertTblTopup = 'INSERT INTO tbl_topup (member_id, order_number, payment_type, total_payment, transaction_time, transaction_status, status_message, created_date, created_by) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)' cursorKmPay.execute(insertTblTopup, ([member_id], [order_number], [globalVariable.payment_type], [newStr.get("amount")], [now], [globalVariable.transaction_status], [globalVariable.topup_status_message], [now], [globalVariable.create_by])) connectKmPay.commit() # INSERT transaksi tabel # insertTblTransaksi = 'INSERT INTO tbl_transaksi (no_rekening, transaction_type, point_type, description, balance, transaksi_date, status_transaksi, created_date, created_by) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)' # a.execute(insertTblTopup, ([no_rekening], ["K"], ['TOPUP'], ["description"], [newStr.get("balance")], [now], ['SUCCESS'], [now], ['1'])) # conn.commit() else: return tokenStatus else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def post(self): param = request.get_json() if param["CMD"]: if param['CMD'] == "CB": return kmPay.checkBalance(self, param) elif param['CMD'] == "RA": return kmPay.registerAccount(self, param) elif param['CMD'] == "TS": return kmPay.topupSaldo(self, param) elif param['CMD'] == 'WS': return kmPay.withdrawSaldo(self, param) elif param['CMD'] == 'WTS': return kmPay.withdrawTypeSaldo(self, param) elif param['CMD'] == 'CT': return kmPay.checkTransaction(self, param) elif param['CMD'] == 'CTP': return kmPay.checkTransactionByPeriod(self, param) elif param['CMD'] == 'PIN': return kmPay.generatePIN(self, param) elif param == None: return jsonify({ 'status': "error", 'response_code': 401, "result": {} }) else: return jsonify({ 'status': "error", 'response_code': 400, "result": {} }) else: return generalNotification.DataNotAvailable(self)
def createCart(self, param): if len(param) != 0: if "TOKEN" in param: wrapData = param['DATA'] splitData = wrapData.split(".") data = helper.decrypt(splitData[0], globalVariable.key, splitData[1]) data = data.replace("\x08", "") newStr = json.loads(data) member_id = newStr["member_id"] cart_items = newStr["cart_items"] for item in cart_items: qty = item["quantity"] product_detail_id = item["product_detail_id"] subTotal = calculatePriceProductByQty(self, product_detail_id, qty) createCartSql = 'INSERT INTO tbl_cart (member_id, product_detail_id, quantity, price, created_date, created_by) VALUES (%s, %s, %s, %s, %s, %s);' cursorKmStore.execute(createCartSql, ([member_id], [ product_detail_id ], [qty], [subTotal], [now], [globalVariable.create_by])) connectKmStore.commit() else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def withdrawSaldo(self, param): if len(param) != 0: if "TOKEN" in param: wrapData = param['DATA'] splitData = wrapData.split(".") data = helper.decrypt(splitData[0], globalVariable.key, splitData[1]) newStr = re.match("(.*?)}", data).group() newStr= json.loads(newStr) no_rekening = newStr.get("no_rekening") type = newStr.get("type") domain = newStr.get("domain") amount = newStr.get("amount") tokenStatus = Authentication.checkValidToken(self, param['TOKEN']) prefix = helper.getPrefixDomain(self, domain) prefix = prefix['prefix_domain'] withdrawNumber = generateWithdrawNumber(self, prefix) withdraw_pin = generatePIN(self) if tokenStatus[0]["status"] == "success" and pinStatus["code"] == 200 : balance = checkBalance(self, param) if balance["result"] != []: lastCredit = balance["result"]["saldo"] saldo = int(lastCredit) - int(amount) if saldo >= 0: withdrawSql = 'INSERT INTO tbl_withdraw (no_rekening, withdraw_number, withdraw_pin, balance, type, status, created_date, created_by) VALUES (%s, %s, %s, %s, %s, %s, %s);' cursorKmPay.execute(withdrawSql, ([no_rekening], [withdrawNumber], [withdraw_pin], [amount], [type], ["PENDING"], [now], [globalVariable.create_by])) connectKmPay.commit() # withdrawSql = 'INSERT INTO tbl_transaksi (no_rekening, transaction_type, description, balance, transaksi_date, status_transaksi, created_date, created_by) VALUES (%s, %s, %s, %s, %s, %s, %s, %s);' # cursorKmPay.execute(withdrawSql, ([no_rekening], ["D"], ["WITHDRAW"], [amount], [now], ["SUCCESS"], [now], [globalVariable.create_by])) # connectKmPay.commit() # Insert to LOG withdrawLogSql = 'INSERT INTO tbl_log_withdraw (no_rekening, withdraw_pin, balance, type, status, created_date, created_by) VALUES (%s, %s, %s, %s, %s, %s, %s);' cursorKmPay.execute(withdrawLogSql, ([no_rekening], [withdraw_pin], [amount], [type], ["NOT RECEIVE"], [now], [globalVariable.create_by])) connectKmPay.commit() return {'status ':"success",'code': 200, "result":"Success Withdraw"} else: return {'status ':"success",'code': 204, "result":"Saldo anda tidak mencukupi"} else: return generalNotification.DataNotAvailable(self) else: return tokenStatus else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def createPayment(self, param): if len(param) != 0: if "TOKEN" in param: pass else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def setMainAddress(self, param): if len(param) != 0: if "TOKEN" in param: pass else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def removeCart(self, param): if len(param) != 0: if "TOKEN" in param: pass else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def registerAccount(self, param): if len(param) != 0: if "TOKEN" in param: now = datetime.datetime.now() wrapData = param['DATA'] splitData = wrapData.split(".") data = helper.decrypt(splitData[0], globalVariable.key, splitData[1]) newStr = re.match("(.*?)}", data).group() newStr = json.loads(newStr) email = newStr.get("email") full_name = newStr.get("full_name") address = newStr.get("address") token = newStr.get("token") tokenStatus = Authentication.checkValidToken(self, param['TOKEN']) if tokenStatus[0]["status"] == "success": emailStatus = checkEmailAccount(self, email) prefix_domain = helper.getPrefixDomain(self, newStr.get("domain")) no_rekening = str( prefix_domain['prefix_domain']) + generateAccountBank(self) if emailStatus != 1: now = str(datetime.datetime.now()) createMemberAccountSql = "INSERT INTO tbl_member (member_no_rekening, member_email, full_name, address, member_created_date, member_created_by) VALUES (%s, %s, %s, %s, %s, %s);" cursorKmCrm.execute(createMemberAccountSql, ([no_rekening], [email], [full_name], [ address ], [now], [globalVariable.create_by])) connectKmCrm.commit() # insert into rekening table createAccountSql = 'INSERT INTO tbl_rekening (no_rekening, is_active, activate_date, created_date, created_by) VALUES (%s, %s, %s, %s, %s);' cursorKmCrm.execute(createAccountSql, ([no_rekening], [1], [now], [now], [globalVariable.create_by])) connectKmCrm.commit() return jsonify({ 'status ': "success", 'code': 200, "message": "Create Account Success" }) else: return jsonify({ 'status ': "error", 'code': 204, "message": "Email has been register before" }) else: return tokenStatus else: return generalNotification.TokenNotAvailable(self) else: return generalNotification.DataNotAvailable(self)
def post(self): param = request.get_json() if param["CMD"]: # KM Register Account if param["CMD"] == "KRA": return kmMain.registerAccount(self, param) # Setting Quiz if param["CMD"] == "KSQ": pass elif param["CMD"] == "KBQ": pass elif param["CMD"] == "KCQ": pass else: pass else: return generalNotification.DataNotAvailable(self)
def post(self): param = request.get_json() if param["CMD"]: # Store Register Account if param["CMD"] == "SRA": return kmStore.registerAccount(self, param) # List Product elif param["CMD"] == "SLP": return kmStore.getListProduct(self, param) # Get Product elif param['CMD'] == "SGP": return kmStore.getProduct(self, param) # Search Product by Name elif param['CMD'] == "SSP": return kmStore.searchProductByName(self, param) # Create Cart elif param['CMD'] == "SCC": return kmStore.createCart(self, param) # Update Cart elif param['CMD'] == "SUC": return kmStore.updateCart(self, param) # Delete Cart elif param['CMD'] == "SDC": return kmStore.removeCart(self, param) # View Detail Cart elif param['CMD'] == "SVC": return kmStore.viewCart(self, param) # Create Order elif param['CMD'] == "SCO": return kmStore.createOrder(self, param) # Set Main Address elif param['CMD'] == "SMA": return kmStore.setMainAddress(self, param) # Create New Address elif param['CMD'] == "SCA": return kmStore.createNewAddress(self, param) # Create Payment elif param['CMD'] == "SCP": return kmStore.createPayment(self, param) else: pass else: return generalNotification.DataNotAvailable(self)
def post(self): param = request.get_json() if param["CMD"]: # CRM Register Account if param["CMD"] == "CRA": return kmCrm.registerAccount(self, param) # Setting Quiz elif param["CMD"] == "CSQ": pass elif param["CMD"] == "CBQ": pass elif param["CMD"] == "CCQ": pass elif param == None: pass else: pass else: return generalNotification.DataNotAvailable(self)