#BidBird®
1 messages · Page 1 of 1 (latest)
hey there can you please move your snippets of code here into this thread?
You don't seem to have included any Stripe SDK/API calls in that code, though
What call are you trying to make?
@dim agate hey thank you. This code has worked successfully prior to the stripe-php update.
const stripe = Stripe('{{ config('services.stripe.key') }}');
// Handle form
submission.var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) { event.preventDefault();
stripe.createToken(card).then(function(result) { if (result.error) {
// Inform the user if there was an error.
var errorElement = document.getElementById('card-errors'); errorElement.textContent = result.error.message; } else {
stripeTokenHandler(result.token); } });});
What's going on is a post request with elements. I'm wondering if the const Stripe is incorrectly formatted with the update?
What's happening? Are you getting any errors you can share?
you bet. here's the request data
{"_token": "UJThXuBvvWVpUPlR5ClSwUY3ObduAAx5Owm8vGuo","quantity": "2","price": "500","stripeToken": null,"coupon_name": null}
sorry, wish the formatting was for code
the stripeToken should not be null
I believe that other token is the laravel csrf token
when I check stripe dev dashboard I see no attempts
other than my test suite from the other day
In your developer console network tab, do you see request to create the token?
no, however the exception thrown is this, from PHP code.
The stripe token field is required.
my thoughts are the const stripe is not initiating.
just found this: stripe.createToken(cardElement).then(function(result) {
// Handle result.error or result.token
});
is the elements deprecated?
This is javascript code though, why would there be a PHP error?
There might be afterwards, if you call your own API
No, you can still use the card element + createToken (though we recommend newer integration patterns)
well, laravel is php, and elements uses js, so we put that script on the same view page, if js does not create a token, then the php exception is thrown during validation
which one would you recommend? I'm willing to do that work. Is there an upgrade guide?
this is the js
<script src=https://js.stripe.com/v3></script>
Ok but do you have a card element created and mounted before doing that? There appears to be some code missing here.
You have two different references to the card element in the snippets above:
stripe.createToken(cardElement)
and
stripe.createToken(card)
Is your card element card or cardElement?
There should be some errors exposed in the dev console if this fails
@wide sphinx Were you able to learn any more from the code you can share?