Example #1
0
def process():
    threading.Timer(2 * 60, process).start()
    for pendingDeactiveNode in getPendingDoc(db.deactive_nodes):
        userId = pendingDeactiveNode.get('userId')
        if userId is not None:
            user = User.by_id(client, userId, 'yes')
            nodes = Node.all(user)
            for node in nodes:
                client.nodes.delete(userId, node.id)

            # set to DONE
            markDel(userId,'DEACTIVATED-NODE')
            markDoneDoc(db.deactive_nodes, userId)

    for pendingDeactiveNode in getPendingDoc(db.lock_users):
        userId = pendingDeactiveNode.get('userId')
        if userId is not None:
            user = User.by_id(client, userId, 'yes')
            if user.permission != 'MAKE-IT-GO-AWAY':
                payload = {
                    'permission': 'MAKE-IT-GO-AWAY'
                }
                client.users.update(userId, payload)

            # set to DONE
            markDel(userId,'LOCKED-USER')
            markDoneDoc(db.lock_users, userId)
def getAddenda(userId, wyre_amount, wyre_date):
    user = User.by_id(synapseClient, userId)
    addenda = ""

    options = {'page': 1, 'per_page': 20, 'type': 'SUBACCOUNT-US'}

    nodes = Node.all(user, **options)
    if not nodes:
        return addenda
    nodeid = getattr(nodes[0], 'id')

    node = Node.by_id(user, nodeid)

    transactions = Transaction.all(node, **options)

    x = len(transactions)
    print("transactions\n")
    print(x)
    for translist in range(0, x):
        amount = getattr(transactions[translist], 'amount')
        timelines = getattr(transactions[translist], 'timelines')
        real_amount = amount.get("amount")
        if real_amount == wyre_amount:
            for d in timelines:
                if d.get("status") == "CREATED":
                    if d.get("date") == wyre_date:
                        from_info = getattr(transactions[translist], 'from')
                        addenda = from_info.get("meta").get("addenda")
    print("addenda:", addenda)
    return addenda
Example #3
0
 def synapse_user_from_slack_user_id(self, slack_user_id):
     """Find the Slack user's Synapse ID and get the Synapse user."""
     user = User.query.filter_by(slack_user_id=slack_user_id).first()
     if user is None:
         return None
     return SynapseUser.by_id(client=synapse_client,
                              id=user.synapse_user_id)
Example #4
0
def reupSynapseCoiDoc(userId, coiDoc):
    user = User.by_id(client, userId)
    data = getIdDoc(coiDoc)
    if data is None:
        print("cannot upload: " + coiDoc)
        return None
    user.base_documents[0].add_physical_document(type='OTHER',
                                                 mime_type='image/png',
                                                 byte_stream=data)
Example #5
0
def reupAMZCapturedImg(userId, amz_id):
    user = User.by_id(client, userId)
    data = getAMZImg(amz_id)
    if data is None:
        print("cannot upload: " + amz_id)
        return None
    user.base_documents[0].add_physical_document(type='OTHER',
                                                 mime_type='image/png',
                                                 byte_stream=data)
Example #6
0
    def create_synapse_user(slack_id, request):
        """Creates a new user with Synapse."""
        # 'options' actually required until pending API update or lib change
        options = {
            'note': 'created by Synapse Slackbot',
            'supp_id': slack_id,
            'is_business': False,
            'cip_tag': 1
        }

        return SynapseUser.create(client=synapse_client,
                                  email=request.form['email'],
                                  phone_number=request.form['phone'],
                                  legal_name=request.form['name'].title(),
                                  **options)
Example #7
0
def createSynapseUser(srn, data):
    try:
        name = pinyin.get(
            data.get("nameCn"), format="strip", delimiter=" ") if (
                data.get('nameCn', None) != ''
                and data.get('nameCn', None) != None) else data.get("nameEn")
        args = {
            'email': data.get('email'),
            'phone_number': data.get('phoneNumber'),
            'legal_name': name,
            'supp_id': srn,
            'is_business': data.get('isBusiness'),  # default False first
            'cip_tag': 1
        }
        return None, User.create(client, **args)
    except Exception as e:
        logger.debug(traceback.format_exc())
        return {'error': str(e)}, None
