javascript 不要用 Stripe 收集邮政编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46863072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do not collect Zip code with Stripe
提问by Mark
Im trying to use Stripe v3 for payment. The guide is here https://stripe.com/docs/elements
我正在尝试使用 Stripe v3 进行付款。指南在这里https://stripe.com/docs/elements
I do not want to collect the zip code. However I cannot figure out how. My HTML is:
我不想收集邮政编码。但是我无法弄清楚如何。我的 HTML 是:
<form>
<label>
<div id="card-element" class="field is-empty"></div>
<span><span>Credit or debit card</span></span>
</label>
<button type="submit">Pay</button>
<div class="outcome">
<div class="error" role="alert"></div>
<div class="success">
Success! Your Stripe token is <span class="token"></span>
</div>
</div>
</form>
And javascript is:
和 javascript 是:
var card = elements.create('card', {
style: {
hidePostalCode: true,
base: {
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSize: '15px',
'::placeholder': {
color: '#CFD7E0',
},
},
}
});
card.mount('#card-element');
But it always asks for the zip code:
但它总是询问邮政编码:
There is a guide to the Element tag here https://stripe.com/docs/stripe.js#element-types. But I cannot see where I can collect the card number, CVC and card expiry, but NOT the zip code...
此处有 Element 标签指南https://stripe.com/docs/stripe.js#element-types。但是我看不到在哪里可以收集卡号、CVC 和卡的有效期,但看不到邮政编码...
回答by duck
Thankfully, this should be a pretty simple fix! hidePostalCode: trueshould be a top level property in your options, rather than nested under stylehere.
谢天谢地,这应该是一个非常简单的修复!hidePostalCode: true应该是您的 中的顶级属性options,而不是嵌套在style此处。
https://stripe.com/docs/stripe.js#element-options
https://stripe.com/docs/stripe.js#element-options
var card = elements.create('card', {
hidePostalCode: true,
style: {
base: {
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSize: '15px',
'::placeholder': {
color: '#CFD7E0',
},
},
}
});
card.mount('#card-element');
回答by Andres Leon Rangel
To remove Zip code collection do this in the javascript snippet like this:
要删除邮政编码集合,请在 javascript 代码段中执行此操作,如下所示:
var style = {//styling
//lots of style stuff
};
var card = elements.create('card', {hidePostalCode: true, style: style});


