コード例 #1
0
ファイル: api.py プロジェクト: CASL-AE/supplyme-admin
    def post(self):
        try:
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403

            incoming = request.get_json()
            request_info = incoming['requestInfo']
            if not activation_code:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Request Parameters'
                }
                return make_response(jsonify(responseObject)), 400

            responseObject = {
                'status': 'success',
                'statusText': 'Request Cloud Match Received'
            }
            return make_response(jsonify(responseObject)), 200

        except Exception as e:
            logger.error('Error on RequestCloudMatch.post; Error: %s', e)
            responseObject = {'status': 'failed', 'statusText': str(e)}
            return make_response(jsonify(responseObject)), 403
コード例 #2
0
    def post(self):
        try:
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403
            incoming = request.get_json()
            accountID = incoming['accountID']
            merchantHash = incoming['merchantHash']
            print(accountID)
            print(merchantHash)
            gateway = BraintreeClient().gateway
            bt_token = XupplyBraintreeCustomer(gateway=gateway).create_token(
                accountID=merchantHash)
            logger.info('Braintree Token ~ User: %s', claims['user_id'])
            data = {
                'btToken': bt_token,
            }
            responseObject = {
                'status': 'success',
                'statusText': 'Braintree Token',
                'data': data,
            }
            return make_response(jsonify(responseObject)), 200

        except Exception as e:
            logger.error('Error on BraintreeToken.post; Error: %s', e)
            responseObject = {'status': 'failed', 'statusText': str(e)}
            return make_response(jsonify(responseObject)), 403
コード例 #3
0
    def get(self):
        try:
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403
            incoming = request.args
            print(incoming)
            accountID = incoming['accountID']
            address = incoming['address']
            result = get_hospital_rank(addresss)
            responseObject = {
                'status': 'success',
                'statusText': 'Google Directions',
                'data': result
            }
            return make_response(jsonify(responseObject)), 200

        except Exception as e:
            logger.error('Error DirectionsGoogleGet.post; Error: %s', e)
            responseObject = {
                'status': 'failed',
                'statusText': str(e)
            }
            return make_response(jsonify(responseObject)), 403
コード例 #4
0
    def get(self):
        try:
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403
            incoming = request.args
            print(incoming)
            accountID = incoming['accountID']
            origin = incoming['origin']
            destination = incoming['destination']
            waypoints = incoming.getlist('waypoints[]')
            result = get_google_directions(origin, destination, waypoints)
            responseObject = {
                'status': 'success',
                'statusText': 'Google Directions',
                'data': result
            }
            return make_response(jsonify(responseObject)), 200

        except Exception as e:
            logger.error('Error DirectionsGoogleGet.post; Error: %s', e)
            responseObject = {
                'status': 'failed',
                'statusText': str(e)
            }
            return make_response(jsonify(responseObject)), 403
コード例 #5
0
    def post(self):
        try:
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403

            incoming = request.get_json()
            activation_code = incoming['activationCode']
            if not activation_code:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Request Parameters'
                }
                return make_response(jsonify(responseObject)), 400

            accountCode = XupplyAccountCode().dict_snapshot(snapshot=activation_code)
            data = {
                'to_name': accountCode.ownerName,
                'to_account_name': accountCode.accountName,
                'from_name': 'The Xupply Team',
                'activation_code': accountCode.activationCode,
            }
            clean_email = accountCode.email
            data['user_email'] = accountCode.email
            # notifications.account_code_email_notification_task.apply_async(kwargs=data)
            # notifications.account_code_email_notification_task(
            #     user_email=data['user_email'],
            #     to_name=data['to_name'],
            #     to_account_name=data['to_account_name'],
            #     from_name=data['from_name'],
            #     activation_code=data['activation_code']
            # )

            responseObject = {
                'status': 'success',
                'statusText': 'Account Code Email Successfully Sent'
            }
            return make_response(jsonify(responseObject)), 200

        except Exception as e:
            logger.error('Error on AccountCodeSendEmail.post; Error: %s', e)
            responseObject = {
                'status': 'failed',
                'statusText': str(e)
            }
            return make_response(jsonify(responseObject)), 403
