我目前正在使用沙箱测试 Braintree API。当我将随机数发布到服务器时,我从 Braintree API 收到消息:需要金额。无法确定付款方式。我发现我可以对随机数使用硬编码值: paymentMethodNonce: "fake-valid-nonce" 在这种情况下,我可以在沙箱中看到交易。但我想查看我在嵌入式用户界面中输入的信用卡。出现“无法确定付款方式”消息的原因可能是什么?我的服务器端node.js代码如下:
var amount = req.body.amount;
// Use the payment method nonce here
var nonceFromTheClient = req.body.paymentMethodNonce;
var newTransaction = gateway.transaction.sale({
amount: amount,
//paymentMethodNonce: "fake-valid-nonce",
paymentMethodNonce: nonceFromTheClient,
options: {
submitForSettlement: true }
}, function(error, result) {
if (result) {
res.send(result);
} else {
res.status(500).send(error);
}
});
Run Code Online (Sandbox Code Playgroud)
我的 Swift 客户端代码:
func sendRequestPaymentToServer(nonce: String, amount: String) {
let paymentURL = URL(string: "http://localhost:5000/checkout")!
var request = URLRequest(url: paymentURL)
request.httpBody = "paymentMethodNonce=\(nonce)&amount=\(amount)".data(using: String.Encoding.utf8)
request.httpMethod = "POST"
URLSession.shared.dataTask(with: …Run Code Online (Sandbox Code Playgroud) 我正在尝试是否有可能将Firebase的Cloud Functions与Braintree集成在一起。我根据docs为Cloud Functions创建了一个项目。在项目目录中,我运行:npm install braintree。我index.js出于测试目的进行了以下修改:
const functions = require('firebase-functions');
var braintree = require("braintree");
var gateway = braintree.connect({
environment:
braintree.Environment.Sandbox,
merchantId: "useYourMerchantId",
publicKey: "useYourPublicKey",
privateKey: "useYourPrivateKey"
});
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-
functions
//
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
//gateway.clientToken.generate({}, function (err, response) {
//response.send(response.clientToken);
//});
});
Run Code Online (Sandbox Code Playgroud)
当我尝试部署此测试功能时,出现错误
错误解析触发器:找不到模块'braintree'
我是Firebase,Cloud Functions和node.js的新手,并且希望获得有关如何将Braintree导入Firebase Functions项目的任何投入。