123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package cashcoupons
- import (
- "context"
- "fmt"
- nethttp "net/http"
- neturl "net/url"
- "strings"
- "git.nanodreamtech.com/sg/wechatpay-go/core"
- "git.nanodreamtech.com/sg/wechatpay-go/core/consts"
- "git.nanodreamtech.com/sg/wechatpay-go/services"
- )
- type CouponApiService services.Service
- func (a *CouponApiService) ListCouponsByFilter(ctx context.Context, req ListCouponsByFilterRequest) (resp *CouponCollection, result *core.APIResult, err error) {
- var (
- localVarHTTPMethod = nethttp.MethodGet
- localVarPostBody interface{}
- localVarQueryParams neturl.Values
- localVarHeaderParams = nethttp.Header{}
- )
-
- if req.Openid == nil {
- return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in ListCouponsByFilterRequest")
- }
- localVarPath := consts.WechatPayAPIServer + "/v3/marketing/favor/users/{openid}/coupons"
-
- localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1)
-
- if req.Appid == nil {
- return nil, nil, fmt.Errorf("field `Appid` is required and must be specified in ListCouponsByFilterRequest")
- }
-
- localVarQueryParams = neturl.Values{}
- localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, ""))
- if req.StockId != nil {
- localVarQueryParams.Add("stock_id", core.ParameterToString(*req.StockId, ""))
- }
- if req.Status != nil {
- localVarQueryParams.Add("status", core.ParameterToString(*req.Status, ""))
- }
- if req.CreatorMchid != nil {
- localVarQueryParams.Add("creator_mchid", core.ParameterToString(*req.CreatorMchid, ""))
- }
- if req.SenderMchid != nil {
- localVarQueryParams.Add("sender_mchid", core.ParameterToString(*req.SenderMchid, ""))
- }
- if req.AvailableMchid != nil {
- localVarQueryParams.Add("available_mchid", core.ParameterToString(*req.AvailableMchid, ""))
- }
- if req.Offset != nil {
- localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, ""))
- }
- if req.Limit != nil {
- localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, ""))
- }
-
- localVarHTTPContentTypes := []string{}
-
- localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
-
- result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
- if err != nil {
- return nil, result, err
- }
-
- resp = new(CouponCollection)
- err = core.UnMarshalResponse(result.Response, resp)
- if err != nil {
- return nil, result, err
- }
- return resp, result, nil
- }
- func (a *CouponApiService) QueryCoupon(ctx context.Context, req QueryCouponRequest) (resp *Coupon, result *core.APIResult, err error) {
- var (
- localVarHTTPMethod = nethttp.MethodGet
- localVarPostBody interface{}
- localVarQueryParams neturl.Values
- localVarHeaderParams = nethttp.Header{}
- )
-
- if req.CouponId == nil {
- return nil, nil, fmt.Errorf("field `CouponId` is required and must be specified in QueryCouponRequest")
- }
- if req.Openid == nil {
- return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in QueryCouponRequest")
- }
- localVarPath := consts.WechatPayAPIServer + "/v3/marketing/favor/users/{openid}/coupons/{coupon_id}"
-
- localVarPath = strings.Replace(localVarPath, "{"+"coupon_id"+"}", neturl.PathEscape(core.ParameterToString(*req.CouponId, "")), -1)
- localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1)
-
- if req.Appid == nil {
- return nil, nil, fmt.Errorf("field `Appid` is required and must be specified in QueryCouponRequest")
- }
-
- localVarQueryParams = neturl.Values{}
- localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, ""))
-
- localVarHTTPContentTypes := []string{}
-
- localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
-
- result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
- if err != nil {
- return nil, result, err
- }
-
- resp = new(Coupon)
- err = core.UnMarshalResponse(result.Response, resp)
- if err != nil {
- return nil, result, err
- }
- return resp, result, nil
- }
- func (a *CouponApiService) SendCoupon(ctx context.Context, req SendCouponRequest) (resp *SendCouponResponse, result *core.APIResult, err error) {
- var (
- localVarHTTPMethod = nethttp.MethodPost
- localVarPostBody interface{}
- localVarQueryParams neturl.Values
- localVarHeaderParams = nethttp.Header{}
- )
-
- if req.Openid == nil {
- return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in SendCouponRequest")
- }
- localVarPath := consts.WechatPayAPIServer + "/v3/marketing/favor/users/{openid}/coupons"
-
- localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1)
-
-
- localVarPostBody = &SendCouponBody{
- StockId: req.StockId,
- OutRequestNo: req.OutRequestNo,
- Appid: req.Appid,
- StockCreatorMchid: req.StockCreatorMchid,
- CouponValue: req.CouponValue,
- CouponMinimum: req.CouponMinimum,
- }
-
- localVarHTTPContentTypes := []string{"application/json"}
-
- localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
-
- result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
- if err != nil {
- return nil, result, err
- }
-
- resp = new(SendCouponResponse)
- err = core.UnMarshalResponse(result.Response, resp)
- if err != nil {
- return nil, result, err
- }
- return resp, result, nil
- }
|