简体   繁体   English

在angularJS / NodeJS中使用条带支付方法Stripe.charges.create({})时,“未捕获的TypeError:无法读取未定义的属性'create'”

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

Hello I am new to AngularJS and working on a project where i am creating a payment form with stripe. 您好,我是AngularJS的新手,正在从事一个我正在创建带条纹付款表格的项目。 I have create the form and create my JS code as described in the stripe's website. 我已经创建了表单,并按照条纹网站中的描述创建了我的JS代码。 I am getting true response for card verification but payment method gives me this error on console "Uncaught TypeError: Cannot read property 'create' of undefined", 我得到了卡验证的真实响应,但是付款方式在控制台“未捕获的TypeError:无法读取未定义的属性'create'”上给我这个错误,

Following is my HTML code: 以下是我的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>

and this the JS code: 这是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'); 
            });
       }
    }

Looks like you're trying to process the charge on the client side. 看起来您正在尝试在客户端处理费用。 But the documentation states: 但是文档指出:

Use Stripe's API and your server-side code to process charges. 使用Stripe的API和您的服务器端代码来处理费用。

The client side library is different from the NodeJS library. 客户端库与NodeJS库不同。 You're trying to call stripe.charges on the client library that doesn't exist. 您正在尝试在不存在的客户端库上调用stripe.charges This logic should be created on the Server side. 此逻辑应在服务器端创建。

If you check the source code for the Client side library here you will see that the charges object doesn't exist. 如果您在此处检查客户端库的源代码,您将看到charges对象不存在。

Instead, it's available here in the NodeJS library 相反,它是可以在这里的图书馆的NodeJS

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Stripe API:没有ID为X的标记(stripe.charges.create) - Stripe API: There is no token with ID X (stripe.charges.create) 未捕获的类型错误:无法读取条带支付的 null 属性“提交” - Uncaught TypeError: Cannot read property 'submit' of null for stripe payment stripe.js:调用stripe.charges.create的api调用未返回响应 - stripe.js: api call that calls stripe.charges.create isn't returning a response stripe 使用 nodeJS 创建支付意图 - stripe create payment intent with nodeJS Gatsby、Stripe:创建按钮源代码返回“未捕获的类型错误:无法读取未定义的属性‘配置’” - Gatsby, Stripe: Creating a button source code returns 'Uncaught TypeError: Cannot read property 'configure' of undefined' 未被捕获的TypeError:无法读取属性-Stripe API的JQUERY - Uncaught TypeError: Cannot read property — JQUERY for Stripe API 未捕获(承诺):TypeError:无法读取未定义的属性“创建”(ionic 3.9,Angularjs 5.0.3) - Uncaught (in promise): TypeError: Cannot read property 'create' of undefined (ionic 3.9 , Angularjs 5.0.3) 未处理的拒绝(TypeError):无法读取未定义的 Stripe Javascript 的属性“id” - Unhandled Rejection (TypeError): Cannot read property 'id' of undefined Stripe Javascript 类型错误:无法读取未定义的属性“forEach”(节点 js、stripe、express) - TypeError: Cannot read property 'forEach' of undefined (node js, stripe, express) Extjs5 treepanel [未捕获的TypeError:无法读取未定义的属性&#39;create&#39;] - Extjs5 treepanel [Uncaught TypeError: Cannot read property 'create' of undefined]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM