如何在节点js中设置Braintree API?

时间:2017-03-12 05:43:36

标签: javascript node.js express braintree

我想使用braintree网站paymentgateway,不幸的是,当我按照指南在线,&代码无法在节点js中使用。有什么遗失?

Index.js:

//send token to clients

app.get("/client_token", function (req, res) {
  gateway.clientToken.generate({}, function (err, response) {
    res.send(response.clientToken);
  });
});

//Receive payment from clients

app.post("/checkout", function (req, res) {
  var nonceFromTheClient = req.body.payment_method_nonce;
  // Use payment method nonce here
});

//Test sandbox
gateway.transaction.sale({
  amount: "10.00",
  paymentMethodNonce: nonceFromTheClient,
  options: {
    submitForSettlement: true
  }
}, function (err, result) {

  if (err) {
    console.error(err);
    return;
  }

  if (result.success) {
    console.log('Transaction ID: ' + result.transaction.id);
  } else {
    console.error(result.message);
  }
});

错误无法通过节点js npm start:

paymentMethodNonce:nonceFromTheClient,

IDE中的详细信息:

ReferenceError:未定义nonceFromTheClient

at Object.<anonymous> (/Users/desmondkam/codecampvn/index.js:37:23)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:445:3

解决

删除//测试沙箱部分将解决localhost&amp;中编译正常的问题IDE。

为了使用Sandbox运行,需要一些关于以下内容的附加代码:https://developers.braintreepayments.com/reference/general/testing/node

"fake-valid-nonce"

您的代码将是:

gateway.transaction.sale({
  amount: "10.00",
  paymentMethodNonce: "fake-valid-nonce",
  options: {
    submitForSettlement: true
  }
}, function (err, result) {
});

0 个答案:

没有答案