Skip to content

Instantly share code, notes, and snippets.

@mpaccione
Created January 23, 2021 02:11
Show Gist options
  • Save mpaccione/600068e2a76874fdb998e730a319fac1 to your computer and use it in GitHub Desktop.
Save mpaccione/600068e2a76874fdb998e730a319fac1 to your computer and use it in GitHub Desktop.
Relevant Code for Stripe confusion
useEffect(() => {
(async () => {
if (stripe === undefined) {
const stripeRes = await loadStripe(
"pk_test_51HrbUxAdAI21ldjmWDqxhD3t8hRrKMQ2WyshTOlNLGYEd4oWVoUrkIS0bKSYzpnCNoOtkpmFwzL62sF8IM8BDTeU00t0EK9JGA"
);
setStripe(stripeRes);
}
})();
dispatch(getActiveStripeSubscriptions());
}, []);
//////////////////////////////
const [card, setCard] = useState({
number: null,
exp_month: null,
exp_year: null,
cvc: null,
});
/////////////////////////////
const postPaymentDetails = async (payment_type) => {
dispatch(setAppLoading(true));
const stripeRes =
payment_type === "bank"
? await stripe.createToken("bank_account", bankAccount)
: await stripe.tokens.create({ card });
if (stripeRes.token) {
const apiRes = await axios.post(`${BILLING_URL}/subscription`, {
applicationId,
paymentParams: { type: payment_type, token: stripeRes.token.id },
});
dispatch(setAppLoading(false));
apiRes && apiRes.data
? dispatch(getActiveStripeSubscriptions())
: displayError(apiRes);
} else {
displayError(stripeRes);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment