-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpayment_refund.go
113 lines (105 loc) · 2.99 KB
/
payment_refund.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
package rm
import (
"context"
"time"
)
// RefundPaymentRequest :
type RefundPaymentRequest struct {
TransactionID string `json:"transactionId"`
Refund struct {
Type string `json:"type"`
CurrencyType string `json:"currencyType"`
Amount uint `json:"amount"`
} `json:"refund"`
Reason string `json:"reason"`
}
// RefundPaymentResponse :
type RefundPaymentResponse struct {
Item struct {
Store struct {
ID string `json:"id"`
Name string `json:"name"`
ImageURL string `json:"imageUrl"`
AddressLine1 string `json:"addressLine1"`
AddressLine2 string `json:"addressLine2"`
PostCode string `json:"postCode"`
City string `json:"city"`
State string `json:"state"`
Country string `json:"country"`
CountryCode string `json:"countryCode"`
PhoneNumber string `json:"phoneNumber"`
GeoLocation struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
} `json:"geoLocation"`
Status string `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
} `json:"store"`
ReferenceID string `json:"referenceId"`
TransactionID string `json:"transactionId"`
Order struct {
ID string `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
Amount int `json:"amount"`
} `json:"order"`
TerminalID string `json:"terminalId"`
Payee struct {
UserID string `json:"userId"`
} `json:"payee"`
CurrencyType string `json:"currencyType"`
BalanceAmount int `json:"balanceAmount"`
Voucher interface{} `json:"voucher"`
Platform string `json:"platform"`
Method string `json:"method"`
TransactionAt time.Time `json:"transactionAt"`
Type string `json:"type"`
Status string `json:"status"`
Region string `json:"region"`
ExtraInfo struct {
Card struct {
} `json:"card"`
} `json:"extraInfo"`
Source string `json:"source"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
} `json:"item"`
Code string `json:"code"`
}
// RefundPayment :
func (c *Client) RefundPayment(
ctx context.Context,
req RefundPaymentRequest,
) (*RefundPaymentResponse, error) {
pymt, err := c.GetPaymentByTransactionID(ctx, req.TransactionID)
if err != nil {
return nil, err
}
// if pymt.Item.Status != PaymentStatusSuccess {
// return nil,
// }
// if amount is zero, we will perform full refunded
if req.Refund.Amount == 0 {
req.Refund.Type = "FULL"
// FIXME: support partial refund
// if orderResp.Item.Order.Amount < orderResp.Item.BalanceAmount {
// }
req.Refund.Amount = pymt.Item.Order.Amount
}
if req.Refund.CurrencyType == "" {
req.Refund.CurrencyType = "MYR"
}
resp := new(RefundPaymentResponse)
if err := c.do(
ctx,
"refund_payment",
"post",
c.openEndpoint+"/v3/payment/refund",
req,
resp,
); err != nil {
return nil, err
}
return resp, nil
}