-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
163 lines (150 loc) · 5.57 KB
/
request.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
package ovo
import (
"strconv"
"time"
)
// CreateRequest is request model for create push-to-pay transaction.
type CreateRequest struct {
Amount float64 `validate:"required,gt=0"`
Phone string `validate:"e164" mod:"no_space,e164"`
MerchantInvoice string `validate:"required" mod:"no_space"`
ReferenceNumber int `validate:"required,gt=0,lt=1000000"`
BatchNo int `validate:"required,gt=0,lt=1000000"`
}
// CreateReversalRequest is request model for create reversal push-to-pay transaction.
type CreateReversalRequest struct {
Amount float64 `validate:"required,gt=0"`
Phone string `validate:"e164" mod:"no_space,e164"`
MerchantInvoice string `validate:"required" mod:"no_space"`
ReferenceNumber int `validate:"required,gt=0,lt=1000000"`
BatchNo int `validate:"required,gt=0,lt=1000000"`
}
// VoidRequest is request model for void push-to-pay transaction.
type VoidRequest struct {
Amount float64 `validate:"required,gt=0"`
Phone string `validate:"e164" mod:"no_space,e164"`
MerchantInvoice string `validate:"required" mod:"no_space"`
ReferenceNumber int `validate:"required,gt=0,lt=1000000"`
BatchNo int `validate:"required,gt=0,lt=1000000"`
}
// InquiryPhoneRequest is request model for inquiry phone number.
type InquiryPhoneRequest struct {
Phone string `validate:"e164" mod:"no_space,e164"`
}
// GetStatusRequest is request model for get transaction data & status.
type GetStatusRequest struct {
Amount float64 `validate:"required,gt=0"`
Phone string `validate:"e164" mod:"no_space,e164"`
MerchantInvoice string `validate:"required" mod:"no_space"`
ReferenceNumber int `validate:"required,gt=0,lt=1000000"`
BatchNo int `validate:"required,gt=0,lt=1000000"`
}
type request struct {
Type string `json:"type"`
ProcessingCode string `json:"processingCode"`
Amount float64 `json:"amount,omitempty"`
Date string `json:"date"`
ReferenceNumber string `json:"referenceNumber,omitempty"`
TID string `json:"tid"`
MID string `json:"mid"`
MerchantID string `json:"merchantId"`
StoreCode string `json:"storeCode"`
AppSource string `json:"appSource"`
TransactionRequestData transactionRequestData `json:"transactionRequestData"`
}
type transactionRequestData struct {
BatchNo string `json:"batchNo,omitempty"`
Phone string `json:"phone"`
MerchantInvoice string `json:"merchantInvoice,omitempty"`
}
func (c *Client) prepareCreateRequest(req CreateRequest) request {
return request{
Type: "0200",
ProcessingCode: "040000",
Amount: req.Amount,
Date: time.Now().Format("2006-01-02 15:04:05.000"),
ReferenceNumber: strconv.Itoa(req.ReferenceNumber),
TID: c.tid,
MID: c.mid,
MerchantID: c.merchantID,
StoreCode: c.storeCode,
AppSource: "POS",
TransactionRequestData: transactionRequestData{
BatchNo: strconv.Itoa(req.BatchNo),
Phone: req.Phone,
MerchantInvoice: req.MerchantInvoice,
},
}
}
func (c *Client) prepareCreateReversalRequest(req CreateReversalRequest) request {
return request{
Type: "0400",
ProcessingCode: "040000",
Amount: req.Amount,
Date: time.Now().Format("2006-01-02 15:04:05.000"),
ReferenceNumber: strconv.Itoa(req.ReferenceNumber),
TID: c.tid,
MID: c.mid,
MerchantID: c.merchantID,
StoreCode: c.storeCode,
AppSource: "POS",
TransactionRequestData: transactionRequestData{
BatchNo: strconv.Itoa(req.BatchNo),
Phone: req.Phone,
MerchantInvoice: req.MerchantInvoice,
},
}
}
func (c *Client) prepareVoidRequest(req VoidRequest) request {
return request{
Type: "0200",
ProcessingCode: "020040",
Amount: req.Amount,
Date: time.Now().Format("2006-01-02 15:04:05.000"),
ReferenceNumber: strconv.Itoa(req.ReferenceNumber),
TID: c.tid,
MID: c.mid,
MerchantID: c.merchantID,
StoreCode: c.storeCode,
AppSource: "POS",
TransactionRequestData: transactionRequestData{
BatchNo: strconv.Itoa(req.BatchNo),
Phone: req.Phone,
MerchantInvoice: req.MerchantInvoice,
},
}
}
func (c *Client) prepareInquiryPhoneRequest(req InquiryPhoneRequest) request {
return request{
Type: "0100",
ProcessingCode: "050000",
Date: time.Now().Format("2006-01-02 15:04:05.000"),
TID: c.tid,
MID: c.mid,
MerchantID: c.merchantID,
StoreCode: c.storeCode,
AppSource: "POS",
TransactionRequestData: transactionRequestData{
Phone: req.Phone,
},
}
}
func (c *Client) prepareGetStatusRequest(req GetStatusRequest) request {
return request{
Type: "0100",
ProcessingCode: "040000",
Amount: req.Amount,
Date: time.Now().Format("2006-01-02 15:04:05.000"),
ReferenceNumber: strconv.Itoa(req.ReferenceNumber),
TID: c.tid,
MID: c.mid,
MerchantID: c.merchantID,
StoreCode: c.storeCode,
AppSource: "POS",
TransactionRequestData: transactionRequestData{
BatchNo: strconv.Itoa(req.BatchNo),
Phone: req.Phone,
MerchantInvoice: req.MerchantInvoice,
},
}
}