Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bceb55285 | ||
|
|
bb8cdb1d84 | ||
|
|
251afd6aeb | ||
|
|
e6ff292706 |
@@ -28,6 +28,7 @@ Checkin.code-workspace
|
||||
_obj
|
||||
_test
|
||||
.vscode/
|
||||
ChipDNAClient/
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
|
||||
@@ -251,6 +251,8 @@ func CardToEncoderPosition(port *serial.Port) (string, error) {
|
||||
return "", fmt.Errorf("error sending ENQ to prompt device: %v", err)
|
||||
}
|
||||
|
||||
time.Sleep(delay)
|
||||
|
||||
//Check card position status
|
||||
status, err := CheckDispenserStatus(port)
|
||||
if err != nil {
|
||||
@@ -281,6 +283,8 @@ func CardOutOfMouth(port *serial.Port) (string, error) {
|
||||
return "", fmt.Errorf("error sending ENQ to prompt device: %v", err)
|
||||
}
|
||||
|
||||
time.Sleep(delay)
|
||||
|
||||
//Check card position status
|
||||
status, err := CheckDispenserStatus(port)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,8 +19,15 @@ func (lock *AssaLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, check
|
||||
}
|
||||
|
||||
// Checks heart beat of the Assa Abloy lock server and perform key encoding
|
||||
func (lock *AssaLockServer) LockSequence(conn net.Conn) error {
|
||||
func (lock *AssaLockServer) LockSequence() error {
|
||||
const funcName = "AssaLockServer.LockSequence"
|
||||
|
||||
conn, err := InitializeServerConnection(LockServerURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
resp, err := sendHeartbeatToServer(conn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[%s] heartbeat failed: %v", funcName, err)
|
||||
|
||||
@@ -35,7 +35,7 @@ var (
|
||||
type (
|
||||
LockServer interface {
|
||||
BuildCommand(doorReq DoorCardRequest, checkIn, checkOut time.Time) error
|
||||
LockSequence(conn net.Conn) error
|
||||
LockSequence() error
|
||||
}
|
||||
|
||||
AssaLockServer struct {
|
||||
|
||||
@@ -53,8 +53,15 @@ func (lock *OmniLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, check
|
||||
}
|
||||
|
||||
// Starts link to the Omnitec lock server and perform key encoding
|
||||
func (lock *OmniLockServer) LockSequence(conn net.Conn) error {
|
||||
func (lock *OmniLockServer) LockSequence() error {
|
||||
const funcName = "OmniLockServer.LockSequence"
|
||||
|
||||
conn, err := InitializeServerConnection(LockServerURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Start the link with the lock server
|
||||
regs, err := lock.linkStart(conn)
|
||||
if err != nil {
|
||||
|
||||
@@ -139,14 +139,21 @@ func (lock *SaltoLockServer) waitForAck(conn net.Conn, reader *bufio.Reader, tim
|
||||
}
|
||||
|
||||
// LockSequence performs the full ENQ/ACK handshake and command exchange
|
||||
func (lock *SaltoLockServer) LockSequence(conn net.Conn) error {
|
||||
func (lock *SaltoLockServer) LockSequence() error {
|
||||
const timeout = 10 * time.Second
|
||||
var (
|
||||
resp []byte
|
||||
reader = bufio.NewReader(conn)
|
||||
drained = 0 // count of stale frames consumed across waits
|
||||
)
|
||||
|
||||
conn, err := InitializeServerConnection(LockServerURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
reader := bufio.NewReader(conn)
|
||||
|
||||
// 1. Send ENQ
|
||||
log.Infof("Sending ENQ")
|
||||
if _, e := conn.Write([]byte{ENQ}); e != nil {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -36,7 +35,7 @@ func (lock *TLJLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, checkO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lock *TLJLockServer) LockSequence(conn net.Conn) error {
|
||||
func (lock *TLJLockServer) LockSequence() error {
|
||||
log.Infof("Sending command: %q", lock.command)
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
resp, err := client.Get(lock.command)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -30,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
buildVersion = "1.0.11"
|
||||
buildVersion = "1.0.15"
|
||||
serviceName = "hardlink"
|
||||
customLayout = "2006-01-02 15:04:05 -0700"
|
||||
transactionUrl = "http://127.0.0.1:18181/start-transaction/"
|
||||
@@ -53,14 +52,12 @@ type configRec struct {
|
||||
// App holds shared resources.
|
||||
type App struct {
|
||||
dispPort *serial.Port
|
||||
lockConn net.Conn
|
||||
lockserver lockserver.LockServer
|
||||
}
|
||||
|
||||
func newApp(dispPort *serial.Port, lockConn net.Conn, config configRec) *App {
|
||||
func newApp(dispPort *serial.Port, config configRec) *App {
|
||||
return &App{
|
||||
dispPort: dispPort,
|
||||
lockConn: lockConn,
|
||||
lockserver: lockserver.NewLockServer(config.LockType, config.EncoderAddress, fatalError),
|
||||
}
|
||||
}
|
||||
@@ -70,8 +67,6 @@ func main() {
|
||||
config := readConfig()
|
||||
printer.Layout = readTicketLayout()
|
||||
printer.PrinterName = config.PrinterName
|
||||
|
||||
var lockConn net.Conn
|
||||
lockserver.Cert = config.Cert
|
||||
lockserver.LockServerURL = config.LockserverUrl
|
||||
|
||||
@@ -103,25 +98,19 @@ func main() {
|
||||
}
|
||||
log.Infof("Dispenser initialized on port %s, %s", config.DispenserPort, status)
|
||||
|
||||
// Initialize lock-server connection once
|
||||
// Test lock-server connection
|
||||
switch strings.ToLower(config.LockType) {
|
||||
case lockserver.TLJ:
|
||||
|
||||
default:
|
||||
lockConn, err = lockserver.InitializeServerConnection(config.LockserverUrl)
|
||||
lockConn, err := lockserver.InitializeServerConnection(config.LockserverUrl)
|
||||
if err != nil {
|
||||
fatalError(err)
|
||||
}
|
||||
defer lockConn.Close()
|
||||
log.Infof("Connected to lock server at %s", config.LockserverUrl)
|
||||
log.Infof("Connectting to lock server at %s", config.LockserverUrl)
|
||||
lockConn.Close()
|
||||
}
|
||||
|
||||
// db, err := payment.InitMSSQL(config.dbport, config.dbname, config.dbuser, config.dbpassword)
|
||||
// if err != nil {
|
||||
// fatalError(fmt.Errorf("DB init failed: %v", err))
|
||||
// }
|
||||
// defer db.Close()
|
||||
|
||||
if config.IsPayment {
|
||||
startClient := func() (*exec.Cmd, error) {
|
||||
cmd := exec.Command("./ChipDNAClient/ChipDnaClient.exe")
|
||||
@@ -181,7 +170,7 @@ func main() {
|
||||
|
||||
// Create App and wire routes
|
||||
// dispHandle := &serial.Port{} // Placeholder, replace with actual dispenser handle
|
||||
app := newApp(dispHandle, lockConn, config)
|
||||
app := newApp(dispHandle, config)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
setUpRoutes(app, mux)
|
||||
@@ -270,7 +259,7 @@ func (app *App) startTransaction(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: 90 * time.Second}
|
||||
client := &http.Client{Timeout: 300 * time.Second}
|
||||
response, err := client.Post(transactionUrl, "text/xml", r.Body)
|
||||
if err != nil {
|
||||
logging.Error(serviceName, err.Error(), "Payment processing error", string(op), "", "", 0)
|
||||
@@ -389,7 +378,7 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
app.lockserver.BuildCommand(doorReq, checkIn, checkOut)
|
||||
|
||||
// lock server sequence
|
||||
err = app.lockserver.LockSequence(app.lockConn)
|
||||
err = app.lockserver.LockSequence()
|
||||
if err != nil {
|
||||
logging.Error(serviceName, err.Error(), "Key encoding", string(op), "", "", 0)
|
||||
writeError(w, http.StatusBadGateway, err.Error())
|
||||
|
||||
+30
-48
@@ -218,63 +218,45 @@ func nullableFloatArg(nf sql.NullFloat64) interface{} {
|
||||
}
|
||||
|
||||
func BuildRedirectURL(result map[string]string) string {
|
||||
// 1) normalize the result code
|
||||
var msgType, description string
|
||||
q := url.Values{}
|
||||
|
||||
res := strings.ToLower(result["TRANSACTION_RESULT"])
|
||||
|
||||
// 2) pick base path and optional error params
|
||||
var basePath string
|
||||
var msgType, description string
|
||||
|
||||
switch res {
|
||||
case ResultApproved:
|
||||
basePath = CheckinSuccessfulEndpoint
|
||||
|
||||
case ResultDeclined:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "declined"
|
||||
description = "payment declined"
|
||||
|
||||
case ResultCancelled:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "cancelled"
|
||||
description = "payment cancelled by customer"
|
||||
|
||||
case ResultPending:
|
||||
// you could choose to treat pending as unsuccessful or special-case it
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "pending"
|
||||
description = "payment pending"
|
||||
case ResultError:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "error"
|
||||
description = result["ERROR"]
|
||||
|
||||
default:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "error"
|
||||
description = "unknown transaction result"
|
||||
if res == ResultApproved {
|
||||
q.Set("TxnReference", result["REFERENCE"])
|
||||
q.Set("CardHash", hex.EncodeToString([]byte(result["CARD_HASH"])))
|
||||
q.Set("CardReference", hex.EncodeToString([]byte(result["CARD_REFERENCE"])))
|
||||
u := url.URL{
|
||||
Path: CheckinSuccessfulEndpoint,
|
||||
RawQuery: q.Encode(),
|
||||
}
|
||||
return u.String()
|
||||
}
|
||||
|
||||
if msgType != "" {
|
||||
log.Warnf("Transaction %s: %s - %s", res, msgType, description)
|
||||
msgType = ResultError
|
||||
if res != "" {
|
||||
msgType = res
|
||||
}
|
||||
|
||||
// 3) build query params
|
||||
q := url.Values{}
|
||||
q.Set("TxnReference", result["REFERENCE"])
|
||||
q.Set("CardHash", hex.EncodeToString([]byte(result["CARD_HASH"])))
|
||||
q.Set("CardReference", hex.EncodeToString([]byte(result["CARD_REFERENCE"])))
|
||||
|
||||
// only append these when non-approved
|
||||
if msgType != "" {
|
||||
q.Set("MsgType", msgType)
|
||||
q.Set("Description", description)
|
||||
errors, ok := result["ERRORS"]
|
||||
if ok && errors != "" {
|
||||
description = errors
|
||||
}
|
||||
errors, ok = result["ERROR"]
|
||||
if ok && errors != "" {
|
||||
description += " " + errors
|
||||
}
|
||||
if description == "" {
|
||||
description = "Transaction failed"
|
||||
}
|
||||
|
||||
// 4) assemble final URL
|
||||
// note: url.URL automatically escapes values in RawQuery
|
||||
log.Errorf("Transaction %s: %s", msgType, description)
|
||||
|
||||
q.Set("MsgType", msgType)
|
||||
q.Set("Description", description)
|
||||
u := url.URL{
|
||||
Path: basePath,
|
||||
Path: CheckinUnsuccessfulEndpoint,
|
||||
RawQuery: q.Encode(),
|
||||
}
|
||||
return u.String()
|
||||
|
||||
+23
-11
@@ -2,38 +2,50 @@
|
||||
|
||||
builtVersion is a const in main.go
|
||||
|
||||
#### 1.0.11 - 11 August 2024
|
||||
#### 1.0.15 - 27 August 2025
|
||||
fixed TCP/IP connection to the lock server
|
||||
|
||||
#### 1.0.14 - 21 August 2025
|
||||
fixed issue in creditcall payment processing where error description was not properly set
|
||||
|
||||
#### 1.0.13 - 21 August 2025
|
||||
TCP/IP connection to the lock server is now established before encoding the keycard and closedafter the encoding is done.
|
||||
|
||||
#### 1.0.12 - 11 August 2025
|
||||
added delay before checking dispenser status
|
||||
|
||||
#### 1.0.11 - 11 August 2025
|
||||
updated Salto key encoding workflow
|
||||
|
||||
#### 1.0.10 - 08 August 2024
|
||||
#### 1.0.10 - 08 August 2025
|
||||
updated logging for TLJ locks
|
||||
|
||||
#### 1.0.9 - 08 August 2024
|
||||
#### 1.0.9 - 08 August 2025
|
||||
added TLJ lock server and implemented workflow for TLJ locks
|
||||
|
||||
#### 1.0.8 - 01 August 2024
|
||||
#### 1.0.8 - 01 August 2025
|
||||
improved error handling and logging in Salto
|
||||
|
||||
#### 1.0.7 - 25 July 2024
|
||||
#### 1.0.7 - 25 July 2025
|
||||
added check if the room exists
|
||||
|
||||
#### 1.0.6 - 25 July 2024
|
||||
#### 1.0.6 - 25 July 2025
|
||||
updated workflow for Salto locks
|
||||
|
||||
#### 1.0.5 - 24 July 2024
|
||||
#### 1.0.5 - 24 July 2025
|
||||
added encoding keycard copy for Salto locks
|
||||
|
||||
#### 1.0.4 - 22 July 2024
|
||||
#### 1.0.4 - 22 July 2025
|
||||
added salto lock server and implemented workflow for Salto
|
||||
|
||||
#### 1.0.0 - 30 June 2024
|
||||
#### 1.0.0 - 30 June 2025
|
||||
added creditcall payment method
|
||||
`/starttransaction` - API payment endpoint to start a transaction
|
||||
|
||||
#### 0.9.1 - 22 May 2024
|
||||
#### 0.9.1 - 22 May 2025
|
||||
added lockserver interface and implemented workflow for Omnitec
|
||||
|
||||
#### 0.9.0 - 22 May 2024
|
||||
#### 0.9.0 - 22 May 2025
|
||||
The new API has two new endpoints:
|
||||
- `/issuedoorcard` - encoding the door card for the room.
|
||||
- `/printroomticket` - printing the room ticket.
|
||||
Reference in New Issue
Block a user