コード例 #6
0
    def post(self):
        try:
            claims = {}
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403

            incoming = request.get_json()
            print(incoming)
            accountID = incoming['accountID']
            merchantHash = incoming['merchantHash']
            nonce = incoming['nonce']
            paymentInfo = incoming['paymentInfo']
            employeeID = claims['user_id']

            delta_server = XupplyReferences()
            transaction = delta_server.transaction_ref
            account_ref = XupplyReferences().accounts_ref.document(accountID)
            payment_ref = account_ref.collection('Payments').document()
            payment_object = XupplyPayment().dict_snapshot(
                snapshot=paymentInfo)

            merchant_result = create_payment_task(
                employeeID=employeeID,
                accountID=accountID,
                nonce=nonce,
                payment_object=payment_object,
                merchantHash=merchantHash,
            )

            if merchant_result.is_success == True:
                paymentHash = merchant_result.payment_method.token
                logger.info(
                    'Create Braintree Payment Success: {}'.format(paymentHash))
                create_payment_transaction(transaction, payment_ref,
                                           payment_object, paymentHash)

                data = {'paymentHash': paymentHash}
                responseObject = {
                    'status': 'success',
                    'statusText': 'Dwolla Payment Created',
                    'data': data,
                }
                return make_response(jsonify(responseObject)), 200

            else:
                logger.error('Create Braintree Payment Failure: {}'.format(
                    merchant_result.errors.deep_errors))
                for error in merchant_result.errors.deep_errors:
                    error_code = None
                    error_message = None
                    error_code = error.code
                    error_message = error.message
                    responseObject = {
                        'status': error_code,
                        'statusText': error_message
                    }
                    return make_response(jsonify(responseObject)), 400

        except Exception as e:
            logger.error('Error on BraintreePayment.post; Error: %s', e)
            responseObject = {'status': 'failed', 'statusText': str(e)}
            return make_response(jsonify(responseObject)), 403
コード例 #7
0
    def post(self):
        try:
            claims = {}
            id_token = request.headers.get('Authorization').split(' ').pop()
            claims = verify_firebase_token(id_token)
            if not claims:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Token'
                }
                return make_response(jsonify(responseObject)), 403

            incoming = request.get_json()
            print(incoming)
            accountID = incoming['accountID']
            employeeID = claims['user_id']
            email = claims['email']

            delta_server = XupplyReferences()
            transaction = delta_server.transaction_ref
            account_ref = XupplyReferences().accounts_ref.document(accountID)
            account_doc = account_ref.get()
            account_dict = account_doc.to_dict()
            if not account_dict:
                responseObject = {
                    'status': 'failed',
                    'statusText': 'Invalid Account Dict'
                }
                return make_response(jsonify(responseObject)), 403

            account_object = XupplyAccount().dict_snapshot(
                snapshot=account_doc.to_dict())

            print('HERE')
            merchant_result = create_customer_task(
                email=email,
                employeeID=employeeID,
                accountID=accountID,
                account_object=account_object)

            print(merchant_result.is_success)
            print(merchant_result.customer.id)
            if merchant_result.is_success == True:
                merchantHash = merchant_result.customer.id

                logger.info('Create Braintree Customer Success: {}'.format(
                    merchantHash))
                create_customer_transaction(transaction, account_ref,
                                            account_object, merchantHash)

                data = {'merchantHash': merchantHash}
                responseObject = {
                    'status': 'success',
                    'statusText': 'Braintree Customer Created',
                    'data': data,
                }
                return make_response(jsonify(responseObject)), 200
            else:
                for error in merchant_result.errors.deep_errors:
                    error_code = None
                    error_message = None
                    error_code = error.code
                    error_message = error.message
                    responseObject = {
                        'status': error_code,
                        'statusText': error_message
                    }
                    return make_response(jsonify(responseObject)), 400

        except Exception as e:
            logger.error('Error on BraintreeCustomer.post; Error: %s', e)
            responseObject = {'status': 'failed', 'statusText': str(e)}
            return make_response(jsonify(responseObject)), 403