Skip to content

Commit 6e34460

Browse files
committed
env var for saas/api
1 parent 6e1de75 commit 6e34460

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

Diff for: book/11-end/api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"license": "MIT",
55
"engines": {
6-
"node": "12.16.1",
6+
"node": "14.18.1",
77
"yarn": "1.22.5"
88
},
99
"scripts": {

Diff for: book/11-end/api/server/stripe.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as dotenv from 'dotenv';
12
import * as express from 'express';
23
import Stripe from 'stripe';
34

@@ -6,6 +7,8 @@ import User from './models/User';
67

78
import logger from './logger';
89

10+
dotenv.config();
11+
912
const dev = process.env.NODE_ENV !== 'production';
1013

1114
const stripeInstance = new Stripe(
@@ -44,6 +47,8 @@ function createSession({
4447
metadata: { userId, teamId },
4548
};
4649

50+
console.log(process.env.STRIPE_TEST_SECRETKEY, process.env.STRIPE_TEST_PRICEID);
51+
4752
if (mode === 'subscription') {
4853
params.line_items = [
4954
{

Diff for: book/11-end/app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"license": "MIT",
55
"engines": {
6-
"node": "12.16.1",
6+
"node": "14.18.1",
77
"yarn": "1.22.5"
88
},
99
"scripts": {

Diff for: book/11-end/app/pages/billing.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class Billing extends React.Component<Props, State> {
193193

194194
const { sessionId } = await fetchCheckoutSessionApiMethod({ mode, teamId: currentTeam._id });
195195

196+
console.log(process.env.STRIPE_TEST_PUBLISHABLEKEY, sessionId);
197+
196198
// When the customer clicks on the button, redirect them to Checkout.
197199
const stripe = await stripePromise;
198200
const { error } = await stripe.redirectToCheckout({ sessionId });

Diff for: saas/api/server/stripe.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import * as dotenv from 'dotenv';
12
import * as express from 'express';
2-
import * as bodyParser from 'body-parser';
33
import Stripe from 'stripe';
44

55
import Team from './models/Team';
66
import User from './models/User';
77

88
import logger from './logger';
99

10+
dotenv.config();
11+
1012
const dev = process.env.NODE_ENV !== 'production';
1113

1214
const stripeInstance = new Stripe(
@@ -100,7 +102,7 @@ function getListOfInvoices({ customerId }: { customerId: string }) {
100102
function stripeWebhookAndCheckoutCallback({ server }: { server: express.Application }) {
101103
server.post(
102104
'/api/v1/public/stripe-invoice-payment-failed',
103-
bodyParser.raw({ type: 'application/json' }),
105+
express.raw({ type: 'application/json' }),
104106
async (req, res, next) => {
105107
try {
106108
const event = stripeInstance.webhooks.constructEvent(

0 commit comments

Comments
 (0)