api_coupon.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // 微信支付营销系统开放API
  4. //
  5. // 新增立减金api
  6. //
  7. // API version: 3.4.0
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package cashcoupons
  10. import (
  11. "context"
  12. "fmt"
  13. nethttp "net/http"
  14. neturl "net/url"
  15. "strings"
  16. "git.nanodreamtech.com/sg/wechatpay-go/core"
  17. "git.nanodreamtech.com/sg/wechatpay-go/core/consts"
  18. "git.nanodreamtech.com/sg/wechatpay-go/services"
  19. )
  20. type CouponApiService services.Service
  21. // ListCouponsByFilter 根据过滤条件查询用户的券
  22. //
  23. // 根据过滤条件查询用户的券(商户号角色、批次、状态)
  24. //
  25. // 接口频率:500qps
  26. //
  27. // 前置条件:已发代金券
  28. //
  29. // 注意事项:
  30. //
  31. // 1. 创建方只能查自制批次的券,发券商户只能查询自发批次的券
  32. func (a *CouponApiService) ListCouponsByFilter(ctx context.Context, req ListCouponsByFilterRequest) (resp *CouponCollection, result *core.APIResult, err error) {
  33. var (
  34. localVarHTTPMethod = nethttp.MethodGet
  35. localVarPostBody interface{}
  36. localVarQueryParams neturl.Values
  37. localVarHeaderParams = nethttp.Header{}
  38. )
  39. // Make sure Path Params are properly set
  40. if req.Openid == nil {
  41. return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in ListCouponsByFilterRequest")
  42. }
  43. localVarPath := consts.WechatPayAPIServer + "/v3/marketing/favor/users/{openid}/coupons"
  44. // Build Path with Path Params
  45. localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1)
  46. // Make sure All Required Params are properly set
  47. if req.Appid == nil {
  48. return nil, nil, fmt.Errorf("field `Appid` is required and must be specified in ListCouponsByFilterRequest")
  49. }
  50. // Setup Query Params
  51. localVarQueryParams = neturl.Values{}
  52. localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, ""))
  53. if req.StockId != nil {
  54. localVarQueryParams.Add("stock_id", core.ParameterToString(*req.StockId, ""))
  55. }
  56. if req.Status != nil {
  57. localVarQueryParams.Add("status", core.ParameterToString(*req.Status, ""))
  58. }
  59. if req.CreatorMchid != nil {
  60. localVarQueryParams.Add("creator_mchid", core.ParameterToString(*req.CreatorMchid, ""))
  61. }
  62. if req.SenderMchid != nil {
  63. localVarQueryParams.Add("sender_mchid", core.ParameterToString(*req.SenderMchid, ""))
  64. }
  65. if req.AvailableMchid != nil {
  66. localVarQueryParams.Add("available_mchid", core.ParameterToString(*req.AvailableMchid, ""))
  67. }
  68. if req.Offset != nil {
  69. localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, ""))
  70. }
  71. if req.Limit != nil {
  72. localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, ""))
  73. }
  74. // Determine the Content-Type Header
  75. localVarHTTPContentTypes := []string{}
  76. // Setup Content-Type
  77. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  78. // Perform Http Request
  79. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  80. if err != nil {
  81. return nil, result, err
  82. }
  83. // Extract CouponCollection from Http Response
  84. resp = new(CouponCollection)
  85. err = core.UnMarshalResponse(result.Response, resp)
  86. if err != nil {
  87. return nil, result, err
  88. }
  89. return resp, result, nil
  90. }
  91. // QueryCoupon 查询代金券详情
  92. //
  93. // 查询用户的券详情
  94. //
  95. // 接口频率:500qps
  96. //
  97. // 前置条件:用户的券已发放
  98. //
  99. // 注意:
  100. //
  101. // 1. 该接口支持批次创建商户号与批次发放商户调用
  102. func (a *CouponApiService) QueryCoupon(ctx context.Context, req QueryCouponRequest) (resp *Coupon, result *core.APIResult, err error) {
  103. var (
  104. localVarHTTPMethod = nethttp.MethodGet
  105. localVarPostBody interface{}
  106. localVarQueryParams neturl.Values
  107. localVarHeaderParams = nethttp.Header{}
  108. )
  109. // Make sure Path Params are properly set
  110. if req.CouponId == nil {
  111. return nil, nil, fmt.Errorf("field `CouponId` is required and must be specified in QueryCouponRequest")
  112. }
  113. if req.Openid == nil {
  114. return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in QueryCouponRequest")
  115. }
  116. localVarPath := consts.WechatPayAPIServer + "/v3/marketing/favor/users/{openid}/coupons/{coupon_id}"
  117. // Build Path with Path Params
  118. localVarPath = strings.Replace(localVarPath, "{"+"coupon_id"+"}", neturl.PathEscape(core.ParameterToString(*req.CouponId, "")), -1)
  119. localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1)
  120. // Make sure All Required Params are properly set
  121. if req.Appid == nil {
  122. return nil, nil, fmt.Errorf("field `Appid` is required and must be specified in QueryCouponRequest")
  123. }
  124. // Setup Query Params
  125. localVarQueryParams = neturl.Values{}
  126. localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, ""))
  127. // Determine the Content-Type Header
  128. localVarHTTPContentTypes := []string{}
  129. // Setup Content-Type
  130. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  131. // Perform Http Request
  132. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  133. if err != nil {
  134. return nil, result, err
  135. }
  136. // Extract Coupon from Http Response
  137. resp = new(Coupon)
  138. err = core.UnMarshalResponse(result.Response, resp)
  139. if err != nil {
  140. return nil, result, err
  141. }
  142. return resp, result, nil
  143. }
  144. // SendCoupon 发放指定批次的代金券
  145. //
  146. // 发放指定批次的代金券
  147. //
  148. // 接口频率:500qps
  149. //
  150. // 前置条件:已创建并激活代金券批次
  151. //
  152. // 是否支持幂等:是
  153. //
  154. // 注意:
  155. //
  156. // 1. 商户可在H5活动页面、商户小程序、商户APP等自有场景内调用该接口完成发券,商户默认只允许发放本商户号(调用发券接口的商户号)创建的代金券,如需发放其他商户商户创建的代金券,请参考常见问题Q1。
  157. // 2. 跨商户发券时,请求参数中除了stock\_id和stock\_creator\_mchid为创建方提供的数据,其他的所有调用数据都由发放方提供。
  158. func (a *CouponApiService) SendCoupon(ctx context.Context, req SendCouponRequest) (resp *SendCouponResponse, result *core.APIResult, err error) {
  159. var (
  160. localVarHTTPMethod = nethttp.MethodPost
  161. localVarPostBody interface{}
  162. localVarQueryParams neturl.Values
  163. localVarHeaderParams = nethttp.Header{}
  164. )
  165. // Make sure Path Params are properly set
  166. if req.Openid == nil {
  167. return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in SendCouponRequest")
  168. }
  169. localVarPath := consts.WechatPayAPIServer + "/v3/marketing/favor/users/{openid}/coupons"
  170. // Build Path with Path Params
  171. localVarPath = strings.Replace(localVarPath, "{"+"openid"+"}", neturl.PathEscape(core.ParameterToString(*req.Openid, "")), -1)
  172. // Make sure All Required Params are properly set
  173. // Setup Body Params
  174. localVarPostBody = &SendCouponBody{
  175. StockId: req.StockId,
  176. OutRequestNo: req.OutRequestNo,
  177. Appid: req.Appid,
  178. StockCreatorMchid: req.StockCreatorMchid,
  179. CouponValue: req.CouponValue,
  180. CouponMinimum: req.CouponMinimum,
  181. }
  182. // Determine the Content-Type Header
  183. localVarHTTPContentTypes := []string{"application/json"}
  184. // Setup Content-Type
  185. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  186. // Perform Http Request
  187. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  188. if err != nil {
  189. return nil, result, err
  190. }
  191. // Extract SendCouponResponse from Http Response
  192. resp = new(SendCouponResponse)
  193. err = core.UnMarshalResponse(result.Response, resp)
  194. if err != nil {
  195. return nil, result, err
  196. }
  197. return resp, result, nil
  198. }