#mdubya - Invalid Token
1 messages ยท Page 1 of 1 (latest)
using stripe.js
ive done this several times before so clearly im missing something silly.
Request req_LvF2goq71cmDKw: Invalid token id: tok_1Km29VJIVBxY3C7m6Q6nkITF
What kind of flow are you using? What Stripe.js elements?
card elements
Okay and you are tokenizing the PM and sending it back to the server. Not firing off .confirmCardPayment?
correct.
no initial payment. a "add a new debit/credit card" option.
token POSTs fine. (it appears)
stripe.PaymentMethod.create(
type='card',
card={'token': stripe_card_token},
stripe_account=self.stripe_connect_account_id,
)```
it is for a connect platform. and i imagine there in lies the hang up.
Ah, in that case I think you would need to use the platform accounts' public key to initialize Stripe.js
but when i manually write in: py card={'token': 'tok_visa'} it performs as expected.
Yeah that's because that is a test token that skips all validation criteria
isnt all thats needed is the token_id? and that looks to be generating correctly.
just POSTing a plain text string, right?
Are you using the platform's API key to initialize Stripe.js?
yea
Okay so the token should get created so it can be added to the platform account... and you are still getting this failure. Is it consistent with your current integration?
appears as though the token is being created correctly.
not sure what you mean by is it consistent
in test mode. ive only tried the 4242 test num.
i can try a different one
same. getting what appears to be a valid token_id
req_FiNkcwj2rMd0Ra
The server response is all I'm interested in. So it's consistently invalid?
Okay so it sounds like the approach you are using in Stripe.js is not working. What functions are you calling?
stripeTokenHandler()
and then just a few listeners
$("#add_customer").on('click', function(){
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 {
// attempt to add card.
stripeTokenHandler(result.token)
}
});
})
function stripeTokenHandler(token) {
// Insert the token 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', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
boiler plate poached from stripe docs
Hmmm...yep that looks pretty standard, if old.
yea. reading through docs. looks like this format was deprecated.
does the SetupIntent need to be created before the paymentMethod?
current = ```js
stripe = Stripe(stripe_publishable_key);
elements = stripe.elements();```
new docs are showing ```js
var elements = stripe.elements({
clientSecret: 'CLIENT_SECRET',
});
The setup intent is created on the back-end first, the the client secret is passed to the client
Then Stripe.js takes care of creating the PM
hmm. so im probably mixing current and deprecated flows and thats the monkey wrench?
Oooooohhhh....yeah that might be causing a problem.
definitely currently trying the reverse order. create payment method. create setupintent.
works fine in that order in a closed environment
i have to step off here. but i apprecaite your help. i will try following the docs ๐ and see how far that gets me.
Best of luck and we'll be here when you have more questions