feat(hardlink): unify kiosk payments and finalize legacy cleanup
This commit is contained in:
@@ -37,20 +37,20 @@ type doorCardDispenser interface {
|
||||
}
|
||||
|
||||
type App struct {
|
||||
disp doorCardDispenser
|
||||
lockserver lockserver.LockServer
|
||||
paymentService *paymentsvc.Service
|
||||
creditCallStreamEnabled bool
|
||||
creditCallTransport http.RoundTripper
|
||||
creditCallReceipt func(string)
|
||||
isPayment bool
|
||||
db *sql.DB
|
||||
cfg *config.ConfigRec
|
||||
dbMu sync.Mutex
|
||||
cardWellMu sync.RWMutex
|
||||
cardWellStatus string
|
||||
availabilityMu sync.Mutex
|
||||
availabilityTimers map[string]*time.Timer
|
||||
trustSelected bool
|
||||
disp doorCardDispenser
|
||||
lockserver lockserver.LockServer
|
||||
paymentService *paymentsvc.Service
|
||||
creditCallTransport http.RoundTripper
|
||||
creditCallReceipt func(string)
|
||||
isPayment bool
|
||||
db *sql.DB
|
||||
cfg *config.ConfigRec
|
||||
dbMu sync.Mutex
|
||||
cardWellMu sync.RWMutex
|
||||
cardWellStatus string
|
||||
availabilityMu sync.Mutex
|
||||
availabilityTimers map[string]*time.Timer
|
||||
}
|
||||
|
||||
func NewApp(disp *dispenser.Client, lockType, encoderAddress, cardWellStatus string, db *sql.DB, cfg *config.ConfigRec) *App {
|
||||
@@ -66,6 +66,13 @@ func NewApp(disp *dispenser.Client, lockType, encoderAddress, cardWellStatus str
|
||||
return app
|
||||
}
|
||||
|
||||
// SetPaymentCurrency supplies the CMS currency to the selected modern processor.
|
||||
func (app *App) SetPaymentCurrency(currency string) {
|
||||
if app.paymentService != nil {
|
||||
app.paymentService.SetCurrency(currency)
|
||||
}
|
||||
}
|
||||
|
||||
func (app *App) SetPaymentService(service *paymentsvc.Service) {
|
||||
app.paymentService = service
|
||||
}
|
||||
@@ -80,10 +87,14 @@ func (app *App) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/ping-pdq", app.fetchChipDNAStatus)
|
||||
mux.HandleFunc("/logerror", app.onChipDNAError)
|
||||
mux.HandleFunc("/api/payment/sale", app.salePayment)
|
||||
mux.HandleFunc("/api/payment/preauth", app.streamCreditCallPreauth)
|
||||
mux.HandleFunc("/api/payment/preauth", app.preauthPayment)
|
||||
}
|
||||
|
||||
func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
if app.trustSelected {
|
||||
http.Error(w, "Trust uses /api/payment/preauth", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
const op = logging.Op("takePreauthorization")
|
||||
|
||||
var (
|
||||
@@ -164,6 +175,10 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
if app.trustSelected {
|
||||
http.Error(w, "Trust uses /api/payment/sale", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
const op = logging.Op("takePayment")
|
||||
|
||||
var (
|
||||
@@ -251,16 +266,8 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
theResponse cmstypes.StatusRec
|
||||
)
|
||||
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("issueDoorCard called")
|
||||
if r.Method != http.MethodPost {
|
||||
errorhandlers.WriteError(w, http.StatusMethodNotAllowed, "Method not allowed; use POST")
|
||||
@@ -314,7 +321,11 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// doorReq.RoomField = "104"
|
||||
// build lock server command
|
||||
app.lockserver.BuildCommand(doorReq, checkIn, checkOut)
|
||||
if err := app.lockserver.BuildCommand(doorReq, checkIn, checkOut); err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Build key command", string(op), "", "", 0)
|
||||
errorhandlers.WriteError(w, http.StatusBadGateway, "Build key command failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Each request performs at most one encoder operation.
|
||||
encodingStarted := time.Now()
|
||||
@@ -374,15 +385,7 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
func (app *App) printRoomTicket(w http.ResponseWriter, r *http.Request) {
|
||||
const op = logging.Op("printRoomTicket")
|
||||
var roomDetails printer.RoomDetailsRec
|
||||
// Allow CORS preflight if needed
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
log.Println("printRoomTicket called")
|
||||
if r.Method != http.MethodPost {
|
||||
errorhandlers.WriteError(w, http.StatusMethodNotAllowed, "Method not allowed; use POST")
|
||||
@@ -424,6 +427,12 @@ func (app *App) printRoomTicket(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *App) reportDispenserStatus(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
w.Header().Set("Allow", http.MethodGet)
|
||||
errorhandlers.WriteError(w, http.StatusMethodNotAllowed, "Method not allowed; use GET")
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_ = json.NewEncoder(w).Encode(cmstypes.StatusRec{
|
||||
|
||||
Reference in New Issue
Block a user