185 lines
4.4 KiB
Go
185 lines
4.4 KiB
Go
package pay007
|
|
|
|
import "time"
|
|
|
|
const (
|
|
StatusPending = 0
|
|
StatusPaid = 1
|
|
StatusClosed = 2
|
|
StatusRefund = 3
|
|
)
|
|
|
|
// SubmitRequest creates a platform order and returns a cashier URL.
|
|
type SubmitRequest struct {
|
|
OutTradeNo string
|
|
Name string
|
|
Money string
|
|
Type string
|
|
ClientType string
|
|
NotifyURL string
|
|
ReturnURL string
|
|
Body string
|
|
Attach string
|
|
}
|
|
|
|
func (r SubmitRequest) params() map[string]string {
|
|
return compactParams(map[string]string{
|
|
"out_trade_no": r.OutTradeNo,
|
|
"name": r.Name,
|
|
"money": r.Money,
|
|
"type": r.Type,
|
|
"clienttype": r.ClientType,
|
|
"notify_url": r.NotifyURL,
|
|
"return_url": r.ReturnURL,
|
|
"body": r.Body,
|
|
"attach": r.Attach,
|
|
})
|
|
}
|
|
|
|
type SubmitResponse struct {
|
|
OrderNo string `json:"order_no"`
|
|
OutTradeNo string `json:"out_trade_no"`
|
|
Amount int64 `json:"amount"`
|
|
CashierURL string `json:"cashier_url"`
|
|
}
|
|
|
|
type QueryRequest struct {
|
|
TradeNo string
|
|
OutTradeNo string
|
|
}
|
|
|
|
func (r QueryRequest) params() map[string]string {
|
|
return compactParams(map[string]string{
|
|
"trade_no": r.TradeNo,
|
|
"out_trade_no": r.OutTradeNo,
|
|
})
|
|
}
|
|
|
|
type QueryResponse struct {
|
|
TradeNo string `json:"trade_no"`
|
|
OutTradeNo string `json:"out_trade_no"`
|
|
ChannelTradeNo string `json:"channel_trade_no"`
|
|
Amount int64 `json:"amount"`
|
|
Status int `json:"status"`
|
|
Completed bool `json:"completed"`
|
|
ChannelChecked bool `json:"channel_checked"`
|
|
PaidAt *time.Time `json:"paid_at"`
|
|
}
|
|
|
|
type RefundRequest struct {
|
|
TradeNo string
|
|
OutTradeNo string
|
|
Money string
|
|
Reason string
|
|
}
|
|
|
|
func (r RefundRequest) params() map[string]string {
|
|
return compactParams(map[string]string{
|
|
"trade_no": r.TradeNo,
|
|
"out_trade_no": r.OutTradeNo,
|
|
"money": r.Money,
|
|
"reason": r.Reason,
|
|
})
|
|
}
|
|
|
|
type RefundResponse struct {
|
|
RefundNo string `json:"refund_no"`
|
|
Status int `json:"status"`
|
|
}
|
|
|
|
type OrdersRequest struct {
|
|
OrderNo string
|
|
Status *int
|
|
Page int
|
|
PageSize int
|
|
}
|
|
|
|
func (r OrdersRequest) params() map[string]string {
|
|
params := compactParams(map[string]string{
|
|
"order_no": r.OrderNo,
|
|
})
|
|
if r.Status != nil {
|
|
params["status"] = itoa(*r.Status)
|
|
}
|
|
if r.Page > 0 {
|
|
params["page"] = itoa(r.Page)
|
|
}
|
|
if r.PageSize > 0 {
|
|
params["page_size"] = itoa(r.PageSize)
|
|
}
|
|
return params
|
|
}
|
|
|
|
type OrdersResponse struct {
|
|
Total int64 `json:"total"`
|
|
List []Order `json:"list"`
|
|
}
|
|
|
|
type Order struct {
|
|
TradeNo string `json:"trade_no"`
|
|
OutTradeNo string `json:"out_trade_no"`
|
|
Subject string `json:"subject"`
|
|
Amount int64 `json:"amount"`
|
|
Fee int64 `json:"fee"`
|
|
Status int `json:"status"`
|
|
ChannelID uint `json:"channel_id"`
|
|
ChannelTradeNo string `json:"channel_trade_no"`
|
|
ClientType string `json:"client_type"`
|
|
IsManual bool `json:"is_manual"`
|
|
PaidAt *time.Time `json:"paid_at"`
|
|
CreatedAt *time.Time `json:"created_at"`
|
|
}
|
|
|
|
type ManualRequest struct {
|
|
OutTradeNo string
|
|
Name string
|
|
Money string
|
|
Type string
|
|
Attach string
|
|
}
|
|
|
|
func (r ManualRequest) params() map[string]string {
|
|
return compactParams(map[string]string{
|
|
"out_trade_no": r.OutTradeNo,
|
|
"name": r.Name,
|
|
"money": r.Money,
|
|
"type": r.Type,
|
|
"attach": r.Attach,
|
|
})
|
|
}
|
|
|
|
type ManualResponse struct {
|
|
TradeNo string `json:"trade_no"`
|
|
OutTradeNo string `json:"out_trade_no"`
|
|
Amount int64 `json:"amount"`
|
|
Status int `json:"status"`
|
|
}
|
|
|
|
type StatsRequest struct {
|
|
Begin string
|
|
End string
|
|
}
|
|
|
|
func (r StatsRequest) params() map[string]string {
|
|
return compactParams(map[string]string{
|
|
"begin": r.Begin,
|
|
"end": r.End,
|
|
})
|
|
}
|
|
|
|
type StatsResponse struct {
|
|
OrderCount int64 `json:"order_count"`
|
|
TotalAmount int64 `json:"total_amount"`
|
|
TotalFee int64 `json:"total_fee"`
|
|
NetAmount int64 `json:"net_amount"`
|
|
TotalOrderCount int64 `json:"total_order_count"`
|
|
PaidOrderCount int64 `json:"paid_order_count"`
|
|
UnpaidOrderCount int64 `json:"unpaid_order_count"`
|
|
RefundedOrderCount int64 `json:"refunded_order_count"`
|
|
ClosedOrderCount int64 `json:"closed_order_count"`
|
|
ManualOrderCount int64 `json:"manual_order_count"`
|
|
ReceivedAmount int64 `json:"received_amount"`
|
|
RefundAmount int64 `json:"refund_amount"`
|
|
RefundCount int64 `json:"refund_count"`
|
|
}
|