Skip to content

Commit

Permalink
add new api
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Dec 18, 2024
1 parent 6fe2b99 commit 798424e
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 20 deletions.
2 changes: 1 addition & 1 deletion alipay/v3/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
v3DataBillDownloadUrlQuery = "/v3/alipay/data/dataservice/bill/downloadurl/query" // 查询对账单下载地址
v3TradePrecreate = "/v3/alipay/trade/precreate" // 统一收单线下交易预创建
v3TradeCreate = "/v3/alipay/trade/create" // 统一收单交易创建接口
v3TradeOrderInfoSync = "/v3/alipay/trade/orderinfo/sync" // 支付宝订单信息同步接口

// 商家扣款
v3UserAgreementQuery = "/v3/alipay/user/agreement/query" // 支付宝个人代扣协议查询接口
Expand All @@ -50,7 +51,6 @@ const (
v3TradeOrderSettle = "/v3/alipay/trade/order/settle" // 统一收单交易结算接口
v3TradeOrderSettleQuery = "/v3/alipay/trade/order/settle/query" // 交易分账查询接口
v3TradeOrderOnSettleQuery = "/v3/alipay/trade/order/onsettle/query" // 分账剩余金额查询
v3TradeOrderInfoSync = "/v3/alipay/trade/orderinfo/sync" // 支付宝订单信息同步接口

// 刷脸付
v3ZolozAuthenticationSmilepayInitialize = "/v3/zoloz/authentication/smilepay/initialize" // 刷脸支付初始化
Expand Down
8 changes: 4 additions & 4 deletions alipay/v3/fund_auth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-pay/gopay"
)

