-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
169 lines (147 loc) · 4.61 KB
/
api.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package ovo
import (
"context"
"net/http"
)
// Transaction is ovo transaction model.
type Transaction struct {
Type string `json:"type"`
ProcessingCode string `json:"processingCode"`
Amount float64 `json:"amount"`
Date string `json:"date"`
TraceNumber int `json:"traceNumber"`
HostTime string `json:"hostTime"`
HostDate string `json:"hostDate"`
ReferenceNumber int `json:"referenceNumber"`
ApprovalCode string `json:"approvalCode"`
ResponseCode string `json:"responseCode"`
TID string `json:"tid"`
MID string `json:"mid"`
TransactionRequestData transactionRequestData `json:"transactionRequestData"`
TransactionResponseData transactionResponseData `json:"transactionResponseData"`
}
// Create to create push-to-pay transaction.
func (c *Client) Create(request CreateRequest) (*Transaction, int, error) {
return c.CreateWithContext(context.Background(), request)
}
// CreateWithContext to create push-to-pay transaction with context.
func (c *Client) CreateWithContext(ctx context.Context, request CreateRequest) (*Transaction, int, error) {
if err := validate(&request); err != nil {
return nil, http.StatusBadRequest, err
}
var response Transaction
code, err := c.requester.Call(
ctx,
http.MethodPost,
c.baseURL,
c.appID,
c.key,
nil,
c.prepareCreateRequest(request),
&response,
)
if err != nil {
return nil, code, err
}
return &response, code, nil
}
// CreateReversal to create reversal push-to-pay transaction.
func (c *Client) CreateReversal(request CreateReversalRequest) (*Transaction, int, error) {
return c.CreateReversalWithContext(context.Background(), request)
}
// CreateReversalWithContext to create reversal push-to-pay transaction with context.
func (c *Client) CreateReversalWithContext(ctx context.Context, request CreateReversalRequest) (*Transaction, int, error) {
if err := validate(&request); err != nil {
return nil, http.StatusBadRequest, err
}
var response Transaction
code, err := c.requester.Call(
ctx,
http.MethodPost,
c.baseURL,
c.appID,
c.key,
nil,
c.prepareCreateReversalRequest(request),
&response,
)
if err != nil {
return nil, code, err
}
return &response, code, nil
}
// Void to void push-to-pay transaction.
func (c *Client) Void(request VoidRequest) (*Transaction, int, error) {
return c.VoidWithContext(context.Background(), request)
}
// VoidWithContext to void push-to-pay transaction with context.
func (c *Client) VoidWithContext(ctx context.Context, request VoidRequest) (*Transaction, int, error) {
if err := validate(&request); err != nil {
return nil, http.StatusBadRequest, err
}
var response Transaction
code, err := c.requester.Call(
ctx,
http.MethodPost,
c.baseURL,
c.appID,
c.key,
nil,
c.prepareVoidRequest(request),
&response,
)
if err != nil {
return nil, code, err
}
return &response, code, nil
}
// InquiryPhone to inquiry customer phone number.
func (c *Client) InquiryPhone(request InquiryPhoneRequest) (*Transaction, int, error) {
return c.InquiryPhoneWithContext(context.Background(), request)
}
// InquiryPhoneWithContext to inquiry customer phone number with context.
func (c *Client) InquiryPhoneWithContext(ctx context.Context, request InquiryPhoneRequest) (*Transaction, int, error) {
if err := validate(&request); err != nil {
return nil, http.StatusBadRequest, err
}
var response Transaction
code, err := c.requester.Call(
ctx,
http.MethodPost,
c.baseURL,
c.appID,
c.key,
nil,
c.prepareInquiryPhoneRequest(request),
&response,
)
if err != nil {
return nil, code, err
}
return &response, code, nil
}
// GetStatus to get transaction data & status.
func (c *Client) GetStatus(request GetStatusRequest) (*Transaction, int, error) {
return c.GetStatusWithContext(context.Background(), request)
}
// GetStatusWithContext to get transaction data & status with context.
func (c *Client) GetStatusWithContext(ctx context.Context, request GetStatusRequest) (*Transaction, int, error) {
if err := validate(&request); err != nil {
return nil, http.StatusBadRequest, err
}
var response Transaction
code, err := c.requester.Call(
ctx,
http.MethodPost,
c.baseURL,
c.appID,
c.key,
nil,
c.prepareGetStatusRequest(request),
&response,
)
if err != nil {
return nil, code, err
}
return &response, code, nil
}