def create_link_token_for_payment(): global payment_id try: request = PaymentInitiationRecipientCreateRequest( name='John Doe', bacs=RecipientBACSNullable(account='26207729', sort_code='560029'), address=PaymentInitiationAddress(street=['street name 999'], city='city', postal_code='99999', country='GB')) response = client.payment_initiation_recipient_create(request) recipient_id = response['recipient_id'] request = PaymentInitiationPaymentCreateRequest( recipient_id=recipient_id, reference='TestPayment', amount=PaymentAmount(currency='GBP', value=100.00)) response = client.payment_initiation_payment_create(request) pretty_print_response(response.to_dict()) payment_id = response['payment_id'] request = LinkTokenCreateRequest( products=[Products('payment_initiation')], client_name='Plaid Test', country_codes=list( map(lambda x: CountryCode(x), PLAID_COUNTRY_CODES)), language='en', user=LinkTokenCreateRequestUser(client_user_id=str(time.time())), payment_initiation=LinkTokenCreateRequestPaymentInitiation( payment_id=payment_id)) response = client.link_token_create(request) pretty_print_response(response.to_dict()) return jsonify(response.to_dict()) except plaid.ApiException as e: return json.loads(e.body)
def get_holdings(): try: request = InvestmentsHoldingsGetRequest(access_token=access_token) response = client.investments_holdings_get(request) pretty_print_response(response.to_dict()) return jsonify({'error': None, 'holdings': response.to_dict()}) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def get_accounts(): try: request = AccountsGetRequest(access_token=access_token) response = client.accounts_get(request) pretty_print_response(response.to_dict()) return jsonify(response.to_dict()) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def payment(): global payment_id try: request = PaymentInitiationPaymentGetRequest(payment_id=payment_id) response = client.payment_initiation_payment_get(request) pretty_print_response(response.to_dict()) return jsonify({'error': None, 'payment': response.to_dict()}) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def get_identity(): try: request = IdentityGetRequest(access_token=access_token) response = client.identity_get(request) pretty_print_response(response.to_dict()) return jsonify({ 'error': None, 'identity': response.to_dict()['accounts'] }) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def get_transactions(): # Pull transactions for the last 30 days start_date = (datetime.datetime.now() - timedelta(days=30)) end_date = datetime.datetime.now() try: options = TransactionsGetRequestOptions() request = TransactionsGetRequest(access_token=access_token, start_date=start_date.date(), end_date=end_date.date(), options=options) response = client.transactions_get(request) pretty_print_response(response.to_dict()) return jsonify(response.to_dict()) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def item(): try: request = ItemGetRequest(access_token=access_token) response = client.item_get(request) request = InstitutionsGetByIdRequest( institution_id=response['item']['institution_id'], country_codes=list( map(lambda x: CountryCode(x), PLAID_COUNTRY_CODES))) institution_response = client.institutions_get_by_id(request) pretty_print_response(response.to_dict()) pretty_print_response(institution_response.to_dict()) return jsonify({ 'error': None, 'item': response.to_dict()['item'], 'institution': institution_response.to_dict()['institution'] }) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def transfer(): global transfer_id try: request = TransferGetRequest(transfer_id=transfer_id) response = client.transfer_get(request) pretty_print_response(response.to_dict()) return jsonify({ 'error': None, 'transfer': response['transfer'].to_dict() }) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)
def create_link_token(): try: request = LinkTokenCreateRequest( products=products, client_name="Plaid Quickstart", country_codes=list( map(lambda x: CountryCode(x), PLAID_COUNTRY_CODES)), language='en', user=LinkTokenCreateRequestUser(client_user_id=str(time.time()))) # create link token response = client.link_token_create(request) return jsonify(response.to_dict()) except plaid.ApiException as e: return json.loads(e.body)
def get_assets(): try: request = AssetReportCreateRequest( access_tokens=[access_token], days_requested=60, options=AssetReportCreateRequestOptions( webhook='https://www.example.com', client_report_id='123', user=AssetReportUser( client_user_id='789', first_name='Jane', middle_name='Leah', last_name='Doe', ssn='123-45-6789', phone_number='(555) 123-4567', email='*****@*****.**', ))) response = client.asset_report_create(request) pretty_print_response(response.to_dict()) asset_report_token = response['asset_report_token'] except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response) # Poll for the completion of the Asset Report. num_retries_remaining = 20 asset_report_json = None while num_retries_remaining > 0: try: request = AssetReportGetRequest( asset_report_token=asset_report_token, ) response = client.asset_report_get(request) asset_report_json = response['report'] break except plaid.ApiException as e: response = json.loads(e.body) if response['error_code'] == 'PRODUCT_NOT_READY': num_retries_remaining -= 1 time.sleep(1) continue error_response = format_error(e) return jsonify(error_response) if asset_report_json is None: return jsonify({ 'error': { 'status_code': e.status, 'display_message': 'Timed out when polling for Asset Report', 'error_code': '', 'error_type': '' } }) asset_report_pdf = None try: request = AssetReportPDFGetRequest( asset_report_token=asset_report_token, ) pdf = client.asset_report_pdf_get(request) return jsonify({ 'error': None, 'json': asset_report_json.to_dict(), 'pdf': base64.b64encode(pdf.read()).decode('utf-8'), }) except plaid.ApiException as e: error_response = format_error(e) return jsonify(error_response)