-
Notifications
You must be signed in to change notification settings - Fork 0
/
alipay_api_trade_cancel.go
64 lines (54 loc) · 2.07 KB
/
alipay_api_trade_cancel.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
package alipay
import (
"encoding/json"
"errors"
)
/*
* 付款码支付
* 统一收单交易撤销接口
* alipay.trade.cancel
*/
// 统一收单交易撤销接口 请求 参数
type TradeCancelRequest struct {
OutTradeNo string `json:"out_trade_no,omitempty"` //特殊可选 64 原支付请求的商户订单号,和支付宝交易号不能同时为空 20150320010101001
TradeNo string `json:"trade_no,omitempty"` //特殊可选 64 支付宝交易号,和商户订单号不能同时为空 2014112611001004680073956707
}
func (t *TradeCancelRequest) HttpMethod() string {
return "POST"
}
func (t *TradeCancelRequest) ApiParamMethod() string {
return "alipay.trade.cancel"
}
// 从响应数据中生成结构体
func (t *TradeCancelRequest) GenResponse(data []byte) (IResponse, error) {
type tempResponse struct {
TradeCancelResponse TradeCancelResponse `json:"alipay_trade_cancel_response"`
}
var tResp tempResponse
err := json.Unmarshal(data, &tResp)
if err != nil {
return nil, err
}
return tResp.TradeCancelResponse, nil
}
func (t *TradeCancelRequest) DoValidate() error {
if len(t.OutTradeNo) < 1 && len(t.TradeNo) < 1 {
err := errors.New("原支付请求的商户订单号,和支付宝交易号不能同时为空")
return err
}
return nil
}
// 统一收单交易撤销接口 响应 参数
type TradeCancelResponse struct {
TradeNo string `json:"trade_no"` //必选 64 支付宝交易号; 当发生交易关闭或交易退款时返回; 2013112011001004330000121536
OutTradeNo string `json:"out_trade_no"` //必选 64 商户订单号 6823789339978248
RetryFlag string `json:"retry_flag"` //必选 1 是否需要重试 N
Action string `json:"action"` //必选 10 本次撤销触发的交易动作,接口调用成功且交易存在时返回。
//可能的返回值:
//close:交易未支付,触发关闭交易动作,无退款;
//refund:交易已支付,触发交易退款动作;
//未返回:未查询到交易,或接口调用失败;
}
func (t TradeCancelResponse) ApiParamMethod() string {
return "alipay.trade.cancel"
}