def process():
    walletsArg = args.wallets
    missingDoc = args.missing_doc

    if walletsArg is None or missingDoc is None:
        print('Both wallets and missing_doc parameters are required.')
        sys.exit()

    if missingDoc not in ['individual', 'company']:
        print('missing_doc must only be individual or company')
        sys.exit()

    walletIds = walletsArg.split(',')
    for walletId in walletIds:
        if walletId != '':
            vbaRequest = getVbaRequestByWalletId(walletId)
            vbaData = vbaRequest.get('vbaData')

            if vbaData is None:
                print('There is no userId for wallet {}'.format(walletId))
                continue

            userId = vbaData.get('userId')
            if userId is None:
                print('There is no userId for wallet {}'.format(walletId))
                continue

            user = User.by_id(client, userId, 'yes')
            if missingDoc == 'individual':
                error, baseDocument = addBasisDocument(user, vbaRequest)
                if error is not None:
                    print(
                        'Wallet {}: add individual base doc error: {}'.format(
                            walletId, error['error']))
            else:
                error, baseDocument = addBusinessDocument(
                    user, vbaRequest, walletId)
                if error is not None:
                    print('Wallet {}: add company base doc error: {}'.format(
                        walletId, error['error']))
Example #9
0
def process():
    for wallet in getWalletsHaveUserId(db.vbarequests):
        userId = wallet.get('vbaData').get('userId')
        walletId = wallet.get('walletId')
        user = User.by_id(client, userId, 'yes')
        userInfo = user.__getattribute__('json')

        # append walletId
        userInfo['walletId'] = walletId

        # rename mongo reserved keys
        userInfo['userId'] = userInfo.pop('_id')

        if userInfo is not None:
            db.synapse_users.update({'walletId': walletId}, {'$set': userInfo},
                                    upsert=True)
        else:
            grayLogger.critical('user not found',
                                extra={
                                    'type': 'sync_synapse_users',
                                    'userId': userId
                                })
            print('user not found by id: {}'.format(userId))
Example #10
0
def reupSynapseIdDoc(userId, idDoc, baseDocId, subDocId):
    user = User.by_id(client, userId, 'yes')
    data = getIdDoc(idDoc)
    if data is None:
        print("cannot upload: " + idDoc)
        return None

    document = None
    if baseDocId is not None and baseDocId != '':
        for doc in user.base_documents:
            if doc.id == baseDocId:
                document = doc
                break
    else:
        if len(user.base_documents) == 1:
            # if user has only one document, update it
            document = user.base_documents[0]
        elif len(user.base_documents) > 1:
            # if user has more than one document, update individual document (base on email)
            for doc in user.base_documents:
                if doc.email[-10:] != 'epiapi.com' and doc.email[-12:] != 'sendwyre.com':
                    document = doc
                    break

    if document is not None:
        # delete old doc if exist
        if subDocId is not None and subDocId != '':
            args = {
                'physical_documents': [{
                    'id': subDocId,
                    'document_type':'DELETE_DOCUMENT',
                    'document_value':'data:image/gif;base64,SUQs=='
                }]
            }
            document.update(**args)
        # add new
        document.add_physical_document(type='GOVT_ID_INT', mime_type='image/png', byte_stream=data)
