2017-09-24 106 views
0

我一直在試圖瞭解如何爲我的應用程序設置Stripe,但是在實現模塊時遇到了問題。通常當使用模塊時,我會要求它在文件的頂部能夠使用它,但我不知道如何在paymentController文件中執行此操作,或者我甚至需要。我導入了條紋npm,那我是說我可以在全球範圍內訪問它嗎?就像你看到我對此很新,並且想要了解如何構建這個以便支付工作。節點,模塊使用結構

app.js文件:

angular.module('userApp', ['appRoutes', 'userControllers', 'userServices', 'ngAnimate', 'mainController', 'authServices', 'managementController', 'paymentController']) 

.config(function($httpProvider) { 
    $httpProvider.interceptors.push('AuthInterceptors'); 
}); 

paymentController文件:

angular.module('paymentController', []) 

.controller('paymentCtrl', function($scope) { 

    var app = this; 


}); 

Server.js文件:

var express = require('express'); // ExperssJS Framework 
var app = express(); // Invoke express to variable for use in application 
var port = process.env.PORT || 8080; // Set default port or assign a port in enviornment 
var morgan = require('morgan'); // Import Morgan Package 
var mongoose = require('mongoose'); // HTTP request logger middleware for Node.js 
var bodyParser = require('body-parser'); // Node.js body parsing middleware. Parses incoming request bodies in a middleware before your handlers, available under req.body. 
var router = express.Router(); // Invoke the Express Router 
var appRoutes = require('./app/routes/api')(router); // Import the application end points/API 
var path = require('path'); // Import path module 
var passport = require('passport'); // Express-compatible authentication middleware for Node.js. 
var social = require('./app/passport/passport')(app, passport); // Import passport.js End Points/API 

app.use(morgan('dev')); // Morgan Middleware 
app.use(bodyParser.json()); // Body-parser middleware 
app.use(bodyParser.urlencoded({ extended: true })); // For parsing application/x-www-form-urlencoded 
app.use(express.static(__dirname + '/public')); // Allow front end to access public folder 
app.use('/api', appRoutes); // Assign name to end points (e.g., '/api/management/', '/api/users' ,etc.) 


mongoose.connect('mongodb://localhost:27017/tutorial', function(err) { 
    if (err) { 
    console.log('Not connected to the database: ' + err); 
    } else { 
    console.log('Successfully connected to MongoDB'); 
    } 
}); 

// Set Application Static Layout 
app.get('*', function(req, res) { 
    res.sendFile(path.join(__dirname + '/public/app/views/index.html')); // Set index.html as layout 
}); 

// Start Server 
app.listen(port, function() { 
    console.log('Running the server on port ' + port); // Listen on configured port 
}); 

回答

0

我建議以下哪所示節點在這條真實教程:

https://stripe.com/docs/charges

就像你其他的包括,你想將使用條紋庫的JS文件的開頭是這樣的:在同一個文件

var stripe = require('stripe')('sk_my_secret_key') 

然後,在其他地方,你可以調用任何你需要條紋庫方法:

stripe.charges.create(…) 

當然,在生產中,你會想建立一個合適的12因子的應用[1],並把你的祕密的環境變量或配置文件。

[1] https://12factor.net/config