Stripe的元素表单呈现

时间:2017-05-15 16:30:06

标签: javascript ruby-on-rails stripe-payments

我试图在我的rails应用中将Stripe的元素集成为付款方式。问题是我无法重现他们提供的示例(https://stripe.com/docs/elements/examples中的示例3)和字段'卡号'根本不会加载或显示。我已经尝试过使用document.ready函数和document.addEventListener(" DOMContentLoaded",doStuff);但我得到的只是同一张图片。

Failed stripe form

另外,我已经尝试删除所有的CSS,但问题仍然存在。有什么想法吗?



$(document).ready(function() {
console.log("Loaded");
    stripe_public_key = $("meta[name='stripe_public_key']").attr("content");
    var stripe = Stripe(stripe_public_key);
    var elements = stripe.elements({
        fonts: [
            {
                family: 'Open Sans',
                weight: 400,
                src: 'local("Open Sans"), local("OpenSans"), url(https://fonts.gstatic.com/s/opensans/v13/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2) format("woff2")',
                unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215',
            },
        ]
    });

    var card = elements.create('card', {
        hidePostalCode: true,
        style: {
            base: {
                iconColor: '#F99A52',
                color: '#32315E',
                lineHeight: '48px',
                fontWeight: 400,
                fontFamily: '"Open Sans", "Helvetica Neue", "Helvetica", sans-serif',
                fontSize: '15px',

                '::placeholder': {
                    color: '#CFD7DF',
                }
            },
        }
    });
    card.mount('#card-element');

});

<form>
  <label>
    <span>Name</span>
    <input name="cardholder-name" class="field" placeholder="Jane Doe" />
  </label>
  <label>
    <span>Phone</span>
    <input class="field" placeholder="(123) 456-7890" type="tel" />
  </label>
  <label>
    <span>ZIP code</span>
    <input name="address-zip" class="field" placeholder="94110" />
  </label>
  <label>
    <span>Card</span>
    <div id="card-element" class="field"></div>
  </label>
  <button type="submit">Pay $25</button>
  <div class="outcome">
    <div class="error"></div>
    <div class="success">
      Success! Your Stripe token is <span class="token"></span>
    </div>
  </div>
</form>
&#13;
&#13;
&#13;

0 个答案:

没有答案