Meteorjs:条纹结帐错误
Meteorjs: Stripe Checkout error
我在 Stripe 结帐时不断从服务器收到交易错误,我遵循本教程 (http://www.wsvincent.com/meteor-stripe-checkout/)
虽然一直报异常,但是交易是在Stripe中注册的,说明没问题,但我只想知道这个错误是怎么回事?
Template.bookingPost2.events({
"click #accept": function(event, template){
event.preventDefault();
StripeCheckout.open({
key: 'public_key',
amount: 5000, // this is equivalent to
name: 'Meteor Tutorial',
description: 'On how to use Stripe (.00)',
panelLabel: 'Pay Now',
token: function(res) {
stripeToken = res.id;
console.info(res);
Meteor.call('chargeCard', stripeToken);
}
});
}
});
服务器端
Meteor.methods({
'chargeCard': function(stripeToken) {
check(stripeToken, String);
var Stripe = StripeAPI('secret_key');
Stripe.charges.create({
source: stripeToken,
amount: 5000, // this is equivalent to
currency: 'usd'
}, function(err, charge) {
console.log(err, charge);
});
}
});
错误消息
Exception while simulating the effect of invoking 'chargeCard' ReferenceError: StripeAPI is not defined
at Meteor.methods.chargeCard (http://localhost:3000/lib/collections/stripeStuff.js?c2bc7ea1ef220be9a0448871dc837fcc30c64138:4:20)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4269:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4260:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4138:17)
at TokenCallback.StripeCheckout.open.token [as fn] (http://localhost:3000/client/helper/booking2.js?49ebf774558be893cec6b35973bdb33ebfc76887:22:16)
at TokenCallback.trigger (https://checkout.stripe.com/checkout.js:2:13749)
at TokenCallback.__bind [as trigger] (https://checkout.stripe.com/checkout.js:2:13081)
at IframeView.onToken (https://checkout.stripe.com/checkout.js:2:11783)
at IframeView.closed (https://checkout.stripe.com/checkout.js:2:18825) ReferenceError: StripeAPI is not defined
at Meteor.methods.chargeCard (http://localhost:3000/lib/collections/stripeStuff.js?c2bc7ea1ef220be9a0448871dc837fcc30c64138:4:20)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4269:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4260:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4138:17)
at TokenCallback.StripeCheckout.open.token [as fn] (http://localhost:3000/client/helper/booking2.js?49ebf774558be893cec6b35973bdb33ebfc76887:22:16)
at TokenCallback.trigger (https://checkout.stripe.com/checkout.js:2:13749)
at TokenCallback.__bind [as trigger] (https://checkout.stripe.com/checkout.js:2:13081)
at IframeView.onToken (https://checkout.stripe.com/checkout.js:2:11783)
at IframeView.closed (https://checkout.stripe.com/checkout.js:2:18825)
看起来您的服务器端方法位于共享(客户端+服务器)目录中。确保它位于 server
文件夹中或包裹在 if (Meteor.isServer){}
块中。看看能不能解决问题。
(请注意,您的 Stripe 密钥不应在客户端公开)。
我在 Stripe 结帐时不断从服务器收到交易错误,我遵循本教程 (http://www.wsvincent.com/meteor-stripe-checkout/)
虽然一直报异常,但是交易是在Stripe中注册的,说明没问题,但我只想知道这个错误是怎么回事?
Template.bookingPost2.events({
"click #accept": function(event, template){
event.preventDefault();
StripeCheckout.open({
key: 'public_key',
amount: 5000, // this is equivalent to
name: 'Meteor Tutorial',
description: 'On how to use Stripe (.00)',
panelLabel: 'Pay Now',
token: function(res) {
stripeToken = res.id;
console.info(res);
Meteor.call('chargeCard', stripeToken);
}
});
}
});
服务器端
Meteor.methods({
'chargeCard': function(stripeToken) {
check(stripeToken, String);
var Stripe = StripeAPI('secret_key');
Stripe.charges.create({
source: stripeToken,
amount: 5000, // this is equivalent to
currency: 'usd'
}, function(err, charge) {
console.log(err, charge);
});
}
});
错误消息
Exception while simulating the effect of invoking 'chargeCard' ReferenceError: StripeAPI is not defined
at Meteor.methods.chargeCard (http://localhost:3000/lib/collections/stripeStuff.js?c2bc7ea1ef220be9a0448871dc837fcc30c64138:4:20)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4269:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4260:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4138:17)
at TokenCallback.StripeCheckout.open.token [as fn] (http://localhost:3000/client/helper/booking2.js?49ebf774558be893cec6b35973bdb33ebfc76887:22:16)
at TokenCallback.trigger (https://checkout.stripe.com/checkout.js:2:13749)
at TokenCallback.__bind [as trigger] (https://checkout.stripe.com/checkout.js:2:13081)
at IframeView.onToken (https://checkout.stripe.com/checkout.js:2:11783)
at IframeView.closed (https://checkout.stripe.com/checkout.js:2:18825) ReferenceError: StripeAPI is not defined
at Meteor.methods.chargeCard (http://localhost:3000/lib/collections/stripeStuff.js?c2bc7ea1ef220be9a0448871dc837fcc30c64138:4:20)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4269:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4260:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4138:17)
at TokenCallback.StripeCheckout.open.token [as fn] (http://localhost:3000/client/helper/booking2.js?49ebf774558be893cec6b35973bdb33ebfc76887:22:16)
at TokenCallback.trigger (https://checkout.stripe.com/checkout.js:2:13749)
at TokenCallback.__bind [as trigger] (https://checkout.stripe.com/checkout.js:2:13081)
at IframeView.onToken (https://checkout.stripe.com/checkout.js:2:11783)
at IframeView.closed (https://checkout.stripe.com/checkout.js:2:18825)
看起来您的服务器端方法位于共享(客户端+服务器)目录中。确保它位于 server
文件夹中或包裹在 if (Meteor.isServer){}
块中。看看能不能解决问题。
(请注意,您的 Stripe 密钥不应在客户端公开)。