def process():
    threading.Timer(60, process).start()

    # open images
    logo = Image.open('epiapi_logo.png')
    box = Image.open('box.png')

    # get fonts
    font = ImageFont.truetype("fonts/Arial_Unicode.ttf", 28)
    boldFont = ImageFont.truetype("fonts/Arial_Unicode_Bold.ttf", 28)
    italicFont = ImageFont.truetype("fonts/Arial_Unicode_Italic.ttf", 26)
    heading = ImageFont.truetype("fonts/Arial_Unicode.ttf", 50)

    for doc in getPendingAuthorizationDocs(db.authorization_docs):
        try:
            img = Image.new('RGB', (1240, 1754), (255, 255, 255))
            draw = ImageDraw.Draw(img)

            # heading
            draw.text((140, 80),
                      'EPIAPI - ID TRANSLATION', (0, 0, 0),
                      font=heading)

            # logo
            img.paste(logo, (960, 40))

            # document info
            draw.text((140, 250), 'Prepared For', (0, 0, 0), font=boldFont)
            draw.text((380, 250),
                      'Synapse Financial Technologies Inc.', (0, 0, 0),
                      font=font)
            draw.text((140, 300), 'Date', (0, 0, 0), font=boldFont)
            draw.text((380, 300),
                      datetime.today().strftime('%d %B %Y'), (0, 0, 0),
                      font=font)
            draw.text((140, 350), 'UserId', (0, 0, 0), font=boldFont)
            draw.text((380, 350), doc.get('userId'), (0, 0, 0), font=font)

            # box
            img.paste(box, (130, 425))
            # text with box
            draw.text(
                (160, 450),
                'Epiapi verifies the below information in relation to the userId provided above.',
                (0, 0, 0),
                font=italicFont)
            draw.text(
                (160, 480),
                'Epiapi staff review each ID manually prior to signing off on the below.',
                (0, 0, 0),
                font=italicFont)

            draw.text((140, 600),
                      'ORIGINAL', (0, 0, 0),
                      font=ImageFont.truetype("fonts/Arial_Unicode_Bold.ttf",
                                              40))
            idDocUri = doc.get('idDoc')

            curHeight = 700

            if idDocUri is not None and idDocUri != "":
                idDocResp = get(idDocUri)
                if idDocResp.status_code == 200:
                    basewidth = 580
                    with Image.open(BytesIO(idDocResp.content)) as idDocImg:
                        w, h = idDocImg.size

                        wpercent = (basewidth / float(w))
                        hsize = int((float(h) * float(wpercent)))
                        idDocImg = idDocImg.resize((basewidth, hsize),
                                                   Image.ANTIALIAS)
                        img.paste(idDocImg, (140, 700))
                        curHeight += (hsize + 40)

            draw.text((140, curHeight),
                      'ENGLISH TRANSLATION', (0, 0, 0),
                      font=ImageFont.truetype("fonts/Arial_Unicode_Bold.ttf",
                                              40))

            draw.text((140, curHeight + 100),
                      'Fullname:', (0, 0, 0),
                      font=boldFont)
            draw.text((420, curHeight + 100),
                      doc.get('fullName'), (0, 0, 0),
                      font=font)

            draw.text((140, curHeight + 140), 'Sex:', (0, 0, 0), font=boldFont)
            draw.text((420, curHeight + 140),
                      doc.get('sex'), (0, 0, 0),
                      font=font)

            draw.text((140, curHeight + 180),
                      'Ethnicity:', (0, 0, 0),
                      font=boldFont)
            draw.text((420, curHeight + 180),
                      doc.get('ethnicity'), (0, 0, 0),
                      font=font)

            draw.text((140, curHeight + 220),
                      'Date of birth:', (0, 0, 0),
                      font=boldFont)
            draw.text((420, curHeight + 220),
                      doc.get('dobString'), (0, 0, 0),
                      font=font)

            draw.text((140, curHeight + 260),
                      'Citizen ID Number:', (0, 0, 0),
                      font=boldFont)
            draw.text((420, curHeight + 260),
                      doc.get('citizenIdNumber'), (0, 0, 0),
                      font=font)

            draw.text((140, curHeight + 300),
                      'Address:', (0, 0, 0),
                      font=boldFont)
            street1 = doc.get('address').get('street1')
            street2 = doc.get('address').get('street2')
            city = doc.get('address').get('city')
            state = doc.get('address').get('state')
            postalCode = doc.get('address').get('postalCode')
            country = doc.get('address').get('country')
            address = "{} {} {} {}".format(city, state, postalCode, country)

            draw.text((420, curHeight + 300), street1, (0, 0, 0), font=font)
            paddingForStreet2 = 0
            if street2 != "":
                paddingForStreet2 = 40
                draw.text((420, curHeight + 340),
                          street2, (0, 0, 0),
                          font=font)
            draw.text((420, curHeight + 300 + paddingForStreet2 + 40),
                      address, (0, 0, 0),
                      font=font)

            # attach signature
            signatureImg = Image.open('{}.png'.format(
                doc.get('adminAccountId')))
            img.paste(signatureImg,
                      (860, curHeight + 300 + paddingForStreet2 + 150))

            draw.text((900, curHeight + 300 + paddingForStreet2 + 120),
                      'Verified by:', (0, 0, 0),
                      font=font)
            draw.text((900, curHeight + 300 + paddingForStreet2 + 270),
                      doc.get('adminAccountName')
                      if doc.get('adminAccountName') is not None else "",
                      (0, 0, 0),
                      font=font)

            userId = doc.get('userId')

            img.save('{}.pdf'.format(userId))

            with open('{}.pdf'.format(userId),
                      mode='rb') as file:  # b is important -> binary
                fileContent = file.read()
                user = User.by_id(client, userId, 'yes')
                for doc in user.base_documents:
                    if doc.email[-10:] != 'epiapi.com' and doc.email[
                            -12:] != 'sendwyre.com':
                        doc.add_physical_document(type='AUTHORIZATION',
                                                  mime_type='application/pdf',
                                                  byte_stream=fileContent)

            os.remove('{}.pdf'.format(userId))

            # close signature
            signatureImg.close()

            # close img
            img.close()

            # mark to DONE after upload
            db.authorization_docs.update({'walletId': doc.get('walletId')},
                                         {'$set': {
                                             'status': 'DONE'
                                         }})
        except Exception as e:
            print(e)
            pass

    # close images
    logo.close()
    box.close()
