尝试使用Stripe发送日期付款

时间:2016-08-22 18:14:30

标签: node.js stripe-payments

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

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>

1 个答案:

答案 0 :(得分:1)

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