Stripe JS card element won't allow user input in FlaskHTML text input allow only numeric inputHow to partially validate form fields prior to stripe card validation that's in the same formHow to allow users to enter custom amount vs charging set amount in stripe?Stripe - Cannot charge a customer that has no active cardSave card details while doing stripe paymentStripe: card holder name verificationStripe Elements forcing a postal codeStripe python attach existing card/source to new customerHow to POST stripe custom checkout token to flask backendStripe connect share card source not working
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
How do I draw and define two right triangles next to each other?
Do I have a twin with permutated remainders?
How is it possible to have an ability score that is less than 3?
Languages that we cannot (dis)prove to be Context-Free
Perform and show arithmetic with LuaLaTeX
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
LWC SFDX source push error TypeError: LWC1009: decl.moveTo is not a function
Is it possible to run Internet Explorer on OS X El Capitan?
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Character reincarnated...as a snail
What's the output of a record needle playing an out-of-speed record
RSA: Danger of using p to create q
How old can references or sources in a thesis be?
Intersection point of 2 lines defined by 2 points each
Are the number of citations and number of published articles the most important criteria for a tenure promotion?
How to determine what difficulty is right for the game?
dbcc cleantable batch size explanation
What typically incentivizes a professor to change jobs to a lower ranking university?
Modeling an IP Address
I'm flying to France today and my passport expires in less than 2 months
Why is consensus so controversial in Britain?
Can I make popcorn with any corn?
When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?
Stripe JS card element won't allow user input in Flask
HTML text input allow only numeric inputHow to partially validate form fields prior to stripe card validation that's in the same formHow to allow users to enter custom amount vs charging set amount in stripe?Stripe - Cannot charge a customer that has no active cardSave card details while doing stripe paymentStripe: card holder name verificationStripe Elements forcing a postal codeStripe python attach existing card/source to new customerHow to POST stripe custom checkout token to flask backendStripe connect share card source not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.
Here is my code for the views function:
@billing.route('/charge', methods=['GET', 'POST'])
def charge():
if request.method == 'POST':
customer = stripe.Customer.create(
email='customer@example.com',
source=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=request.form['amountInCents'],
currency='usd',
description='Flask Charge'
)
return render_template('billing/charge.html')
After looking at the web console I'm receiving this error:
Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().
How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1
javascript stripe-payments
add a comment |
I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.
Here is my code for the views function:
@billing.route('/charge', methods=['GET', 'POST'])
def charge():
if request.method == 'POST':
customer = stripe.Customer.create(
email='customer@example.com',
source=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=request.form['amountInCents'],
currency='usd',
description='Flask Charge'
)
return render_template('billing/charge.html')
After looking at the web console I'm receiving this error:
Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().
How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1
javascript stripe-payments
add a comment |
I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.
Here is my code for the views function:
@billing.route('/charge', methods=['GET', 'POST'])
def charge():
if request.method == 'POST':
customer = stripe.Customer.create(
email='customer@example.com',
source=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=request.form['amountInCents'],
currency='usd',
description='Flask Charge'
)
return render_template('billing/charge.html')
After looking at the web console I'm receiving this error:
Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().
How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1
javascript stripe-payments
I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.
Here is my code for the views function:
@billing.route('/charge', methods=['GET', 'POST'])
def charge():
if request.method == 'POST':
customer = stripe.Customer.create(
email='customer@example.com',
source=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=request.form['amountInCents'],
currency='usd',
description='Flask Charge'
)
return render_template('billing/charge.html')
After looking at the web console I'm receiving this error:
Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().
How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1
javascript stripe-payments
javascript stripe-payments
asked Mar 9 at 1:19
polymathpolymath
688
688
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:
<script src="https://js.stripe.com/v3/"></script>
<body>
<form>
<div class="group">
<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>
</div>
<div class="group">
<label>
<span>Card</span>
<div id="card-element" class="field"></div>
</label>
</div>
<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>
</body>
<script>
var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style =
base:
// Add your base input styles here. For example:
fontSize: '16px',
color: "#32325d",
;
var card = elements.create('card',
style:
base:
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',
fontSize: '15px',
'::placeholder':
color: '#CFD7E0',
,
,
);
card.mount('#card-element');
function setOutcome(result)
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token)
// Use the token to create a charge or a customer
// https://stripe.com/docs/charges
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
else if (result.error)
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
card.on('change', function(event)
setOutcome(event);
);
document.querySelector('form').addEventListener('submit', function(e)
e.preventDefault();
var form = document.querySelector('form');
var extraDetails =
name: form.querySelector('input[name=cardholder-name]').value,
;
stripe.createToken(card, extraDetails).then(setOutcome);
);
</script>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073069%2fstripe-js-card-element-wont-allow-user-input-in-flask%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:
<script src="https://js.stripe.com/v3/"></script>
<body>
<form>
<div class="group">
<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>
</div>
<div class="group">
<label>
<span>Card</span>
<div id="card-element" class="field"></div>
</label>
</div>
<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>
</body>
<script>
var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style =
base:
// Add your base input styles here. For example:
fontSize: '16px',
color: "#32325d",
;
var card = elements.create('card',
style:
base:
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',
fontSize: '15px',
'::placeholder':
color: '#CFD7E0',
,
,
);
card.mount('#card-element');
function setOutcome(result)
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token)
// Use the token to create a charge or a customer
// https://stripe.com/docs/charges
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
else if (result.error)
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
card.on('change', function(event)
setOutcome(event);
);
document.querySelector('form').addEventListener('submit', function(e)
e.preventDefault();
var form = document.querySelector('form');
var extraDetails =
name: form.querySelector('input[name=cardholder-name]').value,
;
stripe.createToken(card, extraDetails).then(setOutcome);
);
</script>
add a comment |
After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:
<script src="https://js.stripe.com/v3/"></script>
<body>
<form>
<div class="group">
<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>
</div>
<div class="group">
<label>
<span>Card</span>
<div id="card-element" class="field"></div>
</label>
</div>
<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>
</body>
<script>
var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style =
base:
// Add your base input styles here. For example:
fontSize: '16px',
color: "#32325d",
;
var card = elements.create('card',
style:
base:
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',
fontSize: '15px',
'::placeholder':
color: '#CFD7E0',
,
,
);
card.mount('#card-element');
function setOutcome(result)
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token)
// Use the token to create a charge or a customer
// https://stripe.com/docs/charges
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
else if (result.error)
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
card.on('change', function(event)
setOutcome(event);
);
document.querySelector('form').addEventListener('submit', function(e)
e.preventDefault();
var form = document.querySelector('form');
var extraDetails =
name: form.querySelector('input[name=cardholder-name]').value,
;
stripe.createToken(card, extraDetails).then(setOutcome);
);
</script>
add a comment |
After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:
<script src="https://js.stripe.com/v3/"></script>
<body>
<form>
<div class="group">
<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>
</div>
<div class="group">
<label>
<span>Card</span>
<div id="card-element" class="field"></div>
</label>
</div>
<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>
</body>
<script>
var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style =
base:
// Add your base input styles here. For example:
fontSize: '16px',
color: "#32325d",
;
var card = elements.create('card',
style:
base:
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',
fontSize: '15px',
'::placeholder':
color: '#CFD7E0',
,
,
);
card.mount('#card-element');
function setOutcome(result)
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token)
// Use the token to create a charge or a customer
// https://stripe.com/docs/charges
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
else if (result.error)
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
card.on('change', function(event)
setOutcome(event);
);
document.querySelector('form').addEventListener('submit', function(e)
e.preventDefault();
var form = document.querySelector('form');
var extraDetails =
name: form.querySelector('input[name=cardholder-name]').value,
;
stripe.createToken(card, extraDetails).then(setOutcome);
);
</script>
After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:
<script src="https://js.stripe.com/v3/"></script>
<body>
<form>
<div class="group">
<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>
</div>
<div class="group">
<label>
<span>Card</span>
<div id="card-element" class="field"></div>
</label>
</div>
<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>
</body>
<script>
var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style =
base:
// Add your base input styles here. For example:
fontSize: '16px',
color: "#32325d",
;
var card = elements.create('card',
style:
base:
iconColor: '#666EE8',
color: '#31325F',
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',
fontSize: '15px',
'::placeholder':
color: '#CFD7E0',
,
,
);
card.mount('#card-element');
function setOutcome(result)
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token)
// Use the token to create a charge or a customer
// https://stripe.com/docs/charges
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
else if (result.error)
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
card.on('change', function(event)
setOutcome(event);
);
document.querySelector('form').addEventListener('submit', function(e)
e.preventDefault();
var form = document.querySelector('form');
var extraDetails =
name: form.querySelector('input[name=cardholder-name]').value,
;
stripe.createToken(card, extraDetails).then(setOutcome);
);
</script>
answered Mar 9 at 1:19
polymathpolymath
688
688
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073069%2fstripe-js-card-element-wont-allow-user-input-in-flask%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown