mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
Some checks are pending
CI / checks (push) Waiting to run
* feat(stripe): add Stripe payment sync and webhook support Introduce Stripe integration for automatic payment ingestion and refund tracking. Adds new fields to the payment model for Stripe IDs and status, Stripe client driver, sync service, cron job, manual API endpoint, and public webhook handler for real-time updates. Includes tests and documentation. Manual cash entry remains supported. * chore(stripe): upgrade to stripe-go v83 Upgrade Stripe SDK from v79 to v83 across the codebase. Update all imports to use github.com/stripe/stripe-go/v83 and refactor client usage to match the new API, including changes to PaymentIntents listing. Update documentation and plans to reference the new version. Remove references to the old version from go.mod and go.sum. * refactor(payment): extract payment logic to new service Moves all payment-related logic (manual payments, Stripe sync, webhook handling) from the booking service into a dedicated payment service (`internal/service/payment`). Updates server, cron, and handler wiring to inject and use the new payment service. Adjusts tests, routes, and documentation to reflect the new separation of concerns. This improves cohesion, clarifies responsibilities, and prepares for future payment features. No database schema changes are introduced. * chore(ci): add Go and templ setup to CI workflow This update enhances the CI workflow by adding steps to set up Go using the version specified in go.mod, add the Go bin directory to the PATH, and install the templ code generation tool. These additions ensure that Go-based tooling is available for subsequent CI steps.
130 lines
3.5 KiB
Go
130 lines
3.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
|
|
"github.com/rjNemo/rentease/assets"
|
|
"github.com/rjNemo/rentease/internal/config"
|
|
"github.com/rjNemo/rentease/internal/driver/database"
|
|
"github.com/rjNemo/rentease/internal/driver/logger"
|
|
"github.com/rjNemo/rentease/internal/driver/parser"
|
|
"github.com/rjNemo/rentease/internal/driver/pdf"
|
|
stripeclient "github.com/rjNemo/rentease/internal/driver/stripe"
|
|
bookingRepo "github.com/rjNemo/rentease/internal/repository/booking"
|
|
"github.com/rjNemo/rentease/internal/server"
|
|
"github.com/rjNemo/rentease/internal/service/auth"
|
|
"github.com/rjNemo/rentease/internal/service/booking"
|
|
"github.com/rjNemo/rentease/internal/service/payment"
|
|
)
|
|
|
|
func main() {
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
defer cancel()
|
|
|
|
baseLogger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))
|
|
|
|
appConfig, err := config.New(ctx)
|
|
if err != nil {
|
|
baseLogger.Error("configuration error", slog.Any("error", err))
|
|
}
|
|
|
|
appLogger := logger.New(appConfig.LogLevel)
|
|
slog.SetDefault(appLogger)
|
|
|
|
if err := run(ctx, appConfig, appLogger); err != nil {
|
|
appLogger.Error("server exited", slog.Any("error", err))
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(ctx context.Context, appConfig *config.Config, appLogger *slog.Logger) error {
|
|
// init sentry
|
|
if err := sentry.Init(sentry.ClientOptions{
|
|
Dsn: appConfig.SentryDsn,
|
|
EnableTracing: true,
|
|
TracesSampleRate: 1.0,
|
|
}); err != nil {
|
|
return fmt.Errorf("error initializing sentry %w", err)
|
|
}
|
|
|
|
// init database
|
|
db, err := database.New(appConfig.DatabaseURL)
|
|
if err != nil {
|
|
return fmt.Errorf("error connecting to the database %w", err)
|
|
}
|
|
|
|
if err = database.Migrate(db, &booking.Booking{}, &booking.Item{}, &booking.Payment{}); err != nil {
|
|
return fmt.Errorf("error migrating the database %w", err)
|
|
}
|
|
|
|
bookingStore := bookingRepo.NewPgStore(db)
|
|
|
|
// build pdf client
|
|
pc, err := pdf.NewPdfClient()
|
|
if err != nil {
|
|
return fmt.Errorf("error starting pdf client %w", err)
|
|
}
|
|
|
|
parsingClient := parser.NewBookingAgentParser()
|
|
|
|
var stripeClient payment.StripeClient
|
|
if appConfig.StripeSecretKey != "" {
|
|
opts := []stripeclient.Option{}
|
|
|
|
client, err := stripeclient.New(appConfig.StripeSecretKey, opts...)
|
|
if err != nil {
|
|
return fmt.Errorf("error creating stripe client: %w", err)
|
|
}
|
|
stripeClient = client
|
|
}
|
|
|
|
bookingService, err := booking.NewService(appLogger, bookingStore, parsingClient, pc)
|
|
if err != nil {
|
|
return fmt.Errorf("error creating booking service: %w", err)
|
|
}
|
|
|
|
paymentService, err := payment.NewService(appLogger, bookingStore, stripeClient)
|
|
if err != nil {
|
|
return fmt.Errorf("error creating payment service: %w", err)
|
|
}
|
|
|
|
// build authentication service
|
|
as, err := auth.NewService(
|
|
appConfig.SessionSecret,
|
|
appConfig.Admin,
|
|
appConfig.AdminSecret,
|
|
appConfig.APIKey,
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("error starting auth service %w", err)
|
|
}
|
|
|
|
port := appConfig.Port
|
|
|
|
origins := appConfig.Origins
|
|
|
|
srv, err := server.New(
|
|
bookingService,
|
|
paymentService,
|
|
as,
|
|
config.NewHost(), // TODO: move to the database at some point
|
|
server.WithPort(port),
|
|
server.WithFileSystem(assets.Static),
|
|
server.WithDebug(appConfig.Debug),
|
|
server.WithSecretKey(appConfig.SecretKey),
|
|
server.WithOrigins(origins),
|
|
server.WithStripeWebhookSecret(appConfig.StripeWebhookSecret),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("error starting server %w", err)
|
|
}
|
|
|
|
srv.Start(ctx)
|
|
return nil
|
|
}
|