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 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 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(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