Example #12
0
def process():
    threading.Timer(2 * 60, process).start()

    for pendingDoc in getPendingScheduledDocs(db.scheduled_reup_docs):
        try:
            docType = pendingDoc.get('docType')
            _id = pendingDoc.get('_id')
            baseDocId = pendingDoc.get('baseDocId')
            subDocId = pendingDoc.get('subDocId')

            # skip if docType not found!
            if docType is None:
                continue

            # proceed based on docType
            walletId = pendingDoc.get('walletId')
            userId = pendingDoc.get('userId')
            if docType == 'authorization':
                authorizedData = pendingDoc.get('authorizationData')
                uploadAuthorizedDoc(userId, authorizedData, baseDocId, subDocId)
            elif docType == 'idDoc':
                vba = getVbaByWalletId(walletId)
                if vba is not None:
                    idDoc = vba.get('idDoc')
                    if idDoc is not None:
                        reupSynapseIdDoc(userId, idDoc, baseDocId, subDocId)
            elif docType == 'coiDoc':
                vba = getVbaByWalletId(walletId)
                if vba is not None:
                    coiDoc = vba.get('coiDoc')
                    if coiDoc is not None:
                        reupSynapseCoiDoc(userId, coiDoc, baseDocId, subDocId)
            elif docType == 'amz':
                vba = getVbaByWalletId(walletId)
                merchantIds = vba.get('merchantIds')
                print(merchantIds)
                if merchantIds is not None and len(merchantIds) > 0:
                    merchantId = merchantIds[0].get('merchantId')
                    if merchantId is not None:
                        reupAMZCapturedImg(userId, merchantId, baseDocId, subDocId)
            elif docType == 'basic' or docType == 'company_basic': # individual basic
                user = User.by_id(client, userId, 'yes')
                userData = pendingDoc.get('userData')
                if baseDocId is not None and baseDocId != '':
                    docPayload = {
                        'id': baseDocId,
                        'email': userData.get('email'),
                        'phone_number': userData.get('phone_number'),
                        'ip': userData.get('ip'),
                        'address_street': userData.get('address_street'),
                        'address_city': userData.get('address_city'),
                        'address_subdivision': userData.get('address_subdivision'),
                        'address_postal_code': userData.get('address_postal_code'),
                        'address_country_code': userData.get('address_country_code'),
                        'day': userData.get('day'),
                        'month': userData.get('month'),
                        'year': userData.get('year'),
                    }

                    for key in ['name', 'alias', 'entity_type', 'entity_scope']:
                        if userData.get(key) is not None:
                            docPayload[key] = userData.get(key)

                    payload = {
                        'documents': [docPayload]
                    }
                    client.users.update(userId, payload)
            elif docType == 'delete_physical':
                if baseDocId is not None and subDocId is not None:
                    user = User.by_id(client, userId, 'yes')
                    document = None
                    for doc in user.base_documents:
                        if doc.id == baseDocId:
                            document = doc
                            break

                    if document is not None:
                        # delete old doc if exist
                        args = {
                            'physical_documents': [{
                                'id': subDocId,
                                'document_type':'DELETE_DOCUMENT',
                                'document_value':'data:image/gif;base64,SUQs=='
                            }]
                        }
                        document.update(**args)

            # mark record status = DONE after processing
            markDoneScheduledDoc(_id)
        except:
            pass
