make dojo decline payment in case of signature required
This commit is contained in:
parent
fa2c92c8ab
commit
2a3a5bee7b
@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
buildVersion = "1.3.1"
|
||||
buildVersion = "1.3.2"
|
||||
serviceName = "hardlink"
|
||||
pollingFrequency = 8 * time.Second
|
||||
)
|
||||
|
||||
@ -154,6 +154,8 @@ func (c *Client) waitForTerminalSession(ctx context.Context, terminalSessionID s
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
signatureRejected := false
|
||||
|
||||
for {
|
||||
session, err := c.getTerminalSession(ctx, terminalSessionID)
|
||||
if err != nil {
|
||||
@ -163,13 +165,28 @@ func (c *Client) waitForTerminalSession(ctx context.Context, terminalSessionID s
|
||||
log.Println("session status:", session.Status)
|
||||
|
||||
switch strings.ToLower(session.Status) {
|
||||
case types.ResultInitiateRequested, types.ResultInitiated, types.ResultAuthorized,
|
||||
types.ResultCancelRequested, types.ResultSignatureRequired:
|
||||
// Still processing. For this integration payment intents use captureMode Auto,
|
||||
// so Authorized is expected to continue to Captured.
|
||||
case types.ResultInitiateRequested, types.ResultInitiated, types.ResultAuthorized, types.ResultCancelRequested:
|
||||
|
||||
case types.ResultCaptured, types.ResultCancelled, types.ResultCanceled, types.ResultDeclined, types.ResultExpired,
|
||||
types.ResultSignatureAccepted, types.ResultSignatureRejected /*, types.ResultSignatureRequired*/ :
|
||||
case types.ResultSignatureRequired:
|
||||
if !signatureRejected {
|
||||
rejectedSession, err := c.rejectSignature(ctx, terminalSessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
signatureRejected = true
|
||||
|
||||
if rejectedSession != nil {
|
||||
switch strings.ToLower(rejectedSession.Status) {
|
||||
case types.ResultCaptured, types.ResultCancelled, types.ResultCanceled, types.ResultDeclined,
|
||||
types.ResultExpired, types.ResultSignatureAccepted, types.ResultSignatureRejected:
|
||||
return rejectedSession, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case types.ResultCaptured, types.ResultCancelled, types.ResultCanceled, types.ResultDeclined,
|
||||
types.ResultExpired, types.ResultSignatureAccepted, types.ResultSignatureRejected:
|
||||
return session, nil
|
||||
|
||||
default:
|
||||
@ -184,6 +201,21 @@ func (c *Client) waitForTerminalSession(ctx context.Context, terminalSessionID s
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) rejectSignature(ctx context.Context, terminalSessionID string) (*terminalSessionResponse, error) {
|
||||
payload := signatureVerificationRequest{
|
||||
Accepted: false,
|
||||
}
|
||||
|
||||
var response terminalSessionResponse
|
||||
path := "/terminal-sessions/" + url.PathEscape(terminalSessionID) + "/signature"
|
||||
|
||||
if err := c.doJSON(ctx, http.MethodPut, path, payload, true, &response); err != nil {
|
||||
return nil, fmt.Errorf("reject Dojo signature verification: %w", err)
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (c *Client) getTerminalSession(ctx context.Context, terminalSessionID string) (*terminalSessionResponse, error) {
|
||||
var response terminalSessionResponse
|
||||
path := "/terminal-sessions/" + url.PathEscape(terminalSessionID)
|
||||
@ -249,7 +281,10 @@ func (c *Client) baseResult(req paymentsvc.SaleRequest, details *paymentDetails)
|
||||
result.CardNumber = details.Card.CardNumber
|
||||
result.CardType = details.Card.CardType
|
||||
result.ExpiryDate = details.Card.ExpiryDate
|
||||
result.LastFourDigits = details.Card.CardNumber
|
||||
result.LastFourDigits = details.Card.Last4PAN
|
||||
if result.LastFourDigits == "" {
|
||||
result.LastFourDigits = lastFour(details.Card.CardNumber)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@ -25,6 +25,10 @@ type terminalSessionSale struct {
|
||||
PaymentIntentID string `json:"paymentIntentId"`
|
||||
}
|
||||
|
||||
type signatureVerificationRequest struct {
|
||||
Accepted bool `json:"accepted"`
|
||||
}
|
||||
|
||||
type terminalSessionResponse struct {
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
|
||||
builtVersion is a const in main.go
|
||||
|
||||
#### 1.3.2 - 20 July 2026
|
||||
make dojo decline payment in case of signature required
|
||||
|
||||
#### 1.3.1 - 17 July 2026
|
||||
added receipt printing functionality to the Dojo and Paybridge payment flow
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user