-
Notifications
You must be signed in to change notification settings - Fork 1
/
pay_details.go
141 lines (120 loc) · 5.4 KB
/
pay_details.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
package linepay
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"time"
)
const (
PaymentsDetailsFieldsTransaction string = "RANSACTION"
PaymentsDetailsFieldsOrder string = "ORDER"
PaymentsDetailsFieldsDefault string = "ALL"
)
// if assign `TransactionIDs` and `OrderIDs` both at the same time, they should mean for the same record (like `AND` query).
type PaymentsDetailsRequest struct {
TransactionIDs []int64 ``
OrderIDs []string ``
Fields string ``
}
type PaymentsDetailsResponse struct {
ReturnCode string `json:"returnCode"`
ReturnMessage string `json:"returnMessage"`
Info []PaymentsDetailsInfoResponse `json:"info"`
}
type PaymentsDetailsInfoResponse struct {
TransactionID int64 `json:"transactionId"`
TransactionDate time.Time `json:"transactionDate"`
TransactionType string `json:"transactionType"`
PayStatus string `json:"payStatus"` // AUTHORIZATION, VOIDED_AUTHORIZATION, EXPIRED_AUTHORIZATION
ProductName string `json:"productName"`
MerchantName string `json:"merchantName"`
Currency string `json:"currency"`
AuthorizationExpireDate time.Time `json:"authorizationExpireDate"`
PayInfo []PaymentsDetailsInfoPayInfoResponse `json:"payInfo"`
RefundList []PaymentsDetailsInfoRefundListResponse `json:"refundList"` // in case of `Transaction` type
OriginalTransactionID int64 `json:"originalTransactionId"`
Packages []PaymentsDetailsInfoPackagesResponse `json:"packages"`
Shipping PaymentsDetailsInfoShippingResponse `json:"shipping"`
}
type PaymentsDetailsInfoPayInfoResponse struct {
Method string `json:"method"` // CREDIT_CARD, BALANCE, DISCOUNT
Amount int `json:"amount"` // sum(info[].payInfo[].amount) – sum(refundList[].refundAmount)
}
type PaymentsDetailsInfoRefundListResponse struct {
RefundTransactionID int64 `json:"refundTransactionId"`
TransactionType string `json:"transactionType"` // PAYMENT_REFUND, PARTIAL_REFUND
RefundAmount int `json:"refundAmount"`
RefundTransactionDate time.Time `json:"refundTransactionDate"`
}
type PaymentsDetailsInfoPackagesResponse struct {
ID string `json:"id"`
Amount int `json:"amount"`
UserFeeAmount int `json:"userFeeAmount"`
Name string `json:"name"`
Products []PaymentsDetailsInfoPackagesProductsResponse `json:"products"`
}
type PaymentsDetailsInfoPackagesProductsResponse struct {
ID string `json:"id"`
Name string `json:"name"`
ImageURL string `json:"imageUrl"`
Quantity int `json:"quantity"`
Price int `json:"price"`
OriginalPrice int `json:"originalPrice"`
}
type PaymentsDetailsInfoShippingResponse struct {
MethodID string `json:"methodId"`
FeeAmount int `json:"feeAmount"`
Address PaymentsDetailsInfoShippingAddressResponse `json:"address"`
}
type PaymentsDetailsInfoShippingAddressResponse struct {
Country string `json:"country"`
PostalCode string `json:"postalCode"`
State string `json:"state"`
City string `json:"city"`
Detail string `json:"detail"`
Optional string `json:"optional"`
Recipient PaymentsDetailsInfoShippingAddressRecipientResponse `json:"recipient"`
}
type PaymentsDetailsInfoShippingAddressRecipientResponse struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
FirstNameOptional string `json:"firstNameOptional"`
LastNameOptional string `json:"lastNameOptional"`
Email string `json:"email"`
PhoneNo string `json:"phoneNo"`
}
// PaymentsDetails
func (client *Client) PaymentsDetails(ctx context.Context, request *PaymentsDetailsRequest) (response *PaymentsDetailsResponse, err error) {
params := url.Values{}
for _, u := range request.TransactionIDs {
params.Add("transactionId", strconv.FormatInt(u, 10))
}
for _, u := range request.OrderIDs {
params.Add("orderId", u)
}
res, err := client.get(context.Background(), endpointV3PaymentsDetails, ¶ms)
if err != nil {
err = fmt.Errorf("PaymentsRequest post error = %v", err.Error())
return
}
defer res.Body.Close()
if res.StatusCode == http.StatusOK {
bodyBytes, ioerr := ioutil.ReadAll(res.Body)
if ioerr != nil {
err = fmt.Errorf("ReadAll read body failed: %s", ioerr.Error())
return
}
response = &PaymentsDetailsResponse{}
if err = json.Unmarshal(bodyBytes, response); err != nil {
return
}
} else {
err = fmt.Errorf("failed response, StatusCode: %d", res.StatusCode)
return
}
return
}