def post(cls): merchant = merchant_schema.load(request.get_json()) if MerchantModel.find_merchant_by_email(merchant.email): return {"msg": MERCHANT_ALREADY_EXISTS.format(merchant.email)}, 400 if MerchantModel.find_merchant_by_mobile_number( merchant.mobile_number): return { "msg": MERCHANT_ALREADY_EXISTS.format(merchant.mobile_number) }, 400 merchant.acquirerCountryCode = countryCdoe[merchant.country] terminalId = str(uuid.uuid4().int >> 32)[0:8] while terminalId in TerminalId: terminalId = str(uuid.uuid4().int >> 32)[0:8] idCode = str(uuid.uuid4().int >> 32)[0:15] while idCode in IdCode: idCode = str(uuid.uuid4().int >> 32)[0:15] try: merchant.terminalId = terminalId merchant.idCode = idCode TerminalId.add(terminalId) IdCode.add(idCode) merchant.save_to_db() except: return {"msg": INTERNAL_SERVER_ERROR}, 500 return {"msg": MERCHANT_CREATED.format(merchant.email)}, 201
def get(cls): # finding identity of using access_token _id = get_jwt_identity() merchant = MerchantModel.find_merchant_by_id(_id) if not merchant: return {"msg": MERCHANT_NOT_FOUND}, 404 return merchant_schema.dump(merchant), 200
def get(self, merchant_id): contract = ContractMerchantModel.get_by_merchant_id(self.db, merchant_id) merchant = MerchantModel.get_by_id(self.db, merchant_id) self.finish_json(result={ "contract_merchant": contract.todict() if contract else None, "merchant": merchant.todict() if merchant else None, })
def post(cls): """ Used for registration of merchant.. payload={ "name":***********, "email":**********, "password":*******, "mobile_number":**, "state":**********, "country":********, "acquirerCountryCode":****, "zipCode": ******** } :return: {"msg": error message or merchant created message} """ merchant = merchant_schema.load(request.get_json()) if MerchantModel.find_merchant_by_email(merchant.email): return {"msg": MERCHANT_ALREADY_EXISTS.format(merchant.email)}, 400 if MerchantModel.find_merchant_by_mobile_number(merchant.mobile_number): return {"msg": MERCHANT_ALREADY_EXISTS.format(merchant.mobile_number)}, 400 # maps country name to country code present in libs.countryCode file merchant.acquirerCountryCode = countryCdoe[merchant.country] # Generates a unique TerminalId terminalId = str(uuid.uuid4().int >> 32)[0:8] while terminalId in TerminalId: terminalId = str(uuid.uuid4().int >> 32)[0:8] # Generates a unique idCode idCode = str(uuid.uuid4().int >> 32)[0:15] while idCode in IdCode: idCode = str(uuid.uuid4().int >> 32)[0:15] try: merchant.terminalId = terminalId merchant.idCode = idCode TerminalId.add(terminalId) IdCode.add(idCode) merchant.save_to_db() except: return {"msg": INTERNAL_SERVER_ERROR}, 500 return {"msg": MERCHANT_CREATED.format(merchant.email)}, 201
def push_all_hotels(self): if not IS_PUSH_TO_STOCK: return from models.merchant import MerchantModel merchants = MerchantModel.get_all(self.session) for merchant in merchants: self.log.info("=== push merchant {} ===".format(merchant.id)) self.push_by_merchant(merchant)
def get(self, merchant_id): contract = ContractMerchantModel.get_by_merchant_id( self.db, merchant_id) merchant = MerchantModel.get_by_id(self.db, merchant_id) self.finish_json( result={ "contract_merchant": contract.todict() if contract else None, "merchant": merchant.todict() if merchant else None, })
def push_all(self): Log.info("<<POI push all>> start") if not IS_PUSH_TO_POI: return from models.merchant import MerchantModel merchants = MerchantModel.get_all(self.session) for merchant in merchants: try: self.push_by_merchant(merchant) except Exception as e: Log.debug(traceback.format_exc())
def modify_merchant(self, id, name, type, admin_pwd, root_pwd): merchant = MerchantModel.get_by_id(self.db, id) if not merchant: raise JsonException(errcode=404, errmsg="merchant not fount") else: merchant.update(self.db, name, type) if admin_pwd: UserModel.update_password(self.db, merchant.id, 'admin', admin_pwd) if root_pwd: UserModel.update_password(self.db, merchant.id, 'root', root_pwd) return merchant
def get(cls): _id = get_jwt_identity() merchant = MerchantModel.find_merchant_by_id(_id) print(merchant_schema.dump(merchant)) try: history_details = HistoryModel.find_by_mobile_number( merchant.mobile_number) except: return {'message': INTERNAL_SERVER_ERROR}, 500 return { 'history': [history_schema.dump(hist) for hist in history_details] }, 200
def suspend_merchant(self, merchant_id, is_suspend): is_suspend = int(is_suspend) merchant = MerchantModel.get_by_id(self.db, merchant_id) if not merchant: raise JsonException(errcode=404, errmsg="merchant not fount") merchant.is_suspend = is_suspend CooperateHotelModel.set_suspend_by_merchant_id(self.db, merchant_id, is_suspend) self.db.commit() PushHotelTask().push_hotel_suspend_by_merchant_id.delay(merchant_id) return merchant
def get(self, hotel_id): hotel = Hotel.get_by_id(self.db, hotel_id) if hotel: merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id) contract = ContractMerchantModel.get_by_merchant_id(self.db, merchant.id) if merchant: self.finish_json(result=dict( merchant=merchant.todict(), contract=contract.todict() if contract else None, )) return self.finish_json(result=dict( merchant={}))
def get(self, hotel_id): hotel = Hotel.get_by_id(self.db, hotel_id) if hotel: merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id) contract = ContractMerchantModel.get_by_merchant_id( self.db, merchant.id) if merchant: self.finish_json(result=dict( merchant=merchant.todict(), contract=contract.todict() if contract else None, )) return self.finish_json(result=dict(merchant={}))
def get(cls): """ :return: The History of transactions of the person who is logged in. """ _id = get_jwt_identity() merchant = MerchantModel.find_merchant_by_id(_id) try: history_details = HistoryModel.find_by_mobile_number( merchant.mobile_number) except: return {'message': INTERNAL_SERVER_ERROR}, 500 return { 'history': [history_schema.dump(hist) for hist in history_details] }, 200
def get_current_user(self): # check wechat login first yield self.valid_wechat_login() username = self.get_secure_cookie('username') merchant_id = self.get_secure_cookie('merchant_id') if username and merchant_id: self.set_secure_cookie('username', username, expires_days=0.02) self.set_secure_cookie('merchant_id', merchant_id, expires_days=0.02) self.merchant = MerchantModel.get_by_id(self.db, merchant_id) self.current_user = UserModel.get_user_by_merchantid_username( self.db, merchant_id, username) raise gen.Return(self.current_user)
def push_hotel(self, hotel_id): Log.info("<<POI push hotel mapping {}>> start".format(hotel_id)) if not IS_PUSH_TO_POI: raise gen.Return(True) hotel = CooperateHotelModel.get_by_id(self.db, hotel_id) if not hotel: raise gen.Return(False) merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id) if not merchant: raise gen.Return(False) hotel_data = self.generate_data(hotel, merchant) r = yield self.post_hotel(hotel_data) raise gen.Return(r)
def get_current_user(self): # check wechat login first yield self.valid_wechat_login() username = self.get_secure_cookie('username') merchant_id = self.get_secure_cookie('merchant_id') if username and merchant_id: self.set_secure_cookie('username', username, expires_days=0.02) self.set_secure_cookie('merchant_id', merchant_id, expires_days=0.02) self.merchant = MerchantModel.get_by_id(self.db, merchant_id) self.current_user = UserModel.get_user_by_merchantid_username(self.db, merchant_id, username) self.current_user.hotel_id = None if self.current_user.type == UserModel.TYPE_SUB: maps = UserHotelMappingModel.get_hotel_by_id(self.db, self.current_user.id, merchant_id) if maps: self.current_user.hotel_id = maps[0].hotel_id raise gen.Return(self.current_user)
def push_hotel(self, hotel_id): Log.info("<<POI push hotel mapping {}>> start".format(hotel_id)) if not IS_PUSH_TO_POI: return from models.cooperate_hotel import CooperateHotelModel from models.merchant import MerchantModel hotel = CooperateHotelModel.get_by_id(self.session, hotel_id) if not hotel: return merchant = MerchantModel.get_by_id(self.session, hotel.merchant_id) if not merchant: return hotel_data = self.generate_data(hotel, merchant) self.post_hotel(hotel_data)
def post(self): Log.info("submit order: {}".format(self.request.body)) order_entity = self.format_order(self.request.body) order = yield self.submit_order(order_entity) merchant = MerchantModel.get_by_id(self.db, order.merchant_id) if order.status in [200, 400, 500]: self.finish_json(errcode=1, errmsg="fail: {}".format(order.exception_info), result=dict(order_id=order.id, merchant=merchant.todict(), )) else: yield self.call_weixin(order) self.finish_json(result=dict(order_id=order.id, btwOrderId=order.main_order_id, wait=0 if order.confirm_type == OrderModel.CONFIRM_TYPE_AUTO or order.status == 300 else 1, merchant=merchant.todict(), ))
def post(cls): json_data = request.get_json() merchant_email = json_data["email"] merchant_password = json_data["password"] merchant = MerchantModel.find_merchant_by_email(email=merchant_email) if not merchant: return {"msg": MERCHANT_NOT_FOUND.format(merchant_email)}, 401 elif merchant.password != merchant_password: return {"msg": INVALID_PASSWORD}, 401 # elif not merchant.activated: # return {"msg": MERCHANT_NOT_CONFIRMED.format(merchant.mobile_number)}, 400 expires = timedelta(days=1) access_token = create_access_token(identity=merchant.id, expires_delta=expires, fresh=True) refresh_token = create_refresh_token(identity=merchant.id) return { "access_token": access_token, "refresh_token": refresh_token, "merchant": merchant_schema.dump(merchant) }, 200
def post(self): Log.info("submit order: {}".format(self.request.body)) order_entity = self.format_order(self.request.body) order = yield self.submit_order(order_entity) merchant = MerchantModel.get_by_id(self.db, order.merchant_id) if order.status in [200, 400, 500]: self.finish_json(errcode=1, errmsg="fail: {}".format(order.exception_info), result=dict( order_id=order.id, merchant=merchant.todict(), )) else: yield self.call_weixin(order) self.finish_json(result=dict( order_id=order.id, btwOrderId=order.main_order_id, wait=0 if order.confirm_type == OrderModel.CONFIRM_TYPE_AUTO or order.status == 300 else 1, merchant=merchant.todict(), ))
def post(cls): """ payload= { "email":*************, "password":********** } :return: Error message if credentials are not valid. if they are valid return {"access_token":******************, "refresh_token":*********} """ json_data = request.get_json() merchant_email = json_data["email"] merchant_password = json_data["password"] merchant = MerchantModel.find_merchant_by_email(email=merchant_email) if not merchant: return {"msg": MERCHANT_NOT_FOUND.format(merchant_email)}, 401 elif merchant.password != merchant_password: return {"msg": INVALID_PASSWORD}, 401 expires = timedelta(days= 1) access_token = create_access_token(identity=merchant.id,expires_delta= expires ,fresh=True) refresh_token = create_refresh_token(identity=merchant.id) return {"access_token": access_token, "refresh_token": refresh_token, "merchant": merchant_schema.dump(merchant)}, 200
def get(self): merchants = MerchantModel.get_all(self.db) self.finish_json(result=dict( merchants=[merchant.todict() for merchant in merchants] ))
def push_all_inventories(self): from models.merchant import MerchantModel merchants = MerchantModel.get_all(self.session) for merchant in merchants: self.push_by_merchant(merchant)
def push_all_rateplan_cancelrule_roomrate(self): from models.merchant import MerchantModel merchants = MerchantModel.get_all(self.session) for merchant in merchants: self.push_by_merchant(merchant)
def new_merchant(self, name, type, admin_pwd, root_pwd): merchant = MerchantModel.new_merchant(self.db, name, type) admin, root = UserModel.new_admin_root_user(self.db, merchant.id, admin_pwd, root_pwd) return merchant, admin, root
def post(cls): _id = get_jwt_identity() payload = request.get_json() merchant = MerchantModel.find_merchant_by_id(_id) if merchant is None: return {"msg": INTERNAL_SERVER_ERROR}, 500 payload["acquirerCountryCode"] = merchant.acquirerCountryCode payload["acquiringBin"] = merchant.acquiringBin payload["businessApplicationId"] = merchant.businessApplicationId payload["cardAcceptor"] = { "address": { "country": merchant.country, "state": merchant.state, "zipCode": merchant.zipCode }, "idCode": merchant.idCode, "name": merchant.name, "terminalId": merchant.terminalId } systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6] while systemsTraceAuditNumber in SystemsTraceAuditNumber: systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6] SystemsTraceAuditNumber.add(systemsTraceAuditNumber) payload["systemsTraceAuditNumber"] = systemsTraceAuditNumber payload["localTransactionDateTime"] = datetime.utcnow().strftime( "%Y-%m-%dT%H:%M:%S") payload["retrievalReferenceNumber"] = RetrievalNo.No() + str( systemsTraceAuditNumber) payload["senderPrimaryAccountNumber"] = "4895142232120006" # print(payload) mobile_number = "" wallet_name = "" flag = False status_code = False if "mobile_number" in payload: flag = True payloadAuthApi = {} mobile_number = payload["mobile_number"] wallet_name = payload["wallet_name"] payloadAuthApi["mobile_number"] = payload["mobile_number"] payloadAuthApi["wallet_name"] = payload["wallet_name"] del (payload["mobile_number"]) del (payload["wallet_name"]) payloadAuthApi["merchant_name"] = merchant.name payloadAuthApi["amount"] = payload["amount"] payloadAuthApi["systemsTraceAuditNumber"] = systemsTraceAuditNumber r = VisaNet.AmountConfirmation(payloadAuthApi) print(r) print(r.json()) if r.status_code != 200: history = HistoryModel( amount=payload["amount"], transaction_id=systemsTraceAuditNumber, transaction_time=payload["localTransactionDateTime"], merchant_mobile_number=merchant.mobile_number, customer_mobile_number=mobile_number, customer_wallet_name=wallet_name, merchant_name=merchant.name, status=status_code) history.save_to_db() return {'msg': PAYMENT_CANNOT_BE_COMPLETED}, 400 if "wallet_name" in payload: del (payload["wallet_name"]) response = FundsTransfer.merchant_pull_payments_post_response(payload) if response.status_code != 200: if flag: payloadAuthApi = { 'mobile_number': mobile_number, 'pan': payload["senderPrimaryAccountNumber"], 'systemsTraceAuditNumber': systemsTraceAuditNumber, 'code': response.status_code } r = VisaNet.TransactionConfirmation(payloadAuthApi) history = HistoryModel( amount=payload["amount"], transaction_id=systemsTraceAuditNumber, transaction_time=payload["localTransactionDateTime"], merchant_mobile_number=merchant.mobile_number, customer_mobile_number=mobile_number, customer_wallet_name=wallet_name, merchant_name=merchant.name, status=status_code) history.save_to_db() return {"msg": INTERNAL_SERVER_ERROR}, 500 if response.status_code == 200: if flag: payloadAuthApi = { 'mobile_number': mobile_number, 'pan': payload["senderPrimaryAccountNumber"], 'systemsTraceAuditNumber': systemsTraceAuditNumber, 'code': response.status_code } r = VisaNet.TransactionConfirmation(payloadAuthApi) status_code = True history = HistoryModel( amount=payload["amount"], transaction_id=systemsTraceAuditNumber, transaction_time=payload["localTransactionDateTime"], merchant_mobile_number=merchant.mobile_number, customer_mobile_number=mobile_number, customer_wallet_name=wallet_name, merchant_name=merchant.name, status=status_code) history.save_to_db() # response = FundsTransfer.merchant_push_payments_post_response() return response
def get(self): merchants = MerchantModel.get_all(self.db) merchants = [merchant.todict() for merchant in merchants] self.finish_json(result=dict(merchants=merchants))
def helloworld(self): print 'helloworld' merchants = MerchantModel.get_all(self.session) raise CeleryException(errcode=100, errmsg='he') return merchants
def get(cls): # get using phone number (can be changed per use case) _id = get_jwt_identity() merchant = MerchantModel.find_merchant_by_id(_id) if not merchant: return {"msg": MERCHANT_NOT_FOUND}, 404 return merchant_schema.dump(merchant), 200
def post(cls): """ This method is used when merchant scans a Qr code of customer and send a pull payment request. :return: msg according to status of transaction """ _id = get_jwt_identity() payload = request.get_json() merchant = MerchantModel.find_merchant_by_id(_id) if merchant is None: return {"msg": INTERNAL_SERVER_ERROR}, 500 # Setting essential fields of Payload for pull funds transfer call payload["acquirerCountryCode"] = merchant.acquirerCountryCode payload["acquiringBin"] = merchant.acquiringBin payload["businessApplicationId"] = merchant.businessApplicationId payload["cardAcceptor"] = { "address": { "country": merchant.country, "state": merchant.state, "zipCode": merchant.zipCode }, "idCode": merchant.idCode, "name": merchant.name, "terminalId": merchant.terminalId } # Generates a unique system trace audit number. systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6] while systemsTraceAuditNumber in SystemsTraceAuditNumber: systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6] SystemsTraceAuditNumber.add(systemsTraceAuditNumber) payload["systemsTraceAuditNumber"] = systemsTraceAuditNumber payload["localTransactionDateTime"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S") payload["retrievalReferenceNumber"] = RetrievalNo.No() + str(systemsTraceAuditNumber) payload["senderPrimaryAccountNumber"] = "4895142232120006" # customer mobile number present in the qr scanned by merchant mobile_number = "" # customer wallet name wallet_name = "" # FLag tells whether we get mobile number from customer details or not. flag = False # status code is for transaction shows whether the transaction was successful or not status_code = False if "mobile_number" in payload: # mobile_number is present in payload flag = True # Setting payload for call to AuthApi for Confirmation of amount present in wallet of sender payloadAuthApi = {} mobile_number = payload["mobile_number"] wallet_name = payload["wallet_name"] payloadAuthApi["mobile_number"] = payload["mobile_number"] payloadAuthApi["wallet_name"] = payload["wallet_name"] del (payload["mobile_number"]) del (payload["wallet_name"]) payloadAuthApi["merchant_name"] = merchant.name payloadAuthApi["amount"] = payload["amount"] payloadAuthApi["systemsTraceAuditNumber"] = systemsTraceAuditNumber # call to authApi for confirmation of amount entered by customer. r = VisaNet.AmountConfirmation(payloadAuthApi) if r.status_code != 200: # Updating History for transaction failure. history = HistoryModel(amount=payload["amount"], transaction_id=systemsTraceAuditNumber, transaction_time=payload["localTransactionDateTime"], merchant_mobile_number=merchant.mobile_number, customer_mobile_number=mobile_number, customer_wallet_name=wallet_name, merchant_name=merchant.name, status=status_code ) history.save_to_db() return {'msg': PAYMENT_CANNOT_BE_COMPLETED}, 400 # deleting nonessential fields of payload if "wallet_name" in payload: del(payload["wallet_name"]) # Sending pull payments request to helper function response = FundsTransfer.merchant_pull_payments_post_response(payload) if response.status_code != 200: if flag: payloadAuthApi = { 'mobile_number': mobile_number, 'pan': payload["senderPrimaryAccountNumber"], 'systemsTraceAuditNumber': systemsTraceAuditNumber, 'code': response.status_code } # Sending request for rollback of payment denoted by code of payload r = VisaNet.TransactionConfirmation(payloadAuthApi) # setting history for payment failure history = HistoryModel(amount=payload["amount"], transaction_id=systemsTraceAuditNumber, transaction_time=payload["localTransactionDateTime"], merchant_mobile_number=merchant.mobile_number, customer_mobile_number=mobile_number, customer_wallet_name=wallet_name, merchant_name=merchant.name, status=status_code ) # saving history in the database history.save_to_db() return {"msg": INTERNAL_SERVER_ERROR}, 500 # payment approved by visa pull funds transfer api if response.status_code == 200: if flag: payloadAuthApi = { 'mobile_number': mobile_number, 'pan': payload["senderPrimaryAccountNumber"], 'systemsTraceAuditNumber': systemsTraceAuditNumber, 'code': response.status_code } # Sending confirmation of transaction to Auth api denoted by code of transaction r = VisaNet.TransactionConfirmation(payloadAuthApi) status_code = True # setting history for payment success history = HistoryModel(amount=payload["amount"], transaction_id=systemsTraceAuditNumber, transaction_time=payload["localTransactionDateTime"], merchant_mobile_number=merchant.mobile_number, customer_mobile_number=mobile_number, customer_wallet_name=wallet_name, merchant_name=merchant.name, status=status_code ) # Saving history in the database. history.save_to_db() return response