#CEO of Sadness - Stripe Export
1 messages · Page 1 of 1 (latest)
next.js
I created stripe.ts file in pages/api and I want to use it only in my API routes
We do advise a more global import of Stripe.JS. It might seem like overkill but there are some fraud-detection processes that are useful to have running.
so u think that it will be better to just import stripe in every API route where I want to use stripe and then just call:
apiVersion: "2020-08-27"
});```
Actually I was thinking about what I do with Vue.js. Stripe is injected into the root context that the app shares.
Hmm I think we don't speak about same stuff. I don't want to use STRIPE.JS. I want to use the node lib https://www.npmjs.com/package/stripe
Hmmm I'm not familiar with integrating the NPM module. However it would appear that exporting the Stripe object from a dedicated .ts file is not supported.
ok, ty for help 😄
Honestly I'm surprised the NPM package maintainers don't have that approach documented.
Except the one thing that jumps out to me is that the import appears off in your snippet:
import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...', {
apiVersion: '2020-08-27',
});
Capitalized
Not sure if that helps
(NOT with Stripe) I use exactly this in my Firebase Cloud Functions (single deploy of multiple functions):
import Stripe from "stripe";
import { configs } from "../Functions";
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
const secret_key = configs?.stripe.stripe_test_key
? configs.stripe.stripe_test_key
: process.env.STRIPE_TEST_KEY;
export const stripe = new Stripe(secret_key);
stripe.setMaxNetworkRetries(2);
this is in an app.js file in a Stripe directory which is in a generalized Services Directory - imports are from the Services path:
For example:
import {
chargeExpandables,
listCharges,
listTransfers,
monthStamp,
monthStampNow,
refundCharge,
transferToAccount
} from "../../Stripe";
imported/initialized from top-level:
import "./services/Stripe";
(NOT with Stripe) - do note the import of "Stripe", and the export of "stripe"
@white phoenix just want to make sure you're not using the server-side stripe-node library here with your client app and secret key
This shoudl not be done
Are you building a client or server part of your application currently?
server
but i figured out that there is problem with my building enviroment
because i'm having same issue even if I am importing stripe from "stripe" in every API route and creating new stripe instance by:
apiVersion: '2020-08-27',
});```
import Stripe from "stripe"