TypeError:无法读取未定义的balanceTransactions属性“列表”

时间:2019-07-01 19:14:53

标签: node.js reactjs stripe-payments

我正在尝试显示来自Stripe客户或Connect帐户的余额,但是出现错误TypeError: Cannot read property 'list' of undefined。用户帐户上只有一笔费用,但仍然会引发错误,即未定义。

我可能只是误解了API,但是在尝试执行此操作时我找不到任何示例。如何简单地显示给定客户的所有余额交易?

代码:

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);

2 个答案:

答案 0 :(得分:2)

react-stripe-elements自述文件中的语录:

在注入的组件内,您可以调用以下任意项:

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

所以您使用的是错误的库。

正确的库是stripe-node

答案 1 :(得分:1)

要消除该错误,您应该在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)
            }

        });
    }
}

而且,如果您查看documentationinjectStripe不会提供stripe.balanceTransactions道具。

这些是您可以调用的唯一方法

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