generated from mythrnr/template-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_req_order.go
91 lines (78 loc) · 2.53 KB
/
api_req_order.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
package paypayopa
import (
"context"
"encoding/json"
"time"
)
type CreatePendingPaymentPayload struct {
MerchantPaymentID string `json:"merchantPaymentId"`
UserAuthorizationID string `json:"userAuthorizationId"`
Amount *MoneyAmount `json:"amount"`
RequestedAt int64 `json:"requestedAt"`
ExpiryDate *int64 `json:"expiryDate"`
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"`
}
type PendingPayment struct {
MerchantPaymentID string `json:"merchantPaymentId"`
UserAuthorizationID string `json:"userAuthorizationId"`
Amount *MoneyAmount `json:"amount"`
RequestedAt int64 `json:"requestedAt"`
ExpiryDate *int64 `json:"expiryDate"`
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"`
}
func createPendingPayment(
ctx context.Context,
client *opaClient,
req *CreatePendingPaymentPayload,
) (*PendingPayment, *ResultInfo, error) {
const timeout = 30 * time.Second
res := &PendingPayment{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v1/requestOrder",
res,
req,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}
func cancelPendingOrder(
ctx context.Context,
client *opaClient,
merchantPaymentID string,
) (*ResultInfo, error) {
const timeout = 15 * time.Second
return client.DELETE(
ctxWithTimeout(ctx, timeout),
"/v1/requestOrder/"+merchantPaymentID,
)
}
func getRequestedPaymentDetails(
ctx context.Context,
client *opaClient,
merchantPaymentID string,
) (*Payment, *ResultInfo, error) {
const timeout = 15 * time.Second
res := &Payment{}
info, err := client.GET(
ctxWithTimeout(ctx, timeout),
"/v1/requestOrder/"+merchantPaymentID,
res,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}