#๐ช๐ฆ
1 messages ยท Page 1 of 1 (latest)
hello
what's your line of code
it looks like you might not be resolving the promise
but logging out the promise itself?
let's take step by step
can you log out what elements.getElement('cardExpiry') is
just want to make sure an Element exists
thats a good shout actually
second, why are you passing currency ?
you don't need to do that while creating a Token
needed for connect account
ah
gotcha ok that looks good.
and just to confirm, you're creating a Token representing a debit card right, to later attach to a Connect account as its external account?
yep
now next, can run that code again and
1/ check the console logs for any errors / warnings
2/ check the network tab of browser console to see if a request is even being made
sorry should've mentioned yeah I checked the network
also what library are you using? can you send me the link for react-stripe-elements?
(cause that's technically the outdated one)
yeah I checked the network
what was in there?
ah that is the right package, react-stripe-js
I think thats what mentioned on official stripe
uh
nothing currently because it just gets stuck in the await
I can make it without the await so a promise is returned
but it will just say pending
so it doesnt get to console.log(token)
I can try to import the basic js stripe just for this purpose but that seems weird
Hi there ๐ taking over for @muted quail
You said there's nothing in your network logs that indicate createToken() is actually getting to Stripe?
๐ how are you initializing Stripe? Can you share your full code for that Component?
Also it should be CardCvcElement, no?
Woops
Expiry
Not CVC
CardExpiryElement
it can be either of the 3 I'm pretty sure, thats what the documentation said at least
it said something along the lines of "you dont need to submit all elements, one will suffice"
one sec grabbing component code
Yeah butt cardExpiry isn't the React Element
Ah okay using TS
Main Component
import {
CardCvcElement,
CardElement,
CardExpiryElement,
CardNumberElement,
Elements,
PaymentElement,
} from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";
import React, { useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { createStripe } from "../../api/auth";
import { stripeKey } from "../../api/config";
import { useUserContext } from "../../context/user";
import { CardInfo } from "./CardInfo";
import "./paymentregister.scss";
const stripe = loadStripe(stripeKey);
const PaymentRegister = () => {
useEffect(() => {}, []);
const { t } = useTranslation();
const { state, GET_CLIENT_SECRET } = useUserContext();
return (
<div className="container-m" style={{ paddingTop: "140px" }}>
<div className="payment-details">
<h1>{t("payment-register.title")}</h1>
<div className="payment-details-fields">
<Elements stripe={stripe}>
<CardInfo></CardInfo>
</Elements>
</div>
<p className="payment-details-tos">
{t("payment-register.tos")}{" "}
<a target="_blank">{t("payment-register.our-tos")}</a>{" "}
{t("payment-register.tos2")}{" "}
<a target="_blank" href="https://stripe.com/legal/connect-account">
{t("payment-register.stripe-tos")}
</a>
</p>
</div>
</div>
);
};
export default PaymentRegister;
CardInfo
import {
CardCvcElement,
CardExpiryElement,
CardNumberElement,
useElements,
useStripe,
} from "@stripe/react-stripe-js";
import React from "react";
import { useTranslation } from "react-i18next";
export const CardInfo = () => {
const { t } = useTranslation();
const stripe = useStripe();
const elements = useElements();
const submitDetails = async () => {
debugger;
const token = await stripe.createToken(elements.getElement("cardExpiry"), {
currency: "EUR",
});
console.log(token);
};
return (
<>
<CardNumberElement
className="number"
options={{ placeholder: "Card Number" }}
></CardNumberElement>
<div className="payment-details-fields-double">
<CardCvcElement className="cvc"></CardCvcElement>
<CardExpiryElement className="expiry"></CardExpiryElement>
</div>
<a
className="payment-details-submit"
onClick={() => {
submitDetails();
}}
>
{t("payment-register.submit")}
</a>
</>
);
};
Can you add event.preventDefault() in submitDetails?
Yeah okay didn't think so if you are reaching the promise without await
but no ๐
This is very strange
I saw online something about garbage collection?
but I didnt read enough to know if this is related
I can try finding it agian
Hmm not familiar with that
I can try importing it with ES module and see if that one works?
maybe react issue?
it does
Did you put that in to figure this out? Or it has always been there?
Ill try rerunning it without debug
๐
nope didnt change
This is just local, right? No where I can test myself?
yeah this is local
Ill try importing this through ES module
and not react-stripe
might as well
Can you try changing cardExpiry to CardCvcElement or is TS not going to let you do that?
tried to import loadStripe as ES module, same issue
can send you the styles if you need
if you are carbon copying the components
I rarely ever use TS. Why does it not recognize stripe or elements? Object is possibly null
What do I need to do ๐
oh uh the components themselves are JS
but the intellisense is getting the suggestions for what to input to getElements from TS
version compare?
I made mine really simple
Here is what I have:
CardCvcElement,
CardExpiryElement,
CardNumberElement,
useElements,
useStripe,
} from '@stripe/react-stripe-js'
import React from 'react'
export const CheckoutForm = () => {
const stripe: any = useStripe()
const elements: any = useElements()
const submitDetails = async (e: any) => {
e.preventDefault();
const token = await stripe.createToken(elements.getElement('cardExpiry'), {
currency: 'EUR',
})
console.log(token)
}
return (
<>
<CardNumberElement
className="number"
options={{ placeholder: 'Card Number' }}
></CardNumberElement>
<div className="payment-details-fields-double">
<CardCvcElement className="cvc"></CardCvcElement>
<CardExpiryElement className="expiry"></CardExpiryElement>
</div>
<button
onClick={(e) => {
submitDetails(e)
}}
>test button
</button>
</>
)
}
export default CheckoutForm
CardCvcElement,
CardElement,
CardExpiryElement,
CardNumberElement,
Elements,
PaymentElement,
} from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";
import React, { useEffect, useRef } from "react";
import CheckoutForm from './CheckoutForm'
const stripe = loadStripe("pk_test_123");
const App = () => {
useEffect(() => { }, []);
return (
<Elements stripe={stripe}>
<CheckoutForm></CheckoutForm>
</Elements>
);
};
export default App;```
Try something super simple like that in yours?
I need to step away for ~45 mins
lol!
Your sever shouldn't be involved
Yeah okay
lol the old turn off and turn on
classic.
christ
Bummer it took this long
I should have recommended that earlier ๐
But glad it is figured out
lmao I was about to say is it my fault for not thinking about it or yours
thanks for being here with me tho lmao
haha just glad it is solved
yeah thank you
Good luck going forward! Pop back in if you run into anything else