douglasrcjames
douglasrcjames

Reputation: 1645

TypeError: Cannot read property 'list' of undefined of balanceTransactions

I am trying to display the balance from a Stripe customer or Connect account, but am getting the error TypeError: Cannot read property 'list' of undefined. The user has just one charge on their account, and it still throws error that it is undefined.

I am likely just misunderstanding the API, but there are not any examples I can find when trying to do this. How do I simply display all balance transactions for a given customer?

Code:

import React, { Component } from 'react'
import { injectStripe } from 'react-stripe-elements';

class Balance extends Component {

    componentDidMount(){
        if (this.props.stripe) {
            this.props.stripe.balanceTransactions.list({ limit: 3 }, function(error, transactions) {
                if(error){
                    console.error(error)
                } else {
                    console.log(transactions)
                }

            });
        }
    }

    render() {
        return (
            <div>
                Display Balance here
            </div>
        )
    }
}

export default injectStripe(Balance);

Upvotes: 0

Views: 1047

Answers (2)

Evgenii Malikov
Evgenii Malikov

Reputation: 437

Quote from react-stripe-elements readme:

Within an injected component, you can call any of the following:

this.props.stripe.createPaymentMethod
this.props.stripe.createToken
this.props.stripe.createSource
this.props.stripe.handleCardPayment

So you're using a wrong library.

The correct library is stripe-node

Upvotes: 2

Vencovsky
Vencovsky

Reputation: 31565

To remove the error, you should do a check in stripe.balanceTransactions.

componentDidMount(){
    if (this.props.stripe && this.props.stripe.balanceTransactions) {
        this.props.stripe.balanceTransactions.list({ limit: 3 }, function(error, transactions) {
            if(error){
                console.error(error)
            } else {
                console.log(transactions)
            }

        });
    }
}

And also, if you take a look in the documentation, injectStripe doesn't give stripe.balanceTransactions prop.

These are the only methods you can call

  • this.props.stripe.createPaymentMethod
  • this.props.stripe.createToken
  • this.props.stripe.createSource
  • this.props.stripe.handleCardPayment

Upvotes: 1

Related Questions