【问题标题】:Braintree payment nodeJS paymentMethodNonceBraintree 支付节点JS paymentMethodNonce
【发布时间】:2017-04-15 11:31:42
【问题描述】:

大家好,

我正在尝试使用 NodeJs 锻炼 Braintree 支付系统。该视图使用 HandleBars (HBS) 呈现,然后在提交时在 payment.js 中处理付款。我的问题是,通过信用卡或贝宝容器支付的braintree付款不显示。我不确定是不是因为 HBS 不支持脚本标签,但我需要获取 paymentMethodNonce 代码,然后注入到 payment.js 文件中

下面是视图文件

payment.hbs 文件

<h1> This package will cost you 7$ </h1>
<h3> You can pay via credit card or using paypal </h3>
            <form action="/pickup/payment/process" method="post">
            <fieldset>
                <div class="pure-g">
                </div>

                <br>

                <div id="checkout"></div>

                <b

    utton class="btn-submit" type="submit">Pay now</button>

                </fieldset>
            </form>
        </div>
        <br>
    <br><br>


    <script src="https://js.braintreegateway.com/js/braintree-2.27.0.min.js"></script>
        <script>
            braintree.setup('<%- clientToken %>', 'dropin', {
                container: 'checkout'
            });
        </script>

        <a href="https://www.braintreegateway.com/merchants/ID/verified" target="_blank">
      <img src="https://s3.amazonaws.com/braintree-badges/braintree-badge-wide-dark.png" width="280px" height ="44px" border="0"/>

  </a>

payment.js 文件

var express = require('express');
var router = express.Router();
var braintree = require('braintree');

var bodyParser = require('body-parser');


var parseUrlEnconded = bodyParser.urlencoded({
});


var util = require('util'),
    braintree = require('braintree');

var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: '[...]',
  publicKey: '[...]',
  privateKey: '[...]'
});

gateway.transaction.sale({
  amount: '7.00',  extended: false

  paymentMethodNonce: "nonce-from-the-client",
  options: {
    submitForSettlement: true
  }
},
  function(err, result) {
    if (result) {
      if (result.success) {
        console.log("Transaction ID: " + result.transaction.id)
      } else {
        console.log(result.message)
      }
    } else {
      console.log(err)
    }
});

任何帮助将不胜感激。如有任何澄清,请告诉我。

【问题讨论】:

  • 来自docs,看来你需要&lt;input type="hidden" name="payment-method-nonce"&gt;
  • 谢谢你,我认为添加输入可以建立这些页面之间的链接,但我的主要问题是视图中包含的支付容器在启动时不显示。唯一出现的是 Braintree 徽标
  • 您可以通过右键单击查看该元素发生了什么 -> Inspect Element
  • 完全披露:我在 Braintree 工作。看起来这里发生了几件不同的事情。联系Braintree's support team 可能会更好。

标签: javascript node.js paypal handlebars.js braintree


【解决方案1】:

只有在提供 clientToken 时才会加载 Dropin UI。您必须在 payment.js 后端添加新方法以生成客户端令牌。从您的前端调用此方法并传递 clientToken。

btClientToken:function(req,res){

        gateway.clientToken.generate({}, function (err, response) {
            if(err){
                res.status(400).json({'message':err});
            }else{
                res.status(200).json({clientToken: response.clientToken});
            }
        });
    }

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 2016-05-20
    • 2018-10-26
    • 2017-01-02
    • 2016-06-17
    • 2017-09-25
    • 1970-01-01
    • 2018-07-27
    • 2016-01-20
    相关资源
    最近更新 更多