Skip to content

Commit 2308b25

Browse files
committed
Simplify Stripe checkout and update service config for convert2doc service
1 parent 0b11922 commit 2308b25

File tree

4 files changed

+53
-64
lines changed

4 files changed

+53
-64
lines changed

bin/install-service.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [ -f "$PROJECT_DIR/.env" ]; then
2323
fi
2424

2525
# Set default values if not in environment
26-
SERVICE_NAME=${SERVICE_NAME:-"profullstack-pdf"}
26+
SERVICE_NAME=${SERVICE_NAME:-"convert2doc-pdf"}
2727
SERVICE_USER=${SERVICE_USER:-"ubuntu"}
2828
SERVICE_GROUP=${SERVICE_GROUP:-"ubuntu"}
2929
SERVICE_WORKING_DIR=${SERVICE_WORKING_DIR:-"$PROJECT_DIR"}

etc/convert2doc.service.template

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Unit]
2+
Description=Document Generation Service
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=${SERVICE_USER:-ubuntu}
8+
Group=${SERVICE_GROUP:-ubuntu}
9+
WorkingDirectory=${SERVICE_WORKING_DIR:-/home/ubuntu/www/convert2doc.com/pdf}
10+
ExecStart=/bin/zsh ${START_SCRIPT:-/home/ubuntu/www/convert2doc.com/pdf/bin/start.sh}
11+
Restart=on-failure
12+
RestartSec=10
13+
14+
# Log to files instead of journal
15+
StandardOutput=append:/var/log/${SERVICE_NAME:-convert2doc-pdf}.log
16+
StandardError=append:/var/log/${SERVICE_NAME:-convert2doc-pdf}.error.log
17+
18+
# Environment
19+
Environment=NODE_ENV=${NODE_ENV:-production}
20+
Environment=PATH=${PATH:-/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ubuntu/.local/share/pnpm:/home/ubuntu/.npm/pnpm/bin}
21+
Environment=HOME=${HOME:-/home/ubuntu}
22+
23+
# Hardening
24+
ProtectSystem=full
25+
PrivateTmp=true
26+
NoNewPrivileges=true
27+
28+
[Install]
29+
WantedBy=multi-user.target

src/services/stripe-payment-service.js

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -138,68 +138,28 @@ export const stripePaymentService = {
138138
console.log('- success_url:', successUrl);
139139
console.log('- cancel_url:', cancelUrl);
140140

141-
// Try to create a real Stripe checkout session first
142-
let session;
143-
try {
144-
// Set a timeout for the Stripe API call
145-
const timeoutPromise = new Promise((_, reject) => {
146-
setTimeout(() => reject(new Error('Stripe API call timed out after 5 seconds')), 5000);
147-
});
148-
149-
// Create the checkout session with Stripe
150-
const sessionPromise = stripe.checkout.sessions.create({
151-
customer_email: email,
152-
client_reference_id: userId,
153-
payment_method_types: ['card'],
154-
line_items: [
155-
{
156-
price: priceId,
157-
quantity: 1,
158-
},
159-
],
160-
mode: 'subscription',
161-
success_url: successUrl,
162-
cancel_url: cancelUrl,
163-
metadata: {
164-
user_id: userId,
165-
email,
166-
plan
167-
}
168-
});
169-
170-
// Race the checkout session creation against the timeout
171-
session = await Promise.race([sessionPromise, timeoutPromise]);
172-
console.log(`Stripe payment service: Created real checkout session ${session.id}`);
173-
} catch (stripeError) {
174-
// If Stripe API call fails or times out, create a mock session instead
175-
console.error('Stripe payment service: Error creating Stripe checkout session:', stripeError);
176-
console.log('Stripe payment service: Falling back to mock checkout session');
177-
178-
// Create a mock session ID
179-
const sessionId = `cs_mock_${Math.random().toString(36).substring(2, 15)}`;
180-
181-
// Add query parameters to the success URL
182-
const separator = successUrl.includes('?') ? '&' : '?';
183-
const checkoutUrl = `${successUrl}${separator}session_id=${sessionId}&mock=true`;
184-
185-
console.log(`Stripe payment service: Created mock checkout session ${sessionId}`);
186-
console.log(`Stripe payment service: Checkout URL: ${checkoutUrl}`);
187-
188-
// Create a mock session object
189-
session = {
190-
id: sessionId,
191-
url: checkoutUrl,
192-
object: 'checkout.session',
193-
client_reference_id: userId,
194-
customer_email: email,
195-
metadata: {
196-
user_id: userId,
197-
email,
198-
plan,
199-
mock: 'true'
200-
}
201-
};
202-
}
141+
// Create the checkout session with Stripe
142+
const session = await stripe.checkout.sessions.create({
143+
customer_email: email,
144+
client_reference_id: userId,
145+
payment_method_types: ['card'],
146+
line_items: [
147+
{
148+
price: priceId,
149+
quantity: 1,
150+
},
151+
],
152+
mode: 'subscription',
153+
success_url: successUrl,
154+
cancel_url: cancelUrl,
155+
metadata: {
156+
user_id: userId,
157+
email,
158+
plan
159+
}
160+
});
161+
162+
console.log(`Stripe payment service: Created checkout session ${session.id}`);
203163

204164
// Store the checkout session in Supabase
205165
const { error: sessionError } = await supabase

supabase/.temp/storage-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.22.3
1+
v1.22.4

0 commit comments

Comments
 (0)