// Copyright 2021 Tencent Inc. All rights reserved. // // 营销商家券对外API // // No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) // // API version: 0.0.11 // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT. package merchantexclusivecoupon 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 // AssociateTradeInfo 关联订单信息 // // 适用场景:将有效态(未核销)的商家券与订单信息关联,用于后续参与摇奖&返佣激励等操作的统计 // 适用对象:如普通服务商、普通直连商户 // 频率:500QPS // 前置条件:已为用户发券,且调用查询接口查到用户的券code、批次ID等信息 // 注意事项:仅对有关联订单需求的券进行该操作 // 是否支持幂等:是 func (a *CouponApiService) AssociateTradeInfo(ctx context.Context, req AssociateTradeInfoRequest) (resp *AssociateTradeInfoResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/associate" // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = req // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract AssociateTradeInfoResponse from Http Response resp = new(AssociateTradeInfoResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // DeactivateCoupon 使券失效 // // 失效一张券,券被失效后无法再被核销 func (a *CouponApiService) DeactivateCoupon(ctx context.Context, req DeactivateCouponRequest) (resp *DeactivateCouponResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/deactivate" // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = req // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract DeactivateCouponResponse from Http Response resp = new(DeactivateCouponResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // DisassociateTradeInfo 取消关联订单信息 // // 适用场景:取消商家券与订单信息的关联关系 // 适用对象:如普通服务商、普通直连商户 // 频率:500QPS // 前置条件:已调用关联接口为券创建过关联关系 // 注意事项:建议取消前调用查询接口,查到当前关联的商户单号并确认后,再进行取消操作 // 是否支持幂等:是 func (a *CouponApiService) DisassociateTradeInfo(ctx context.Context, req DisassociateTradeInfoRequest) (resp *DisassociateTradeInfoResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/disassociate" // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = req // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract DisassociateTradeInfoResponse from Http Response resp = new(DisassociateTradeInfoResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // ListCouponsByFilter 根据过滤条件查询用户的券 // // 商户自定义筛选条件(如创建商户号、归属商户号、发放商户号等),查询指定微信用户卡包中满足对应条件的所有商家券信息。 func (a *CouponApiService) ListCouponsByFilter(ctx context.Context, req ListCouponsByFilterRequest) (resp *CouponListResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodGet localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) // Make sure Path Params are properly set if req.Openid == nil { return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in ListCouponsByFilterRequest") } localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/users/{openid}/coupons" // Build Path with Path Params localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1) // Make sure All Required Params are properly set if req.Appid == nil { return nil, nil, fmt.Errorf("field `Appid` is required and must be specified in ListCouponsByFilterRequest") } // Setup Query Params localVarQueryParams = neturl.Values{} localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, "")) if req.StockId != nil { localVarQueryParams.Add("stock_id", core.ParameterToString(*req.StockId, "")) } if req.CreatorMerchant != nil { localVarQueryParams.Add("creator_merchant", core.ParameterToString(*req.CreatorMerchant, "")) } if req.BelongMerchant != nil { localVarQueryParams.Add("belong_merchant", core.ParameterToString(*req.BelongMerchant, "")) } if req.SenderMerchant != nil { localVarQueryParams.Add("sender_merchant", core.ParameterToString(*req.SenderMerchant, "")) } if req.Offset != nil { localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, "")) } if req.Limit != nil { localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, "")) } if req.CouponState != nil { localVarQueryParams.Add("coupon_state", core.ParameterToString(*req.CouponState, "")) } // Determine the Content-Type Header localVarHTTPContentTypes := []string{} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract CouponListResponse from Http Response resp = new(CouponListResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // QueryCoupon 查询用户券详情 // // 商户可通过该接口查询微信用户卡包中某一张商家券的详情信息。 func (a *CouponApiService) QueryCoupon(ctx context.Context, req QueryCouponRequest) (resp *CouponEntity, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodGet localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) // Make sure Path Params are properly set if req.CouponCode == nil { return nil, nil, fmt.Errorf("field `CouponCode` is required and must be specified in QueryCouponRequest") } if req.Appid == nil { return nil, nil, fmt.Errorf("field `Appid` 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/busifavor/users/{openid}/coupons/{coupon_code}/appids/{appid}" // Build Path with Path Params localVarPath = strings.Replace(localVarPath, "{"+"coupon_code"+"}", neturl.PathEscape(core.ParameterToString(*req.CouponCode, "")), -1) localVarPath = strings.Replace(localVarPath, "{"+"appid"+"}", neturl.PathEscape(core.ParameterToString(*req.Appid, "")), -1) localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1) // Make sure All Required Params are properly set // Determine the Content-Type Header localVarHTTPContentTypes := []string{} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract CouponEntity from Http Response resp = new(CouponEntity) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // ReturnCoupon 申请退券 // // 商户可以在退款之后调用退券API,调用了该接口后,券在用户卡包内正常展示,用户可在有效期内正常使用该优惠券。 // 若券过期状态下退款,可不用调用该退券API。 // 前置条件:券的状态为USED func (a *CouponApiService) ReturnCoupon(ctx context.Context, req ReturnCouponRequest) (resp *ReturnCouponResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/return" // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = req // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract ReturnCouponResponse from Http Response resp = new(ReturnCouponResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // SendCoupon 向用户发券 // // 用于向用户发送商家券 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{} ) localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/send" // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = req // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract SendCouponResponse from Http Response resp = new(SendCouponResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // SendGovCard 发放政府消费卡 // // 发放政府消费卡 func (a *CouponApiService) SendGovCard(ctx context.Context, req SendGovCardRequest) (resp *CouponSendGovCardResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) // Make sure Path Params are properly set if req.CardId == nil { return nil, nil, fmt.Errorf("field `CardId` is required and must be specified in SendGovCardRequest") } localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/{card_id}/send" // Build Path with Path Params localVarPath = strings.Replace(localVarPath, "{"+"card_id"+"}", neturl.PathEscape(core.ParameterToString(*req.CardId, "")), -1) // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = &CouponSendGovCardRequest{ Appid: req.Appid, Openid: req.Openid, OutRequestNo: req.OutRequestNo, SendTime: req.SendTime, } // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract CouponSendGovCardResponse from Http Response resp = new(CouponSendGovCardResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // UseCoupon 核销用户的券 // // 在用户满足优惠门槛后,商户可通过该接口核销用户微信卡包中具体某一张商家券。 // 核销频率:500QPS func (a *CouponApiService) UseCoupon(ctx context.Context, req UseCouponRequest) (resp *UseCouponResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) localVarPath := consts.WechatPayAPIServer + "/v3/marketing/busifavor/coupons/use" // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = req // Determine the Content-Type Header localVarHTTPContentTypes := []string{"application/json"} // Setup Content-Type localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes) // Perform Http Request result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType) if err != nil { return nil, result, err } // Extract UseCouponResponse from Http Response resp = new(UseCouponResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil }