stripe.js createToken出现奇怪错误(Hot to use createToken with stripe.js [LEGACY])

我正在将stripe.js集成到我的应用程序中。 我做的事情如下:

var tokenDetails = { number: $('#cnumber').val(), exp_month: $('#expmonth').val(), exp_year: $('#expyear').val(), cvc: $('#cvc').val() }; Stripe.createToken(tokenDetails, myCallback);

这确实启动了对stripe的调用以创建令牌,但是,我收到以下错误:

{ "error": { "message": "Invalid amount. Amount must be an integer in cents.", "param": "amount", "type": "invalid_request_error" } }

文档没有说需要“金额”字段来获取信用卡详细信息的令牌? 这需要吗? 在这种情况下,我将获取令牌,然后将用户添加到带有条带的定期计划中。 任何人都知道这个错误吗?

I'm in the process of integrating stripe.js into my app. I'm doing something like:

var tokenDetails = { number: $('#cnumber').val(), exp_month: $('#expmonth').val(), exp_year: $('#expyear').val(), cvc: $('#cvc').val() }; Stripe.createToken(tokenDetails, myCallback);

This does initiate the call to stripe to create the token, however, I'm getting the following error back:

{ "error": { "message": "Invalid amount. Amount must be an integer in cents.", "param": "amount", "type": "invalid_request_error" } }

The docs don't say anything about needing an "amount" field to get a token for the credit card details? Is this required? In this case I'm going to take the token, then add the user to a a recurring plan with stripe. Anyone know anything about this error?

EDIT:

The callback function must be present, and I wasn't passing it correctly.

最满意答案

在这里找到了问题。 显然,Stripe.createToken()函数采用各种类型的第二个参数。 如果它是一个函数,则将其作为标记化过程的回调调用。 如果它不是一个函数,它被认为是金额(我认为)。

在我的例子中,回调函数是未定义的(错误的命名空间),因此createToken函数假定它是一个金额,它无法做任何事情,因此错误。

修复...确保回调函数存在。

Found out the issue here. Apparently the Stripe.createToken() function takes various types of second argument. If it's a function, it's invoked as the callback to the tokenization process. If it's not a function it's assumed to be the amount (I think).

In my case, the callback function was undefined (wrong namespace) so the createToken function assumes it's an amount, which it couldn't do anything with, thus the error.

The fix...make sure the callback function exists.

stripe.js createToken出现奇怪错误(Hot to use createToken with stripe.js [LEGACY])

我正在将stripe.js集成到我的应用程序中。 我做的事情如下:

var tokenDetails = { number: $('#cnumber').val(), exp_month: $('#expmonth').val(), exp_year: $('#expyear').val(), cvc: $('#cvc').val() }; Stripe.createToken(tokenDetails, myCallback);

这确实启动了对stripe的调用以创建令牌,但是,我收到以下错误:

{ "error": { "message": "Invalid amount. Amount must be an integer in cents.", "param": "amount", "type": "invalid_request_error" } }

文档没有说需要“金额”字段来获取信用卡详细信息的令牌? 这需要吗? 在这种情况下,我将获取令牌,然后将用户添加到带有条带的定期计划中。 任何人都知道这个错误吗?

I'm in the process of integrating stripe.js into my app. I'm doing something like:

var tokenDetails = { number: $('#cnumber').val(), exp_month: $('#expmonth').val(), exp_year: $('#expyear').val(), cvc: $('#cvc').val() }; Stripe.createToken(tokenDetails, myCallback);

This does initiate the call to stripe to create the token, however, I'm getting the following error back:

{ "error": { "message": "Invalid amount. Amount must be an integer in cents.", "param": "amount", "type": "invalid_request_error" } }

The docs don't say anything about needing an "amount" field to get a token for the credit card details? Is this required? In this case I'm going to take the token, then add the user to a a recurring plan with stripe. Anyone know anything about this error?

EDIT:

The callback function must be present, and I wasn't passing it correctly.

最满意答案

在这里找到了问题。 显然,Stripe.createToken()函数采用各种类型的第二个参数。 如果它是一个函数,则将其作为标记化过程的回调调用。 如果它不是一个函数,它被认为是金额(我认为)。

在我的例子中,回调函数是未定义的(错误的命名空间),因此createToken函数假定它是一个金额,它无法做任何事情,因此错误。

修复...确保回调函数存在。

Found out the issue here. Apparently the Stripe.createToken() function takes various types of second argument. If it's a function, it's invoked as the callback to the tokenization process. If it's not a function it's assumed to be the amount (I think).

In my case, the callback function was undefined (wrong namespace) so the createToken function assumes it's an amount, which it couldn't do anything with, thus the error.

The fix...make sure the callback function exists.