我试图在console.log中使用token.create发送付款的日期,但返回未定义。我想知道如何创建日期。

app.post('/payments.html', function(req, res) {
    var token = req.body.stripeToken; // Using Express

// Create a charge: this will charge the user's card
    var charge = stripe.charges.create({
        amount: 20000, // Amount in cents
        currency: "usd",
        source: token,
        description: "Example charge"
    }, function(err, charge) {
            if (err && err.type === 'StripeCardError') {
                 // The card has been declined
             }
    });

    console.log(charge.amount);
    stripe.customers.create({
        description: 'customer for..',
        source: token
    }), function(err, customer){
        console.log("error in creating customer" + err);
    }
    console.log(token.created);
    res.sendFile(__dirname + '/views/payments.html');

    });


这是脚本

 <script type="text/javascript">
            // Fill in your publishable key
            Stripe.setPublishableKey('pk_test_SkainfjXuZvik6J2Sg5praOz');

            var stripeResponseHandler = function(status, response) {
              var $form = $('#payment-form');

              if (response.error) {
                // Show the errors on the form
                $form.find('.payment-errors').text(response.error.message);
                $form.find('button').prop('disabled', false);
            } else {
                // token contains id, last4, and card type
                var token = response.id;
                // Insert the token into the form so it gets submitted to the server
                $form.append($('<input type="hidden" name="stripeToken" />').val(token));
                // and re-submit
                $form.get(0).submit();
            }
        };

        jQuery(function($) {
          $('#payment-form').submit(function(e) {
            var $form = $(this);

                // Disable the submit button to prevent repeated clicks
                $form.find('button').prop('disabled', true);

                Stripe.card.createToken($form, stripeResponseHandler);

                // Prevent the form from submitting with the default action
                return false;
            });
      });
        </script>


这是您输入付款明细的表格

 <form action="" method="POST" id="payment-form">
                  <span style="color:red;"class="payment-errors"></span>
                  <div class="form-row">
                    <label>
                    <span>Name</span>
                     <input type="text" size="20" data-stripe="name">
                    </label>
                    <label>
                    <span>Zip Code</span>
                     <input type="text" size="20" data-stripe="address_zip">
                    </label>
                  </div>
                  <div class="form-row">
                    <label>
                      <span>Card Number</span>
                      <input type="text" size="20" data-stripe="number">
                  </label>
              </div>

              <div class="form-row">
                <label>
                    <span>Expiration (MM/YY)</span>
                    <input type="text" size="2" data-stripe="exp_month">
                </label>
                    <span> / </span>
                <label>
                    <input type="text" size="2" data-stripe="exp_year">
                </label>
            </div>


          <div class="form-row">
            <label>
              <span>CVC</span>
              <input type="text" size="4" data-stripe="cvc">
          </label>
      </div>


      <input type="submit" class="submit" value="Submit Payment">
  </form>

最佳答案

您需要确保要发布整个令牌对象,而不仅仅是令牌ID。

关于node.js - 尝试获取使用Stripe发送付款的日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39086148/

10-16 17:58
查看更多