-
Notifications
You must be signed in to change notification settings - Fork 5
/
pay.go
72 lines (61 loc) · 2.24 KB
/
pay.go
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
package payd
import (
"context"
"net/url"
"github.com/libsv/go-dpp"
validator "github.com/theflyingcodr/govalidator"
)
// PayRequest a request for making a payment.
type PayRequest struct {
PayToURL string `json:"payToURL"`
}
// Validate validates the request.
func (p PayRequest) Validate() error {
return validator.New().Validate("payToURL", func() error {
_, err := url.Parse(p.PayToURL)
return err
}).Err()
}
// DPPOutput an output matching what a dpp server expects.
type DPPOutput struct {
Amount uint64 `json:"amount"`
Script string `json:"script"`
Description string `json:"description"`
}
// DPPDestination defines a dpp payment destination object.
type DPPDestination struct {
Outputs []DPPOutput `json:"outputs"`
}
// MerchantData dpp from a dpp server.
type MerchantData struct {
Avatar string `json:"avatar"`
Name string `json:"name"`
Email string `json:"email"`
Address string `json:"address"`
PaymentReference string `json:"paymentReference"`
ExtendedData map[string]interface{} `json:"extendedData"`
}
// PaymentACK message used in BIP270.
// See https://github.com/moneybutton/bips/blob/master/bip-0270.mediawiki#paymentack
type PaymentACK struct {
Payment PaymentCreate `json:"payment"`
Memo string `json:"memo,omitempty"`
// A number indicating why the transaction was not accepted. 0 or undefined indicates no error.
// A 1 or any other positive integer indicates an error. The errors are left undefined for now;
// it is recommended only to use “1” and to fill the memo with a textual explanation about why
// the transaction was not accepted until further numbers are defined and standardised.
Error int `json:"error,omitempty"`
}
// PayStrategy for registering different payment strategies.
type PayStrategy interface {
PayService
Register(svc PayService, names ...string) PayStrategy
}
// PayService for sending payments to another wallet.
type PayService interface {
Pay(ctx context.Context, req PayRequest) (*dpp.PaymentACK, error)
}
// PayWriter will send a payment to another wallet or dpp server.
type PayWriter interface {
Pay(ctx context.Context, req PayRequest) error
}