Example #13
0
def uploadAuthorizedDoc(userId, doc, baseDocId, subDocId):
    # open images
    logo = Image.open('epiapi_logo.png')
    box = Image.open('box.png')

    # get fonts
    font = ImageFont.truetype("fonts/Arial_Unicode.ttf", 28)
    boldFont = ImageFont.truetype("fonts/Arial_Unicode_Bold.ttf", 28)
    italicFont = ImageFont.truetype("fonts/Arial_Unicode_Italic.ttf", 26)
    heading = ImageFont.truetype("fonts/Arial_Unicode.ttf", 50)

    img = Image.new('RGB', (1240,1754), (255,255,255))
    draw = ImageDraw.Draw(img)

    # heading
    draw.text((140, 80), 'EPIAPI - ID TRANSLATION', (0,0,0), font=heading)

    # logo
    img.paste(logo, (960, 40))

    # document info
    draw.text((140, 250), 'Prepared For', (0,0,0), font=boldFont)
    draw.text((380, 250), 'Synapse Financial Technologies Inc.', (0,0,0), font=font)
    draw.text((140, 300), 'Date', (0,0,0), font=boldFont)
    draw.text((380, 300), datetime.today().strftime('%d %B %Y'), (0,0,0), font=font)
    draw.text((140, 350), 'UserId', (0,0,0), font=boldFont)
    draw.text((380, 350), userId, (0,0,0), font=font)

    # box
    img.paste(box, (130, 425))
    # text with box
    draw.text((160, 450), 'Epiapi verifies the below information in relation to the userId provided above.', (0,0,0), font=italicFont)
    draw.text((160, 480), 'Epiapi staff review each ID manually prior to signing off on the below.', (0,0,0), font=italicFont)

    draw.text((140, 600), 'ORIGINAL', (0, 0, 0), font=ImageFont.truetype("fonts/Arial_Unicode_Bold.ttf", 40))
    idDocUri = doc.get('idDoc')

    curHeight = 700

    if idDocUri is not None and idDocUri != "":
        idDocResp = get(idDocUri)
        if idDocResp.status_code == 200:
            basewidth = 580
            with Image.open(BytesIO(idDocResp.content)) as idDocImg:
                w, h = idDocImg.size

                wpercent = (basewidth / float(w))
                hsize = int((float(h) * float(wpercent)))
                idDocImg = idDocImg.resize((basewidth, hsize), Image.ANTIALIAS)
                img.paste(idDocImg, (140, 700))
                curHeight += (hsize + 40)

    draw.text((140, curHeight), 'ENGLISH TRANSLATION', (0, 0, 0), font=ImageFont.truetype("fonts/Arial_Unicode_Bold.ttf", 40))

    draw.text((140, curHeight + 100), 'Fullname:', (0,0,0), font=boldFont)
    draw.text((420, curHeight + 100), doc.get('fullName'), (0,0,0), font=font)

    draw.text((140, curHeight + 140), 'Sex:', (0,0,0), font=boldFont)
    draw.text((420, curHeight + 140), doc.get('sex'), (0,0,0), font=font)

    draw.text((140, curHeight + 180), 'Ethnicity:', (0,0,0), font=boldFont)
    draw.text((420, curHeight + 180), doc.get('ethnicity'), (0,0,0), font=font)

    draw.text((140, curHeight + 220), 'Date of birth:', (0,0,0), font=boldFont)
    draw.text((420, curHeight + 220), doc.get('dobString'), (0,0,0), font=font)

    draw.text((140, curHeight + 260), 'Citizen ID Number:', (0,0,0), font=boldFont)
    draw.text((420, curHeight + 260), doc.get('citizenIdNumber'), (0,0,0), font=font)

    draw.text((140, curHeight + 300), 'Address:', (0,0,0), font=boldFont)
    street1 = doc.get('address').get('street1')
    street2 = doc.get('address').get('street2')
    city = doc.get('address').get('city')
    state = doc.get('address').get('state')
    postalCode = doc.get('address').get('postalCode')
    country = doc.get('address').get('country')
    address = "{} {} {} {}".format(city, state, postalCode, country)

    draw.text((420, curHeight + 300), street1, (0,0,0), font=font)
    paddingForStreet2 = 0
    if street2 != "":
        paddingForStreet2 = 40
        draw.text((420, curHeight + 340), street2, (0,0,0), font=font)
    draw.text((420, curHeight + 300 + paddingForStreet2 + 40), address, (0,0,0), font=font)

    # attach signature
    signatureImg = Image.open('{}.png'.format(doc.get('adminAccountId')))
    img.paste(signatureImg, (860, curHeight + 300 + paddingForStreet2 + 150))

    draw.text((900, curHeight + 300 + paddingForStreet2 + 120), 'Verified by:', (0,0,0), font=font)
    draw.text((900, curHeight + 300 + paddingForStreet2 + 270), doc.get('adminAccountName') if doc.get('adminAccountName') is not None else "", (0,0,0), font=font)

    img.save('{}.pdf'.format(userId))

    with open('{}.pdf'.format(userId), mode='rb') as file: # b is important -> binary
        fileContent = file.read()
        user = User.by_id(client, userId, 'yes')

        document = None
        if baseDocId is not None and baseDocId != '':
            for doc in user.base_documents:
                if doc.id == baseDocId:
                    document = doc
                    break
        else:
            if len(user.base_documents) == 1:
                # if user has only one document, update it
                document = user.base_documents[0]
            elif len(user.base_documents) > 1:
                # if user has more than one document, update individual document (base on email)
                for doc in user.base_documents:
                    if doc.email[-10:] != 'epiapi.com' and doc.email[-12:] != 'sendwyre.com':
                        document = doc
                        break

        if document is not None:
            # delete old doc if exist
            if subDocId is not None and subDocId != '':
                args = {
                    'physical_documents': [{
                        'id': subDocId,
                        'document_type':'DELETE_DOCUMENT',
                        'document_value':'data:image/gif;base64,SUQs=='
                    }]
                }
                document.update(**args)
            # add new
            document.add_physical_document(type='AUTHORIZATION', mime_type='application/pdf', byte_stream=fileContent)

    os.remove('{}.pdf'.format(userId))

    # close signature
    signatureImg.close()

    # close img
    img.close()

    # close images
    logo.close()
    box.close()
Example #14
0
def getSynapseData(userId, nodeId, subnetId):
    user = User.by_id(client, userId)
    node = Node.by_id(user, nodeId)
    subnet = Subnet.by_id(node, subnetId)
    return user, node, subnet