简体   繁体   English

Braintree付款节点JS paymentMethodNonce

[英]Braintree payment nodeJS paymentMethodNonce

Good day everyone, 今天是个好日子,

I am trying to workout Braintree payment system using NodeJs. 我正在尝试使用NodeJ锻炼Braintree支付系统。 The view is rendered using HandleBars (HBS), and then upon submision the payment is processed in payment.js. 该视图使用HandleBars(HBS)呈现,然后在付款后在Payment.js中处理付款。 My issue is in the view, the braintree payment by credit card or by paypal container does not display. 我的问题是在视图中,不显示通过信用卡或贝宝容器进行的Braintree付款。 I am not sure if its because HBS does not support script tags, but i need to grab the paymentMethodNonce code and then inject into payment.js file 我不确定是否是因为HBS不支持脚本标签,但是我需要获取paymentMethodNonce代码,然后将其注入payment.js文件

Below is the view file 下面是查看文件

payment.hbs file 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 file 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)
    }
});

Any help will be appreciated. 任何帮助将不胜感激。 For any clarification, let me know. 如有任何澄清,请通知我。

Dropin UI will load only when clientToken is provided. 仅当提供clientToken时,Dropin UI才会加载。 You must add new method at payment.js backend to generate client token. 您必须在Payment.js后端添加新方法以生成客户令牌。 Call this method from your frontend and pass clientToken. 从前端调用此方法并传递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});
            }
        });
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM