我已按照this的答案回答了链接中的一个或多个教程,以便使用Firebase设置数据条。服务器已安装,并且可以在Web浏览器(index.hmlt页面)中正常工作。但是,当我尝试在iOS应用程序中使用Stripe时,会收到以下错误消息(404,如下所示)。
谢谢!
错误:失败:responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(404))
来自MyAPIClinent.swift
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let url = self.baseURL.appendingPathComponent("ephemeral_keys")
Alamofire.request(url, method: .post, parameters: [
"api_version": apiVersion,
"customer_id" : "cus_DDVQ3OSLzdnf4X"
])
.validate(statusCode: 200..<300)
.responseJSON { responseJSON in
print(responseJSON)
switch responseJSON.result {
case .success(let json):
completion(json as? [String: AnyObject], nil)
case .failure(let error):
completion(nil, error)
}
}
来自index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const logging = require('@google-cloud/logging')();
//const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'SEK';
var express = require('express');
var stripe = require('stripe')('MY_SECRET_TOKEN');
var bodyParser = require('body-parser')
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended : true
}))
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.post('/ephemeral_keys', (req, res) => {
var customerId = req.body.customer_id;
var api_version = req.body.api_version;
stripe.ephemeralKeys.create(
{customer : customer_id},
{stripe_version : apiversion}
).then((key) => {
res.status(200).send(key)
}).catch((err) => {
console.log(err)
res.status(500).end()
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});