forked from coinbase/x402
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacilitator_hooks.go
More file actions
112 lines (93 loc) · 4.79 KB
/
facilitator_hooks.go
File metadata and controls
112 lines (93 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package x402
import (
"context"
)
// ============================================================================
// Facilitator Hook Context Types
// ============================================================================
// FacilitatorVerifyContext contains information passed to facilitator verify hooks
// Uses view interfaces for version-agnostic hooks
// PayloadBytes and RequirementsBytes provide escape hatch for extensions (e.g., Bazaar)
type FacilitatorVerifyContext struct {
Ctx context.Context
Payload PaymentPayloadView
Requirements PaymentRequirementsView
PayloadBytes []byte // Raw bytes for extensions needing full data
RequirementsBytes []byte // Raw bytes for extensions needing full data
}
// FacilitatorVerifyResultContext contains facilitator verify operation result and context
type FacilitatorVerifyResultContext struct {
FacilitatorVerifyContext
Result *VerifyResponse
}
// FacilitatorVerifyFailureContext contains facilitator verify operation failure and context
type FacilitatorVerifyFailureContext struct {
FacilitatorVerifyContext
Error error
}
// FacilitatorSettleContext contains information passed to facilitator settle hooks
// Uses view interfaces for version-agnostic hooks
// PayloadBytes and RequirementsBytes provide escape hatch for extensions (e.g., Bazaar)
type FacilitatorSettleContext struct {
Ctx context.Context
Payload PaymentPayloadView
Requirements PaymentRequirementsView
PayloadBytes []byte // Raw bytes for extensions needing full data
RequirementsBytes []byte // Raw bytes for extensions needing full data
}
// FacilitatorSettleResultContext contains facilitator settle operation result and context
type FacilitatorSettleResultContext struct {
FacilitatorSettleContext
Result *SettleResponse
}
// FacilitatorSettleFailureContext contains facilitator settle operation failure and context
type FacilitatorSettleFailureContext struct {
FacilitatorSettleContext
Error error
}
// ============================================================================
// Facilitator Hook Result Types
// ============================================================================
// FacilitatorBeforeHookResult represents the result of a facilitator "before" hook
// If Abort is true, the operation will be aborted with the given Reason
type FacilitatorBeforeHookResult struct {
Abort bool
Reason string
Message string
}
// FacilitatorVerifyFailureHookResult represents the result of a facilitator verify failure hook
// If Recovered is true, the hook has recovered from the failure with the given result
type FacilitatorVerifyFailureHookResult struct {
Recovered bool
Result *VerifyResponse
}
// FacilitatorSettleFailureHookResult represents the result of a facilitator settle failure hook
type FacilitatorSettleFailureHookResult struct {
Recovered bool
Result *SettleResponse
}
// ============================================================================
// Facilitator Hook Function Types
// ============================================================================
// FacilitatorBeforeVerifyHook is called before facilitator payment verification
// If it returns a result with Abort=true, verification will be skipped
// and an invalid VerifyResponse will be returned with the provided reason
type FacilitatorBeforeVerifyHook func(FacilitatorVerifyContext) (*FacilitatorBeforeHookResult, error)
// FacilitatorAfterVerifyHook is called after successful facilitator payment verification
// Any error returned will be logged but will not affect the verification result
type FacilitatorAfterVerifyHook func(FacilitatorVerifyResultContext) error
// FacilitatorOnVerifyFailureHook is called when facilitator payment verification fails
// If it returns a result with Recovered=true, the provided VerifyResponse
// will be returned instead of the error
type FacilitatorOnVerifyFailureHook func(FacilitatorVerifyFailureContext) (*FacilitatorVerifyFailureHookResult, error)
// FacilitatorBeforeSettleHook is called before facilitator payment settlement
// If it returns a result with Abort=true, settlement will be aborted
// and an error will be returned with the provided reason
type FacilitatorBeforeSettleHook func(FacilitatorSettleContext) (*FacilitatorBeforeHookResult, error)
// FacilitatorAfterSettleHook is called after successful facilitator payment settlement
// Any error returned will be logged but will not affect the settlement result
type FacilitatorAfterSettleHook func(FacilitatorSettleResultContext) error
// FacilitatorOnSettleFailureHook is called when facilitator payment settlement fails
// If it returns a result with Recovered=true, the provided SettleResponse
// will be returned instead of the error
type FacilitatorOnSettleFailureHook func(FacilitatorSettleFailureContext) (*FacilitatorSettleFailureHookResult, error)