"Uncaught TypeError: Cannot read property 'create' of undefined" while using stripe payment method Stripe.charges.create({}) in angularJS/NodeJS

"Uncaught TypeError: Cannot read property 'create' of undefined" while using stripe payment method Stripe.charges.create({}) in angularJS/NodeJS

你好,我是 AngularJS 的新手,正在从事一个项目,我正在创建一个带条纹的付款表格。我已经按照条纹网站中的描述创建了表单并创建了我的 JS 代码。我收到卡验证的真实响应,但付款方式在控制台 "Uncaught TypeError: Cannot read property 'create' of undefined"、

上给我这个错误

以下是我的 HTML 代码:

<div class="checkout_popup" id="checkout_popup">
    <div class="col-md-12"><h3>Form</h3></div>
    <form id="payment-form" method="post">
    <div class="col-md-12"><input type="email" id="email" placeholder="Email" /></div>
    <div class="col-md-12"><input type="text" id="card-number" data-stripe="number" value="4242424242424242" placeholder="Card Number (16 Digit)"/></div>
    <div class="col-md-12"><input type="text" id="card-cvc" placeholder="cvc" data-stripe="cvc" value="123" /></div>
    <div class="col-md-12"><input type="text" id="card-expiry-month" data-stripe="exp_month" value="12" placeholder="Month Expire" /></div>
    <div class="col-md-12"><input type="text" id="card-expiry-year" data-stripe="exp_year" value="2017" placeholder="Year Expire" /></div>
    <div class="col-md-12"><input type="button" id="pay-now" value="Pay Now" ng-click="submitstripe()" /></div>
    </form>
</div>

这是 JS 代码:

.controller('UserAccountController', function($scope, $http, $state, $stateParams, $filter) {
 $scope.submitstripe = function(){
        console.log('ready stripe');


        Stripe.card.createToken({
        number: document.getElementById('card-number').value,
        cvc: document.getElementById('card-cvc').value,
        exp_month: document.getElementById('card-expiry-month').value,
        exp_year: document.getElementById('card-expiry-year').value
        }, stripeResponseHandler);
        return false;
    };
})

function stripeResponseHandler(status, response) {

        if (response.error) { // Problem!
            console.log(response.error.message);
        } else { // Token was created!
            // Get the token ID:
            var token = response.id;
            // Insert the token into the form so it gets submitted to the server:
            console.log('Credit card verified, your token is : '+token);

            var email = document.getElementById('email').value;

            var charge = Stripe.charges.create({
            amount: 10, // Amount in cents
            currency: "usd",
            source: token,
            description: "test charges"
            }, function(err, charge) {
            if (err && err.type === 'StripeCardError') {
                // The card has been declined
                alert('Your card is not valid');
            }

            document.getElementById('card-number').value = '';
            document.getElementById('card-cvc').value = '';
            document.getElementById('card-expiry-month').value = '';
            document.getElementById('card-expiry-year').value = '';
            document.getElementById('checkout_popup').style.display = 'none';
            alert('payment successfull'); 
            });
       }
    }

您似乎正在尝试在客户端处理费用。但文档指出:

Use Stripe's API and your server-side code to process charges.

客户端库与 NodeJS 库不同。您正在尝试在不存在的客户端库上调用 stripe.charges。此逻辑应在服务器端创建。

如果您检查客户端库 here 的源代码,您会发现 charges 对象不存在。

相反,它在 NodeJS 库here中可用