解析服务器云代码Node.js兼容性
Parse Server Cloud Code Node.js compatibility
我正在尝试开发一个电子商务iOS应用程序。
我想知道是否有可能使用解析服务器+条纹来创建这个。我需要服务器端代码来创建客户、向客户收费等。
我可以在我的云代码中获得类似的功能吗?
// Using Express (http://expressjs.com/)
app.get('/customer', function(request, response) {
var customerId = '...'; // Load the Stripe Customer ID for your logged in user
stripe.customers.retrieve(customerId, function(err, customer) {
if (err) {
response.status(402).send('Error retrieving customer.');
} else {
response.json(customer);
}
})
});
你可以在解析服务器中使用stripe node.js模块。
首先你需要使用 安装模块npm install stripe
或将其添加到package.js文件
...
"dependencies": {
"express": "^4.13.4",
"parse-server": "^2.2.19",
"stripe": "^4.11.0",
...
然后,在你的cloud/main.js文件中,你可以编写一个iOS应用程序可以调用的函数
Parse.Cloud.define("yourCloudFunctionName", function(request, response){
// You can retreive the user info from your request.params
var user = request.params.user;
// Call your stripe package using your API key
var stripe = require('stripe')(' your stripe API key ');
var email = request.params.email;
// Maybe you want to create a customer using the parse email?
stripe.customers.create(
{ email: email },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
// You'll need to return something to the iOS code...
if(err) return err;
else return customer;
}
);
在iOS端,你可以这样调用这个函数:
[PFCloud callFunctionInBackground:@"yourCloudFunctionName"
withParameters:@{@"parameterKey": @"parameterValue"}
block:^(NSArray *results, NSError *error) {
if (!error) {
// this is where you handle the results and change the UI.
}
}];
你想要发送一些用户信息到@"parameterKey": @"parameterValue"
关于分条节点模块的更多信息请点击这里。
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- 如何使用 node.js 比较两个 json 数组
- Node.js's Buffer.writeFloatBE in Javascript
- node.js:setInterval()正在跳过调用
- 如何处理node.js节点mongodb中的连接和查询队列
- Node.js正在更改应用程序以使用集群模块
- 如何使用Node.js最有效地解析网页
- 在openshift node js应用程序中获取请求
- 正在删除node.js中已验证的网站
- 与运行长作业(javascript,node.js)的第三方API同步的最佳实践
- 在索引.html和应用.js [node.js] 之间共享变量
- Node.js中的JavaScript原型对象效率
- node.js请求数据事件未在CORS ajax调用中触发
- 使用node.js制作网站
- 使用node.js服务器中的evernote api获取note内容
- 有没有任何方法可以使用node-js从不同的机器打开浏览器
- 使用CI和CodeDeploy对node.js应用程序进行连续部署
- 在Node.js中上传和检索图像
- 什么's本地node.js服务器和python简单http服务器之间的区别
- 如何使用 Node JS 获取 JSON 嵌套数组值