Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Stripe接受比特币和美元付款?_Javascript_Node.js_Stripe Payments_Bitcoin - Fatal编程技术网

Javascript 如何使用Stripe接受比特币和美元付款?

Javascript 如何使用Stripe接受比特币和美元付款?,javascript,node.js,stripe-payments,bitcoin,Javascript,Node.js,Stripe Payments,Bitcoin,参考资料: 问题: 我正在尝试使用Stripe将比特币支付集成到我的代码中 根据我对文档的理解,我应该通过创建一个新表单创建一个源对象,并在提交时将数据(在本例中为电子邮件和金额)馈送至: 然后将结果传递给服务器以对源对象进行收费。唯一的问题:我不知道如何将结果传递给服务器。我应该创建一个新的处理程序吗 var handler = StripeCheckout.configure({ key: 'key', locale: 'auto', name: 'w

参考资料:


问题:

我正在尝试使用Stripe将比特币支付集成到我的代码中

根据我对文档的理解,我应该通过创建一个新表单创建一个源对象,并在提交时将数据(在本例中为电子邮件和金额)馈送至:

然后将结果传递给服务器以对源对象进行收费。唯一的问题:我不知道如何将结果传递给服务器。我应该创建一个新的处理程序吗

var handler = StripeCheckout.configure({
      key: 'key',
      locale: 'auto',
      name: 'website',
      description: 'Secure Payment',
      token: function(token) {
        $('#stripeToken').val(token.id);
        $("#stripeEmail").val(token.email);
        $('form').submit();
      }                                    
    });
我迷路了

这是我目前拥有的代码,它非常适合美元支付


我的代码:

客户端(payment.ejs)

感谢来自freenode IRC#stripe的“pksk321”为我提供的帮助

显然,所需要的只是将
比特币:true
添加到处理程序中,如下所示:

客户端

var handler = StripeCheckout.configure({
      key: 'key',
      locale: 'auto',
      name: 'website',
      description: 'Secure Payment',
      bitcoin: true,
      token: function(token) {
        $('#stripeToken').val(token.id);
        $("#stripeEmail").val(token.email);
        $('form').submit();
      }                                    
    });

您的问题部分不包含问题!定义“奋斗”。这句话模糊不清,毫无意义。我们不能从中推断出你的处境。上面的代码出了什么问题?查看并澄清您的问题。我们不关心您的HTML,它是您构建前端的一部分;如果你正在为API或其他问题而挣扎,那就是你必须关注的问题,不要包含不相关的信息。你不清楚的是什么?我建议你费心阅读文档。我知道这很烦人也很累,但这是开发某些东西的实际方式。如果你发现一个特定的问题或不知道如何做某事,你可以发布一个问题。但是,如果我最初的问题给人留下了这样的印象,请不要只是说‘我不能这样做,请为我做’@J.C.Rocamonde向我道歉。问题编辑。
<% include partials/header %>
<div class="background">
    <div class="message">
        <div class="paymentBlock">
            <h1 class="title">TITLE</h1>

            <form class="paymentForm" action="/payment/charge" method="POST">  
                <input id="inputAmount" class="amountInput" name="amount" type="number/>
                <input type="hidden" id="stripeToken" name="stripeToken" />
                <input type="hidden" id="stripeEmail" name="stripeEmail"/>
                <button type="submit" class="btn btn-success" id="paymentButton" >Submit Payment</button>
            </form>
        </div>
    </div>
</div>

<script src="https://checkout.stripe.com/checkout.js"></script>

<script>

    var handler = StripeCheckout.configure({
      key: 'key',
      locale: 'auto',
      name: 'website',
      description: 'Secure Payment',
      token: function(token) {
        $('#stripeToken').val(token.id);
        $("#stripeEmail").val(token.email);
        $('form').submit();
      }                                    
    });

    $('#paymentButton').on('click', function(e) {
      e.preventDefault();

      $('#error_explanation').html('');

      var amount = $('#inputAmount').val();
      amount = amount.replace(/\$/g, '').replace(/\,/g, '');

      amount = parseFloat(amount);

      if (isNaN(amount)) {
        $('#error_explanation').html('<p>Please enter a valid amount in USD ($).</p>');
      }
      else if (amount < 1.00) {
        $('#error_explanation').html('<p>Payment amount must be at least $1.</p>');
      }
      else {
        amount = amount * 100;
        handler.open({
          amount: Math.round(amount)
        })
      }
    });
    // Close Checkout on page navigation
    $(window).on('popstate', function() {
      handler.close();
    });
</script>

<% include partials/indexScripts %>
router.post("/", (req, res) => {

    var amount = req.body.amount;
    var object;
    var ARef = admin.database().ref("ref");
    var ARefList;
    amount = amount * 100; 

    var object = {
        amount: amount,
        email: email,
        inversedTimeStamp: now
    }

    stripe.customers.create({
        email: req.body.stripeEmail,
        source: req.body.stripeToken
    })
    .then(customer =>
        stripe.charges.create({
            amount: amount,
            description: "desc",
            currency: "usd",
            customer: customer.id
        })
    )
    .then(charge => 
        ARef.transaction(function(dbAmount){  
            if (!dbAmount) { 
              dbAmount = 0; 
            } 
            dbAmount = dbAmount + amount/100; 
            return dbAmount; 
        })
    )
    .then( () =>
        ARef.push(object)
    )
    .then ( () =>
        ARefList.push(object)
    )
    .then( () =>
        res.render("received",{amount:amount/100})
    );
});
var handler = StripeCheckout.configure({
      key: 'key',
      locale: 'auto',
      name: 'website',
      description: 'Secure Payment',
      bitcoin: true,
      token: function(token) {
        $('#stripeToken').val(token.id);
        $("#stripeEmail").val(token.email);
        $('form').submit();
      }                                    
    });