分析服务器云代码和条纹 [英] Parse-Server Cloud-Code and Stripe
问题描述
我为Heroku上的移动网络应用程序运行Parse-Server实例。我的问题是Stripe checkout插件在我的html页面中工作正常,但是当创建标记并且我打电话给我的Cloud Code时,似乎创建变量初始化条带不起作用。这是我的云代码。
I'm running a Parse-Server instance for a mobile web-app on Heroku. My problem is Stripe checkout plugin is working fine in my html page, but when the token is created and I call my Cloud Code it seems as if creating the variable initializing stripe does nothing. This is my cloud code.
var stripe = require('stripe')('sk_test_******');
Parse.Cloud.define("pay", function(req, res){
Parse.Cloud.useMasterKey();
var token = req.params.token;
var amount = req.params.amount;
var email = req.params.email;
// stripe is null
res.success(stripe);
});
在调用此函数时,stripe的值为空,我找不到原因。我在我的package.json文件中添加了stripe:'〜4.7.0',并运行npm install来在本地创建所有节点模块。我不知道它是否有所作为,但在我的index.js文件中,我创建了一个路由器
Upon calling this, the value of stripe is null and I cannot figure out why. I have added stripe: '~4.7.0' in my package.json file and have run npm install to locally create all node modules. I don't know if it makes a difference but in my index.js file I have created a router
app.use('/', express.static(path.join(__dirname, '/public')));
,因为通过这种方式访问公共目录中的文件更容易。否则,我将不得不在我的公共目录中用/ public / filename引用文件,每次我想包含该文件。任何帮助将不胜感激。
because it's easier to access files in the public directory this way. Otherwise I would have to reference files in my public directory with /public/filename everytime I wanted to include that file. Any help would be much appreciated.
推荐答案
我放弃了在Cloud Code中运行此费用。相反,我在我的index.js文件中创建了一个路由'/ charge',并使用jQuery post进行调用。这里是我在index.js中的代码
I gave up trying to run this charge in Cloud Code. Instead I created a route '/charge' in my index.js file and called it using a jQuery post. Here is my code in index.js
var stripe = require('stripe')('sk_test_****');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: false
}));
app.post('/charge', function(req, res){
var token = req.body.token;
var amount = req.body.amount;
stripe.charges.create({
amount: amount,
currency: 'usd',
source: token,
}, function(err, charge){
if(err)
// Error check
else
res.send('Payment successful!');
}
});
这是我的jQuery请求
Here is my jQuery request
var handler = StripeCheckout.configure({
key: 'pk_test_****',
locale: 'auto',
token: function(token){
$.post('/charge', {
token: token.id,
amount: total,
}, function(data, status){
alert(data);
});
}
});
这篇关于分析服务器云代码和条纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!