update submodule
This commit is contained in:
parent
6a65be781c
commit
1bf3cfa081
@ -1,5 +1,10 @@
|
||||
export const stripeConfig = {
|
||||
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
|
||||
STRIPE_WEBHOOK_SECRET: process.env.STRIPE_WEBHOOK_SECRET,
|
||||
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY || 'sk_test_dummy_key_for_development',
|
||||
STRIPE_WEBHOOK_SECRET: process.env.STRIPE_WEBHOOK_SECRET || 'whsec_dummy_secret_for_development',
|
||||
APP_HOST: process.env.APP_HOST || 'http://localhost:3000',
|
||||
};
|
||||
|
||||
// Vérifier si Stripe est configuré
|
||||
export const isStripeConfigured = () => {
|
||||
return stripeConfig.STRIPE_SECRET_KEY && stripeConfig.STRIPE_SECRET_KEY !== 'sk_test_dummy_key_for_development';
|
||||
};
|
||||
|
@ -1,21 +1,28 @@
|
||||
import { Request, Response } from 'express';
|
||||
import Stripe from 'stripe';
|
||||
import { StripeService } from '../services/stripe';
|
||||
import { stripeConfig } from '../config/stripe';
|
||||
import { stripeConfig, isStripeConfigured } from '../config/stripe';
|
||||
|
||||
export class StripeController {
|
||||
private static stripeService = new StripeService();
|
||||
|
||||
// Only for test
|
||||
static async createTestSubscription(req: Request, res: Response) {
|
||||
if (!isStripeConfigured()) {
|
||||
return res.status(503).json({
|
||||
success: false,
|
||||
message: 'Stripe n\'est pas configuré pour ce déploiement'
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await StripeController.stripeService.createTestSubscription();
|
||||
res.json({
|
||||
return res.json({
|
||||
success: true,
|
||||
data: result
|
||||
});
|
||||
} catch (error: any) {
|
||||
res.status(500).json({
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: 'Erreur lors de la création de l\'abonnement de test',
|
||||
error: {
|
||||
@ -30,10 +37,10 @@ export class StripeController {
|
||||
static async createCheckoutSession(req: Request, res: Response) {
|
||||
try {
|
||||
const session = await StripeController.stripeService.createCheckoutSession(req.body, req.body.frequency);
|
||||
res.json({ success: true, sessionId: session.id });
|
||||
return res.json({ success: true, sessionId: session.id });
|
||||
} catch (error) {
|
||||
console.error('Error creating checkout:', error);
|
||||
res.status(500).json({
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: 'Erreur lors de la création de la session de paiement'
|
||||
});
|
||||
@ -43,9 +50,9 @@ export class StripeController {
|
||||
static async getSubscription(req: Request, res: Response) {
|
||||
try {
|
||||
const subscription = await StripeController.stripeService.getSubscription(req.params.id);
|
||||
res.json({ success: true, subscription });
|
||||
return res.json({ success: true, subscription });
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: 'Erreur lors de la récupération de l\'abonnement'
|
||||
});
|
||||
@ -55,9 +62,9 @@ export class StripeController {
|
||||
static async createPortalSession(req: Request, res: Response) {
|
||||
try {
|
||||
const session = await StripeController.stripeService.createPortalSession(req.params.id);
|
||||
res.json({ success: true, url: session.url });
|
||||
return res.json({ success: true, url: session.url });
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: 'Erreur lors de la création de la session du portail'
|
||||
});
|
||||
@ -101,10 +108,10 @@ export class StripeController {
|
||||
break;
|
||||
}
|
||||
|
||||
res.json({ received: true });
|
||||
return res.json({ received: true });
|
||||
} catch (error) {
|
||||
console.error('Webhook error:', error);
|
||||
res.status(500).json({
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: 'Error processing webhook'
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user