// 资金授权操作查询接口
// 资金授权操作查询接口 alipay.fund.auth.operation.detail.query
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOperationDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOperationDetailQueryRsp, err error) {
authorization, err := a.authorization(MethodPost, v3FundAuthOperationDetailQuery, bm)
Expand All @@ -33,7 +33,7 @@ func (a *ClientV3) FundAuthOperationDetailQuery(ctx context.Context, bm gopay.Bo
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 资金授权冻结接口
// 资金授权冻结接口 alipay.fund.auth.order.freeze
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOrderFreeze(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderFreezeRsp, err error) {
err = bm.CheckEmptyError("auth_code", "auth_code_type", "out_order_no", "out_request_no", "order_title", "product_code", "amount")
Expand Down Expand Up @@ -61,7 +61,7 @@ func (a *ClientV3) FundAuthOrderFreeze(ctx context.Context, bm gopay.BodyMap) (a
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 资金授权解冻接口
// 资金授权解冻接口 alipay.fund.auth.order.unfreeze
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOrderUnfreeze(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderUnfreezeRsp, err error) {
err = bm.CheckEmptyError("auth_no", "out_request_no", "amount", "remark")
Expand Down Expand Up @@ -89,7 +89,7 @@ func (a *ClientV3) FundAuthOrderUnfreeze(ctx context.Context, bm gopay.BodyMap)
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 资金授权发码接口
// 资金授权发码接口 alipay.fund.auth.order.voucher.create
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOrderVoucherCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderVoucherCreateRsp, err error) {
err = bm.CheckEmptyError("out_order_no", "out_request_no", "order_title", "amount", "product_code")
Expand Down
12 changes: 6 additions & 6 deletions alipay/v3/member_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-pay/gopay"
)

// 换取授权访问令牌
// 换取授权访问令牌 alipay.system.oauth.token
// StatusCode = 200 is success
func (a *ClientV3) SystemOauthToken(ctx context.Context, bm gopay.BodyMap) (aliRsp *SystemOauthTokenRsp, err error) {
err = bm.CheckEmptyError("grant_type")
Expand Down Expand Up @@ -37,7 +37,7 @@ func (a *ClientV3) SystemOauthToken(ctx context.Context, bm gopay.BodyMap) (aliR
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 身份认证记录查询
// 身份认证记录查询 alipay.user.certify.open.query
// StatusCode = 200 is success
func (a *ClientV3) UserCertifyOpenQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenQueryRsp, err error) {
err = bm.CheckEmptyError("certify_id")
Expand Down Expand Up @@ -66,7 +66,7 @@ func (a *ClientV3) UserCertifyOpenQuery(ctx context.Context, bm gopay.BodyMap) (
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 身份认证初始化服务
// 身份认证初始化服务 alipay.user.certify.open.initialize
// StatusCode = 200 is success
func (a *ClientV3) UserCertifyOpenInitialize(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenInitializeRsp, err error) {
err = bm.CheckEmptyError("outer_order_no", "biz_code", "identity_param")
Expand Down Expand Up @@ -94,7 +94,7 @@ func (a *ClientV3) UserCertifyOpenInitialize(ctx context.Context, bm gopay.BodyM
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 支付宝会员授权信息查询接口
// 支付宝会员授权信息查询接口 alipay.user.info.share
// StatusCode = 200 is success
func (a *ClientV3) UserInfoShare(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserInfoShareRsp, err error) {
err = bm.CheckEmptyError("avatar", "city", "nick_name", "province")
Expand Down Expand Up @@ -122,7 +122,7 @@ func (a *ClientV3) UserInfoShare(ctx context.Context, bm gopay.BodyMap) (aliRsp
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 用户授权关系查询
// 用户授权关系查询 alipay.open.auth.userauth.relationship.query
// StatusCode = 200 is success
func (a *ClientV3) UserAuthRelationshipQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAuthRelationshipQueryRsp, err error) {
err = bm.CheckEmptyError("scopes")
Expand Down Expand Up @@ -151,7 +151,7 @@ func (a *ClientV3) UserAuthRelationshipQuery(ctx context.Context, bm gopay.BodyM
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 查询解除授权明细
// 查询解除授权明细 alipay.user.deloauth.detail.query
// StatusCode = 200 is success
func (a *ClientV3) UserDelOauthDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserDelOauthDetailQueryRsp, err error) {
err = bm.CheckEmptyError("date", "limit", "offset")
Expand Down
261 changes: 261 additions & 0 deletions alipay/v3/merchant_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
package alipay

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"

"github.com/go-pay/gopay"
)

// 支付宝个人代扣协议查询接口 alipay.user.agreement.query
// StatusCode = 200 is success
func (a *ClientV3) UserAgreementQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAgreementQueryRsp, err error) {
if bm.GetString("alipay_user_id") == gopay.NULL && bm.GetString("alipay_open_id") == gopay.NULL {
return nil, errors.New("alipay_user_id and alipay_open_id are not allowed to be null at the same time")
}
uri := v3UserAgreementQuery + "?" + bm.EncodeURLParams()
authorization, err := a.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, bs, err := a.doGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserAgreementQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}

return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 支付宝个人代扣协议解约接口 alipay.user.agreement.unsign
// StatusCode = 200 is success
func (a *ClientV3) UserAgreementPageUnSign(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAgreementPageUnSignRsp, err error) {
if bm.GetString("alipay_user_id") == gopay.NULL && bm.GetString("alipay_open_id") == gopay.NULL && bm.GetString("alipay_logon_id") == gopay.NULL {
return nil, errors.New("alipay_user_id and alipay_open_id and alipay_logon_id are not allowed to be null at the same time")
}
if bm.GetString("external_agreement_no") == gopay.NULL && bm.GetString("agreement_no") == gopay.NULL {
return nil, errors.New("external_agreement_no and agreement_no are not allowed to be null at the same time")
}
authorization, err := a.authorization(MethodPost, v3UserAgreementPageUnSign, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3UserAgreementPageUnSign, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserAgreementPageUnSignRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 分账关系绑定 alipay.trade.royalty.relation.bind
// StatusCode = 200 is success
func (a *ClientV3) TradeRelationBind(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeRelationBindRsp, err error) {
err = bm.CheckEmptyError("receiver_list", "out_request_no")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3TradeRoyaltyRelationBind, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3TradeRoyaltyRelationBind, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeRelationBindRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 分账关系解绑 alipay.trade.royalty.relation.unbind
// StatusCode = 200 is success
func (a *ClientV3) TradeRelationUnbind(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeRelationUnbindRsp, err error) {
err = bm.CheckEmptyError("receiver_list", "out_request_no")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3TradeRoyaltyRelationUnbind, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3TradeRoyaltyRelationUnbind, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeRelationUnbindRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 分账关系查询 alipay.trade.royalty.relation.batchquery
// StatusCode = 200 is success
func (a *ClientV3) TradeRelationBatchQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeRelationBatchQueryRsp, err error) {
authorization, err := a.authorization(MethodPost, v3TradeRoyaltyRelationBatchQuery, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3TradeRoyaltyRelationBatchQuery, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeRelationBatchQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 分账比例查询 alipay.trade.royalty.rate.query
// StatusCode = 200 is success
func (a *ClientV3) TradeRoyaltyRateQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeRoyaltyRateQueryRsp, err error) {
err = bm.CheckEmptyError("out_request_no")
if err != nil {
return nil, err
}
uri := v3TradeRoyaltyRateQuery + "?" + bm.EncodeURLParams()
authorization, err := a.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, bs, err := a.doGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeRoyaltyRateQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}

return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 统一收单交易结算接口 alipay.trade.order.settle
// StatusCode = 200 is success
func (a *ClientV3) TradeOrderSettle(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeOrderSettleRsp, err error) {
err = bm.CheckEmptyError("out_request_no", "trade_no", "royalty_parameters")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3TradeOrderSettle, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3TradeOrderSettle, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeOrderSettleRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 交易分账查询接口 alipay.trade.order.settle.query
// StatusCode = 200 is success
func (a *ClientV3) TradeOrderSettleQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeOrderSettleQueryRsp, err error) {
uri := v3TradeOrderSettleQuery + "?" + bm.EncodeURLParams()
authorization, err := a.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, bs, err := a.doGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeOrderSettleQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}

return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 分账剩余金额查询 alipay.trade.order.onsettle.query
// StatusCode = 200 is success
func (a *ClientV3) TradeOrderOnSettleQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeOrderOnSettleQueryRsp, err error) {
err = bm.CheckEmptyError("trade_no")
if err != nil {
return nil, err
}
uri := v3TradeOrderOnSettleQuery + "?" + bm.EncodeURLParams()
authorization, err := a.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, bs, err := a.doGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
aliRsp = &TradeOrderOnSettleQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}

return aliRsp, a.autoVerifySignByCert(res, bs)
}
Loading

0 comments on commit 798424e

Please sign in to comment.