-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment_confirmation.go
92 lines (77 loc) · 2.2 KB
/
payment_confirmation.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package yookassa
import (
"fmt"
jsoniter "github.com/json-iterator/go"
)
const (
ConfirmationRedirect = "redirect"
ConfirmationQR = "qr"
ConfirmationEmbeded = "embedded"
ConfirmationExternal = "external"
)
type Confirmation struct {
Type string `json:"type"`
Locale string `json:"locale,omitempty"`
}
type RedirectConfirmation struct {
Type string `json:"type"`
ReturnURL string `json:"return_url"`
Locale string `json:"locale,omitempty"`
Enforce bool `json:"enforce,omitempty"`
}
type redirectConfirmation struct {
Type string `json:"type"`
ReturnURL string `json:"return_url"`
Locale string `json:"locale,omitempty"`
Enforce bool `json:"enforce,omitempty"`
}
// MarshalJSON returns the JSON encoding of RedirectConfirmation.
//
// No parameters.
// Returns a byte slice and an error.
func (c *RedirectConfirmation) MarshalJSON() ([]byte, error) {
return jsoniter.Marshal(&redirectConfirmation{
Type: ConfirmationRedirect,
ReturnURL: c.ReturnURL,
Locale: c.Locale,
Enforce: c.Enforce,
})
}
// Response
type ConfirmationInfo struct {
Type string `json:"type"`
Details interface{} `json:"details,omitempty"`
}
func (c *ConfirmationInfo) UnmarshalJSON(data []byte) error {
c.Type = jsoniter.Get(data, "type").ToString()
switch c.Type {
case ConfirmationRedirect:
c.Details = &RedirectConfirmationDetails{}
case ConfirmationQR:
c.Details = &QRCodeConfirmationDetails{}
case ConfirmationEmbeded:
c.Details = &EmbededConfirmationDetails{}
case ConfirmationExternal:
c.Details = nil
default:
return fmt.Errorf("invalid confirmation type %q", c.Type) // nolint:goerr113
}
if c.Details != nil {
return jsoniter.Unmarshal(data, c.Details)
}
return nil
}
type RedirectConfirmationDetails struct {
Type string `json:"type"`
Enforce bool `json:"enforce"`
ConfirmationURL string `json:"confirmation_url"`
ReturnURL string `json:"return_url"`
}
type EmbededConfirmationDetails struct {
Type string `json:"type"`
ConfirmationToken string `json:"confirmation_token"`
}
type QRCodeConfirmationDetails struct {
Type string `json:"type"`
ConfirmationData string `json:"confirmation_data"`
}