add pluggable PayBridge and Dojo payment flow with CMS credentials
This commit is contained in:
@@ -13,11 +13,12 @@ import (
|
||||
|
||||
"gitea.futuresens.co.uk/futuresens/cmstypes"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/config"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/creditcall"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/dispenser"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/errorhandlers"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/lockserver"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/mail"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/payment"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/paymentsvc"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/printer"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/types"
|
||||
"gitea.futuresens.co.uk/futuresens/logging"
|
||||
@@ -27,6 +28,7 @@ import (
|
||||
type App struct {
|
||||
disp *dispenser.Client
|
||||
lockserver lockserver.LockServer
|
||||
paymentService *paymentsvc.Service
|
||||
isPayment bool
|
||||
db *sql.DB
|
||||
cfg *config.ConfigRec
|
||||
@@ -50,6 +52,10 @@ func NewApp(disp *dispenser.Client, lockType, encoderAddress, cardWellStatus str
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) SetPaymentService(service *paymentsvc.Service) {
|
||||
app.paymentService = service
|
||||
}
|
||||
|
||||
func (app *App) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/issuedoorcard", app.issueDoorCard)
|
||||
mux.HandleFunc("/printroomticket", app.printRoomTicket)
|
||||
@@ -59,6 +65,7 @@ func (app *App) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/testissuedoorcard", app.testIssueDoorCard)
|
||||
mux.HandleFunc("/ping-pdq", app.fetchChipDNAStatus)
|
||||
mux.HandleFunc("/logerror", app.onChipDNAError)
|
||||
mux.HandleFunc("/api/payment/sale", app.salePayment)
|
||||
}
|
||||
|
||||
func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -67,8 +74,8 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
theResponse cmstypes.ResponseRec
|
||||
theRequest cmstypes.TransactionRec
|
||||
trResult payment.TransactionResultXML
|
||||
result payment.PaymentResult
|
||||
trResult creditcall.TransactionResultXML
|
||||
result creditcall.PaymentResult
|
||||
save bool
|
||||
)
|
||||
|
||||
@@ -83,7 +90,7 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
if !app.isPayment {
|
||||
if !app.cfg.TestMode {
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, "Payment Error", "Attempted preauthorization while payment processing is disabled")
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Payment processing is disabled")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Payment processing is disabled")
|
||||
writeTransactionResult(w, http.StatusServiceUnavailable, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -96,13 +103,13 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Println("takePreauthorization called")
|
||||
if r.Method != http.MethodPost {
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Method not allowed; use POST")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Method not allowed; use POST")
|
||||
writeTransactionResult(w, http.StatusMethodNotAllowed, theResponse)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Header.Get("Content-Type") != "text/xml" {
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Content-Type must be text/xml")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Content-Type must be text/xml")
|
||||
writeTransactionResult(w, http.StatusUnsupportedMediaType, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -112,14 +119,14 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Read body error", string(op), "", "", 0)
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Failed to read request body")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Failed to read request body")
|
||||
writeTransactionResult(w, http.StatusBadRequest, theResponse)
|
||||
return
|
||||
}
|
||||
|
||||
if err := xml.Unmarshal(body, &theRequest); err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "ReadXML", string(op), "", "", 0)
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Invalid XML payload")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Invalid XML payload")
|
||||
writeTransactionResult(w, http.StatusBadRequest, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -138,7 +145,7 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Preauth processing error", string(op), "", "", 0)
|
||||
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "No response from payment processor")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "No response from payment processor")
|
||||
writeTransactionResult(w, http.StatusBadGateway, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -156,7 +163,7 @@ func (app *App) takePreauthorization(w http.ResponseWriter, r *http.Request) {
|
||||
// ---- REDIRECT ----
|
||||
|
||||
theResponse.Status = result.Status
|
||||
theResponse.Data, save = payment.BuildPreauthRedirectURL(result.Fields)
|
||||
theResponse.Data, save = creditcall.BuildPreauthRedirectURL(result.Fields)
|
||||
|
||||
if save {
|
||||
go app.persistPreauth(context.Background(), result.Fields, theRequest.CheckoutDate)
|
||||
@@ -171,8 +178,8 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
theResponse cmstypes.ResponseRec
|
||||
theRequest cmstypes.TransactionRec
|
||||
trResult payment.TransactionResultXML
|
||||
result payment.PaymentResult
|
||||
trResult creditcall.TransactionResultXML
|
||||
result creditcall.PaymentResult
|
||||
)
|
||||
|
||||
theResponse.Status.Code = http.StatusInternalServerError
|
||||
@@ -187,11 +194,11 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
if !app.cfg.TestMode {
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, "Payment Error", "Attempted payment while payment processing is disabled")
|
||||
theResponse.Status.Code = http.StatusServiceUnavailable
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Payment processing is disabled")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Payment processing is disabled")
|
||||
writeTransactionResult(w, http.StatusServiceUnavailable, theResponse)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
@@ -201,13 +208,13 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Println("takePayment called")
|
||||
if r.Method != http.MethodPost {
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Method not allowed; use POST")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Method not allowed; use POST")
|
||||
writeTransactionResult(w, http.StatusMethodNotAllowed, theResponse)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Header.Get("Content-Type") != "text/xml" {
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Content-Type must be text/xml")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Content-Type must be text/xml")
|
||||
writeTransactionResult(w, http.StatusUnsupportedMediaType, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -217,14 +224,14 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Read body error", string(op), "", "", 0)
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Failed to read request body")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Failed to read request body")
|
||||
writeTransactionResult(w, http.StatusBadRequest, theResponse)
|
||||
return
|
||||
}
|
||||
|
||||
if err := xml.Unmarshal(body, &theRequest); err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "ReadXML", string(op), "", "", 0)
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "Invalid XML payload")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "Invalid XML payload")
|
||||
writeTransactionResult(w, http.StatusBadRequest, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -242,7 +249,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Start transaction error", string(op), "", "", 0)
|
||||
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "No response from payment processor")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "No response from payment processor")
|
||||
writeTransactionResult(w, http.StatusBadGateway, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -263,7 +270,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
logging.Error(types.ServiceName, "Preauthorization failed", "Result: "+res+" Description: "+desc, string(op), "", app.cfg.Hotel, app.cfg.Kiosk)
|
||||
theResponse.Status = result.Status
|
||||
theResponse.Data = payment.BuildFailureURL(res, result.Fields[types.Errors])
|
||||
theResponse.Data = creditcall.BuildFailureURL(res, result.Fields[types.Errors])
|
||||
|
||||
writeTransactionResult(w, http.StatusOK, theResponse)
|
||||
return
|
||||
@@ -273,7 +280,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ref := result.Fields[types.Reference]
|
||||
log.Printf("Preauth approved, reference: %s. Sending confirm...", ref)
|
||||
confirmReq := payment.ConfirmTransactionRequest{
|
||||
confirmReq := creditcall.ConfirmTransactionRequest{
|
||||
Amount: theRequest.AmountMinorUnits,
|
||||
Reference: ref,
|
||||
}
|
||||
@@ -282,7 +289,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Confirm transaction error", string(op), "", "", 0)
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, "Payment confirmation failed", "Reference: "+ref+", Error: "+err.Error())
|
||||
theResponse.Data = payment.BuildFailureURL(types.ResultError, "ConfirmTransactionError")
|
||||
theResponse.Data = creditcall.BuildFailureURL(types.ResultError, "ConfirmTransactionError")
|
||||
writeTransactionResult(w, http.StatusBadGateway, theResponse)
|
||||
return
|
||||
}
|
||||
@@ -304,7 +311,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
logging.Error(types.ServiceName, "Transaction not approved after confirm", "Confirm result: "+res+" Description: "+desc, string(op), "", app.cfg.Hotel, app.cfg.Kiosk)
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, "Payment confirmation failed", "Reference: "+ref+", Confirm result: "+res+" Description: "+desc)
|
||||
theResponse.Status = result.Status
|
||||
theResponse.Data = payment.BuildFailureURL(res, result.Fields[types.Errors])
|
||||
theResponse.Data = creditcall.BuildFailureURL(res, result.Fields[types.Errors])
|
||||
|
||||
writeTransactionResult(w, http.StatusOK, theResponse)
|
||||
return
|
||||
@@ -315,7 +322,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
printer.PrintReceipt(result.CardholderReceipt)
|
||||
log.Printf("Transaction approved and confirmed, reference: %s", ref)
|
||||
theResponse.Status = result.Status
|
||||
theResponse.Data = payment.BuildSuccessURL(result.Fields)
|
||||
theResponse.Data = creditcall.BuildSuccessURL(result.Fields)
|
||||
|
||||
writeTransactionResult(w, http.StatusOK, theResponse)
|
||||
}
|
||||
@@ -396,6 +403,7 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
app.SetCardWellStatus(status)
|
||||
}
|
||||
|
||||
doorReq.RoomField = "104"
|
||||
// build lock server command
|
||||
app.lockserver.BuildCommand(doorReq, checkIn, checkOut)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.futuresens.co.uk/futuresens/cmstypes"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/payment"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/creditcall"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/types"
|
||||
"gitea.futuresens.co.uk/futuresens/logging"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -34,7 +34,7 @@ func callChipDNA(client *http.Client, url string, payload []byte) ([]byte, error
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
func confirmWithRetry(client *http.Client, req payment.ConfirmTransactionRequest, attempts int) ([]byte, error) {
|
||||
func confirmWithRetry(client *http.Client, req creditcall.ConfirmTransactionRequest, attempts int) ([]byte, error) {
|
||||
|
||||
payload, err := xml.Marshal(req)
|
||||
if err != nil {
|
||||
@@ -69,3 +69,14 @@ func confirmWithRetry(client *http.Client, req payment.ConfirmTransactionRequest
|
||||
|
||||
return nil, lastErr
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, payload any) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
|
||||
if payload == nil {
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(payload)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.futuresens.co.uk/futuresens/cmstypes"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/mail"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/paymentsvc"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/types"
|
||||
"gitea.futuresens.co.uk/futuresens/logging"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type SalePaymentRequest struct {
|
||||
Reference string `json:"reference,omitempty"`
|
||||
ConfirmNo string `json:"confirmNo,omitempty"`
|
||||
Amount int64 `json:"amount"`
|
||||
Currency string `json:"currency,omitempty"`
|
||||
}
|
||||
|
||||
func (app *App) salePayment(w http.ResponseWriter, r *http.Request) {
|
||||
const op = logging.Op("salePayment")
|
||||
var response = cmstypes.ResponseRec{
|
||||
Status: cmstypes.StatusRec{
|
||||
Code: http.StatusInternalServerError,
|
||||
Message: http.StatusText(http.StatusInternalServerError),
|
||||
},
|
||||
}
|
||||
|
||||
setPaymentCORS(w)
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method != http.MethodPost {
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, "Method not allowed; use POST")
|
||||
writeTransactionResult(w, http.StatusMethodNotAllowed, response)
|
||||
return
|
||||
}
|
||||
if app.paymentService == nil {
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, "Payment Service Not Configured", "Payment service is not configured; cannot process payment requests")
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, "Payment service is not configured")
|
||||
writeTransactionResult(w, http.StatusInternalServerError, response)
|
||||
return
|
||||
}
|
||||
if ct := r.Header.Get("Content-Type"); ct != "" && !strings.Contains(ct, "application/json") {
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, "Content-Type must be application/json")
|
||||
writeTransactionResult(w, http.StatusUnsupportedMediaType, response)
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
var req SalePaymentRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "ReadJSON", string(op), "", app.cfg.Hotel, app.cfg.Kiosk)
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, "invalid JSON payload: "+err.Error())
|
||||
writeTransactionResult(w, http.StatusBadRequest, response)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Amount <= 0 {
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, "Amount must be greater than zero")
|
||||
writeTransactionResult(w, http.StatusBadRequest, response)
|
||||
return
|
||||
}
|
||||
if req.Currency == "" {
|
||||
req.Currency = "GBP"
|
||||
}
|
||||
if req.Reference == "" {
|
||||
req.Reference = req.ConfirmNo
|
||||
}
|
||||
if req.Reference == "" {
|
||||
req.Reference = uuid.NewString()
|
||||
}
|
||||
|
||||
requestID := buildPaymentRequestID(req.Reference)
|
||||
timeoutSeconds := app.cfg.TimeoutSeconds
|
||||
if timeoutSeconds <= 0 {
|
||||
timeoutSeconds = 300
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(timeoutSeconds)*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := app.paymentService.Sale(ctx, paymentsvc.SaleRequest{
|
||||
RequestID: requestID,
|
||||
Reference: req.Reference,
|
||||
Amount: req.Amount,
|
||||
Currency: req.Currency,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
status := http.StatusBadGateway
|
||||
if errors.Is(err, paymentsvc.ErrPaymentInProgress) {
|
||||
status = http.StatusConflict
|
||||
}
|
||||
|
||||
logging.Error(types.ServiceName, err.Error(), "Payment provider error", string(op), req.Reference, app.cfg.Hotel, app.cfg.Kiosk)
|
||||
|
||||
response.Status.Code = status
|
||||
response.Status.Message = http.StatusText(status)
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, err.Error())
|
||||
writeTransactionResult(w, status, response)
|
||||
return
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
response.Status.Code = http.StatusBadGateway
|
||||
response.Status.Message = "Empty payment result"
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, "Payment provider returned an empty result")
|
||||
writeTransactionResult(w, http.StatusBadGateway, response)
|
||||
return
|
||||
}
|
||||
|
||||
response.Status.Code = http.StatusOK
|
||||
|
||||
if result.Success && strings.EqualFold(result.Status, "APPROVED") {
|
||||
response.Status.Message = result.Message
|
||||
response.Data = buildPaymentSuccessURL(result)
|
||||
writeTransactionResult(w, http.StatusOK, response)
|
||||
return
|
||||
}
|
||||
|
||||
description := result.ErrorMessage
|
||||
if description == "" {
|
||||
description = result.Message
|
||||
}
|
||||
if description == "" {
|
||||
description = result.Status
|
||||
}
|
||||
|
||||
response.Status.Message = "Payment unsuccessful"
|
||||
response.Data = buildPaymentFailureURL(types.ResultError, description)
|
||||
writeTransactionResult(w, http.StatusOK, response)
|
||||
}
|
||||
|
||||
func buildPaymentRequestID(reference string) string {
|
||||
const prefix = "REQ_"
|
||||
const maxLength = 60
|
||||
|
||||
suffix := fmt.Sprintf("_%d", time.Now().UnixMilli())
|
||||
maxReferenceLength := maxLength - len(prefix) - len(suffix)
|
||||
|
||||
runes := []rune(reference)
|
||||
if len(runes) > maxReferenceLength {
|
||||
runes = runes[:maxReferenceLength]
|
||||
}
|
||||
|
||||
return prefix + string(runes) + suffix
|
||||
}
|
||||
|
||||
func setPaymentCORS(w http.ResponseWriter) {
|
||||
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")
|
||||
}
|
||||
|
||||
func buildPaymentSuccessURL(result *paymentsvc.Result) string {
|
||||
txnReference := result.ReferenceNumber
|
||||
if txnReference == "" {
|
||||
txnReference = result.TransactionID
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Set("CardNumber", hex.EncodeToString([]byte(result.CardNumber)))
|
||||
q.Set("CardType", hex.EncodeToString([]byte(result.CardType)))
|
||||
q.Set("ExpiryDate", hex.EncodeToString([]byte(result.ExpiryDate)))
|
||||
q.Set("TxnReference", txnReference)
|
||||
q.Set("CardHash", hex.EncodeToString([]byte(result.CardHash)))
|
||||
q.Set("CardReference", hex.EncodeToString([]byte(result.CardReference)))
|
||||
|
||||
return (&url.URL{
|
||||
Path: types.CheckinSuccessfulEndpoint,
|
||||
RawQuery: q.Encode(),
|
||||
}).String()
|
||||
}
|
||||
|
||||
func buildPaymentFailureURL(msgType, description string) string {
|
||||
log.WithFields(log.Fields{
|
||||
types.LogFieldError: msgType,
|
||||
types.LogFieldDescription: description,
|
||||
}).Error("Transaction failed")
|
||||
|
||||
q := url.Values{}
|
||||
q.Set("MsgType", msgType)
|
||||
q.Set("Description", description)
|
||||
|
||||
return (&url.URL{
|
||||
Path: types.CheckinUnsuccessfulEndpoint,
|
||||
RawQuery: q.Encode(),
|
||||
}).String()
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/errorhandlers"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/lockserver"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/mail"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/payment"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/creditcall"
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/internal/types"
|
||||
"gitea.futuresens.co.uk/futuresens/logging"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -91,7 +91,7 @@ func (app *App) fetchChipDNAStatus(w http.ResponseWriter, r *http.Request) {
|
||||
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")
|
||||
status, err := payment.ReadPdqStatus(app.cfg.Hotel, app.cfg.Kiosk)
|
||||
status, err := creditcall.ReadPdqStatus(app.cfg.Hotel, app.cfg.Kiosk)
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "fetchChipDNAStatus", string(op), "", app.cfg.Hotel, app.cfg.Kiosk)
|
||||
errorhandlers.WriteError(w, http.StatusServiceUnavailable, err.Error())
|
||||
@@ -111,7 +111,7 @@ func (app *App) fetchChipDNAStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (app *App) onChipDNAError(w http.ResponseWriter, r *http.Request) {
|
||||
const op = logging.Op("onChipDNAError")
|
||||
var tr payment.TransactionResultXML
|
||||
var tr creditcall.TransactionResultXML
|
||||
title := "ChipDNA Error"
|
||||
message := ""
|
||||
|
||||
@@ -168,10 +168,10 @@ func (app *App) onChipDNAError(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch e.Key {
|
||||
|
||||
case payment.KeyErrors:
|
||||
case creditcall.KeyErrors:
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, title, e.Value)
|
||||
|
||||
case payment.KeyIsAvailable:
|
||||
case creditcall.KeyIsAvailable:
|
||||
isAvailable := strings.EqualFold(e.Value, "true")
|
||||
app.handleAvailabilityDebounced(isAvailable)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user