generated from mythrnr/template-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_qrcode.go
110 lines (96 loc) · 3.5 KB
/
api_qrcode.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package paypayopa
import (
"context"
"encoding/json"
"time"
)
type CreateQRCodePayload struct {
MerchantPaymentID string `json:"merchantPaymentId"`
Amount *MoneyAmount `json:"amount"`
OrderDescription string `json:"orderDescription"`
OrderItems []*MerchantOrderItem `json:"orderItems"`
Metadata interface{} `json:"metadata"`
CodeType CodeType `json:"codeType"`
StoreInfo string `json:"storeInfo"`
StoreID string `json:"storeId"`
TerminalID string `json:"terminalId"`
RequestedAt int64 `json:"requestedAt"`
RedirectURL string `json:"redirectUrl"`
RedirectType RedirectType `json:"redirectType"`
UserAgent string `json:"userAgent"`
IsAuthorization bool `json:"isAuthorization"`
AuthorizationExpiry *int64 `json:"authorizationExpiry"`
}
type QRCodeResponse struct {
CodeID string `json:"codeId"`
URL string `json:"url"`
DeepLink string `json:"deeplink"`
ExpiryDate int64 `json:"expiryDate"`
MerchantPaymentID string `json:"merchantPaymentId"`
Amount *MoneyAmount `json:"amount"`
OrderDescription string `json:"orderDescription"`
OrderItems []*MerchantOrderItemResponse `json:"orderItems"`
Metadata *json.RawMessage `json:"metadata"`
CodeType string `json:"codeType"`
StoreInfo string `json:"storeInfo"`
StoreID string `json:"storeId"`
TerminalID string `json:"terminalId"`
RequestedAt int64 `json:"requestedAt"`
RedirectURL string `json:"redirectUrl"`
RedirectType RedirectType `json:"redirectType"`
IsAuthorization bool `json:"isAuthorization"`
Authorizationexpiry *int64 `json:"authorizationExpiry"`
}
type MerchantOrderItemResponse struct {
Name string `json:"name"`
Category string `json:"category"`
Quantity int `json:"quantity"`
ProductID string `json:"productId"`
UnitPrice *MoneyAmount `json:"unit_price"`
}
func createQRCode(
ctx context.Context,
client *opaClient,
req *CreateQRCodePayload,
) (*QRCodeResponse, *ResultInfo, error) {
const timeout = 30 * time.Second
res := &QRCodeResponse{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v2/codes",
res,
req,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}
func deleteQRCode(
ctx context.Context,
client *opaClient,
codeID string,
) (*ResultInfo, error) {
const timeout = 15 * time.Second
return client.DELETE(
ctxWithTimeout(ctx, timeout),
"/v2/codes/"+codeID,
)
}
func getCodePaymentDetails(
ctx context.Context,
client *opaClient,
merchantPaymentID string,
) (*Payment, *ResultInfo, error) {
const timeout = 15 * time.Second
res := &Payment{}
info, err := client.GET(
ctxWithTimeout(ctx, timeout),
"/v2/codes/payments/"+merchantPaymentID,
res,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}