Beispiel #1
0
    def write(self, transactions: List[TransactionBase]):
        with openapi_client.ApiClient(self.configuration) as api_client:
            # Create an instance of the API class
            transaction_api = openapi_client.TransactionsApi(api_client)
            account_api = openapi_client.AccountsApi(api_client)
            try:
                accounts = account_api.get_accounts("last-used")
                accounts = accounts.data.accounts
                account: Account = list(
                    filter(
                        lambda account: account.name == 'Robinhood Unlinked',
                        accounts))[0]
                transactions = [
                    SaveTransaction(
                        account_id=account.id,
                        date=transaction.transaction_date.isoformat(),
                        amount=transaction.amount,
                        memo=transaction.category,
                        payee_name=transaction.payee)
                    for transaction in transactions
                ]
                data = SaveTransactionsWrapper(transactions=transactions)
                transaction_api.create_transaction('last-used', data)

            except ApiException as e:
                print(
                    "Exception when calling AccountsApi->get_account_by_id: %s\n"
                    % e)
Beispiel #2
0
def update_transaction(req):
    # Create an instance of the API class
    api_instance = openapi_client.TransactionsApi()

    authenticated, token = get_client_credentials(PAYMENT_SVC_AUTH_URL,
                                                  PAYMENT_SVC_AUTH_CLIENT_ID,
                                                  PAYMENT_SVC_CLIENT_SECRET)
    if not authenticated:
        raise SBCPaymentException(message=MSG_CLIENT_CREDENTIALS_REQ_FAILED)
    set_api_client_auth_header(api_instance, token)

    # Set API host URI
    set_api_client_request_host(api_instance, PAYMENT_SVC_URL)

    try:
        # Update a transaction
        api_response = api_instance.update_transaction(
            req.payment_identifier, req.receipt_number,
            req.transaction_identifier)

        pprint(api_response)
        return api_response

    except ApiException as err:
        print(
            "Exception when calling TransactionsApi->update_transaction: %s\n"
            % err)
        err_response = json.loads(err.body)
        message = ''
        if err_response.get('detail'):
            message = err_response.get('detail')
        elif err_response.get('message'):
            message = err_response.get('message')
        raise SBCPaymentException(err, message=message)

    except Exception as err:
        print(
            "Exception when calling TransactionsApi->update_transaction: %s\n"
            % err)
        raise SBCPaymentException(err)