generated from mythrnr/template-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_payment_auth.go
116 lines (98 loc) · 2.97 KB
/
api_payment_auth.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
111
112
113
114
115
116
package paypayopa
import (
"context"
"encoding/json"
"strconv"
"time"
)
type CreatePaymentAuthorizationPayload struct {
MerchantPaymentID string `json:"merchantPaymentId"`
UserAuthorizationID string `json:"userAuthorizationId"`
Amount *MoneyAmount `json:"amount"`
RequestedAt int64 `json:"requestedAt"`
ExpiresAt int64 `json:"expiresAt"`
StoreID string `json:"storeId"`
TerminalID string `json:"terminalId"`
OrderReceiptNumber string `json:"orderReceiptNumber"`
OrderDescription string `json:"orderDescription"`
OrderItems []*MerchantOrderItem `json:"orderItems"`
Metadata *json.RawMessage `json:"metadata"`
AgreeSimilarTransaction bool `json:"-"`
}
func createPaymentAuthorization(
ctx context.Context,
client *opaClient,
req *CreatePaymentAuthorizationPayload,
) (*Payment, *ResultInfo, error) {
const timeout = 30 * time.Second
res := &Payment{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v2/payments/preauthorize?agreeSimilarTransaction="+
strconv.FormatBool(req.AgreeSimilarTransaction),
res,
req,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}
type CapturePaymentAuthorizationPayload struct {
MerchantPaymentID string `json:"merchantPaymentId"`
Amount *MoneyAmount `json:"amount"`
MerchantCaptureID string `json:"merchantCaptureId"`
RequestedAt int64 `json:"requestedAt"`
OrderDescription string `json:"orderDescription"`
}
func capturePaymentAuthorization(
ctx context.Context,
client *opaClient,
req *CapturePaymentAuthorizationPayload,
) (*Payment, *ResultInfo, error) {
const timeout = 30 * time.Second
res := &Payment{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v2/payments/capture",
res,
req,
)
if err != nil ||
!info.Success() ||
info.Code == "USER_CONFIRMATION_REQUIRED" {
return nil, info, err
}
return res, info, nil
}
type RevertPaymentAuthorizationPayload struct {
MerchantRevertID string `json:"merchantRevertId"`
PaymentID string `json:"paymentId"`
RequestedAt int64 `json:"requestedAt"`
Reason string `json:"reason"`
}
type RevertedPaymentResponse struct {
Status string `json:"status"`
AcceptedAt int64 `json:"acceptedAt"`
PaymentID string `json:"paymentId"`
RequestedAt int64 `json:"requestedAt"`
Reason string `json:"reason"`
}
func revertPaymentAuthorization(
ctx context.Context,
client *opaClient,
req *RevertPaymentAuthorizationPayload,
) (*RevertedPaymentResponse, *ResultInfo, error) {
const timeout = 30 * time.Second
res := &RevertedPaymentResponse{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v2/payments/preauthorize/revert",
res,
req,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}