mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-09 20:26:51 +00:00
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.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
u "github.com/rjNemo/underscore"
|
|
|
|
"github.com/rjNemo/rentease/internal/service/booking"
|
|
"github.com/rjNemo/rentease/internal/view"
|
|
)
|
|
|
|
func handleCreatePayment(bs *booking.Service) echo.HandlerFunc {
|
|
type CreatePaymentInput struct {
|
|
Amount float64 `form:"amount"`
|
|
PaymentMethod string `form:"paymentMethod"`
|
|
}
|
|
|
|
return func(c echo.Context) error {
|
|
idStr := c.Param("id")
|
|
id, err := strconv.Atoi(idStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
np := new(CreatePaymentInput)
|
|
if err := c.Bind(np); err != nil {
|
|
return err
|
|
}
|
|
|
|
b := bs.One(id)
|
|
|
|
_, err = bs.CreatePayment(b.ID, np.Amount, np.PaymentMethod)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
nb := bs.One(id)
|
|
|
|
return renderTempl(c, http.StatusOK, view.PaymentList(
|
|
u.Map(nb.Payments, func(p booking.Payment) *view.PaymentViewModel {
|
|
return paymentViewModelFromBookingPayment(p)
|
|
}),
|
|
))
|
|
}
|
|
}
|
|
|
|
func handlePaymentForm(bs *booking.Service) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
idStr := c.Param("id")
|
|
id, err := strconv.Atoi(idStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
p := bs.OnePayment(id)
|
|
form := view.PaymentForm(paymentViewModelFromBookingPayment(*p))
|
|
return renderTempl(c, http.StatusOK, form)
|
|
}
|
|
}
|