#mdubya - Invalid Token

1 messages ยท Page 1 of 1 (latest)

viral wave
#

Hi ๐Ÿ‘‹
What token? how was it generated?

upper hollow
#

using stripe.js

#

ive done this several times before so clearly im missing something silly.

#

Request req_LvF2goq71cmDKw: Invalid token id: tok_1Km29VJIVBxY3C7m6Q6nkITF

viral wave
#

What kind of flow are you using? What Stripe.js elements?

upper hollow
#

card elements

viral wave
#

Okay and you are tokenizing the PM and sending it back to the server. Not firing off .confirmCardPayment?

upper hollow
#

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.

viral wave
#

Ah, in that case I think you would need to use the platform accounts' public key to initialize Stripe.js

upper hollow
#

but when i manually write in: py card={'token': 'tok_visa'} it performs as expected.

viral wave
#

Yeah that's because that is a test token that skips all validation criteria

upper hollow
#

isnt all thats needed is the token_id? and that looks to be generating correctly.

#

just POSTing a plain text string, right?

viral wave
#

Are you using the platform's API key to initialize Stripe.js?

upper hollow
#

yea

viral wave
#

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?

upper hollow
#

appears as though the token is being created correctly.

#

not sure what you mean by is it consistent

viral wave
#

Does it always happen when you use valid cards?

#

In the current integration?

upper hollow
#

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

viral wave
#

The server response is all I'm interested in. So it's consistently invalid?

upper hollow
#

correct.

#

"Invalid token id: tok_1Km3EjJIVBxY3C7mEngLQQpa"

viral wave
#

Okay so it sounds like the approach you are using in Stripe.js is not working. What functions are you calling?

upper hollow
#

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

viral wave
#

Hmmm...yep that looks pretty standard, if old.

upper hollow
#

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',
});

viral wave
#

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

upper hollow
#

hmm. so im probably mixing current and deprecated flows and thats the monkey wrench?

viral wave
#

Oooooohhhh....yeah that might be causing a problem.

upper hollow
#

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.

viral wave
#

Best of luck and we'll be here when you have more questions