簡體   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

您好,我是AngularJS的新手,正在從事一個我正在創建帶條紋付款表格的項目。 我已經創建了表單,並按照條紋網站中的描述創建了我的JS代碼。 我得到了卡驗證的真實響應,但是付款方式在控制台“未捕獲的TypeError:無法讀取未定義的屬性'create'”上給我這個錯誤,

以下是我的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'); 
            });
       }
    }

看起來您正在嘗試在客戶端處理費用。 但是文檔指出:

使用Stripe的API和您的服務器端代碼來處理費用。

客戶端庫與NodeJS庫不同。 您正在嘗試在不存在的客戶端庫上調用stripe.charges 此邏輯應在服務器端創建。

如果您在此處檢查客戶端庫的源代碼,您將看到charges對象不存在。

相反,它是可以在這里的圖書館的NodeJS

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM