【问题标题】:Create Stripe source from token issue从令牌问题创建 Stripe 源
【发布时间】:2019-01-12 20:12:48
【问题描述】:

我有一个我正在尝试使用的 Javascript 文件,以从 Stripe 令牌创建一个 Stripe 源。然后能够将该源提交到我的表单,提交表单,然后从表单提交到的 .php 文件创建费用。

我只是在执行此操作时遇到了一些困难,我的控制台中没有出现任何错误,它会按预期创建令牌和源。但是,数据永远不会提交到我的表单,因为页面永远不会重定向,也不会产生任何费用。

我不确定我究竟缺少什么才能使其正常工作。

下面是控制台输出的附加图像。

我目前的代码如下所示。

    Stripe.card.createToken({
            number: document.getElementById('cardNumId').value,
            cvc: document.getElementById('cvcID').value,
            exp_month: document.getElementById('expMonthId').value,
            exp_year: document.getElementById('expYearId').value
    }, stripeResponseHandler);

    var stripeResponseHandler = function(status, response) {

    if (response.error) {

        alert('Something went wrong, sorry!' + error);

    } else {

    var token = response.id;

    form.addEventListener('submit', function(event) {
        event.preventDefault();
    stripe.createSource(source, token).then(function(result) {
    if (result.error) {
      // Inform the user if there was an error
      alert('Something went wrong, sorry!' + error);
    } else {
      // Send the source to your server
      stripeSourceHandler(result.source);

    }
  });
  });

    function stripeSourceHandler(source) {

        // Insert the source ID into the form so it gets submitted to the server
        var form = document.getElementById('payment-form');
        var hiddenInput = document.createElement('input');
        hiddenInput.setAttribute('type', 'hidden');
        hiddenInput.setAttribute('name', 'stripeSource');
        hiddenInput.setAttribute('value', source.id);
        form.appendChild(hiddenInput);

        // Submit the form
        form.submit();

            }
        }
    };

【问题讨论】:

    标签: javascript php html token stripe-payments


    【解决方案1】:

    我认为您应该在 Stripe 文档中阅读此内容: https://stripe.com/docs/stripe-js/elements/quickstart

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2015-06-21
      • 2015-11-07
      • 2017-09-28
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 2019-02-24
      相关资源
      最近更新 更多