api_native.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // Native支付
  4. //
  5. // Native支付API
  6. //
  7. // API version: 1.2.3
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package native
  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. "git.nanodreamtech.com/sg/wechatpay-go/services/partnerpayments"
  20. )
  21. type NativeApiService services.Service
  22. // CloseOrder 关闭订单
  23. //
  24. // 以下情况需要调用关单接口:
  25. // 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;
  26. // 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。
  27. func (a *NativeApiService) CloseOrder(ctx context.Context, req CloseOrderRequest) (result *core.APIResult, err error) {
  28. var (
  29. localVarHTTPMethod = nethttp.MethodPost
  30. localVarPostBody interface{}
  31. localVarQueryParams neturl.Values
  32. localVarHeaderParams = nethttp.Header{}
  33. )
  34. // Make sure Path Params are properly set
  35. if req.OutTradeNo == nil {
  36. return nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in CloseOrderRequest")
  37. }
  38. localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/out-trade-no/{out_trade_no}/close"
  39. // Build Path with Path Params
  40. localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1)
  41. // Make sure All Required Params are properly set
  42. // Setup Body Params
  43. localVarPostBody = &CloseRequest{
  44. SpMchid: req.SpMchid,
  45. SubMchid: req.SubMchid,
  46. }
  47. // Determine the Content-Type Header
  48. localVarHTTPContentTypes := []string{"application/json"}
  49. // Setup Content-Type
  50. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  51. // Perform Http Request
  52. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  53. if err != nil {
  54. return result, err
  55. }
  56. return result, nil
  57. }
  58. // Prepay Native支付预下单
  59. //
  60. // 商户Native支付统一下单接口,微信后台系统返回链接参数code_url,商户后台系统将code_url值生成二维码图片,用户使用微信客户端扫码后发起支付。
  61. func (a *NativeApiService) Prepay(ctx context.Context, req PrepayRequest) (resp *PrepayResponse, result *core.APIResult, err error) {
  62. var (
  63. localVarHTTPMethod = nethttp.MethodPost
  64. localVarPostBody interface{}
  65. localVarQueryParams neturl.Values
  66. localVarHeaderParams = nethttp.Header{}
  67. )
  68. localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/native"
  69. // Make sure All Required Params are properly set
  70. // Setup Body Params
  71. localVarPostBody = req
  72. // Determine the Content-Type Header
  73. localVarHTTPContentTypes := []string{"application/json"}
  74. // Setup Content-Type
  75. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  76. // Perform Http Request
  77. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  78. if err != nil {
  79. return nil, result, err
  80. }
  81. // Extract PrepayResponse from Http Response
  82. resp = new(PrepayResponse)
  83. err = core.UnMarshalResponse(result.Response, resp)
  84. if err != nil {
  85. return nil, result, err
  86. }
  87. return resp, result, nil
  88. }
  89. // QueryOrderById 微信支付订单号查询订单
  90. //
  91. // 商户可以通过查询订单接口主动查询订单状态
  92. func (a *NativeApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *partnerpayments.Transaction, result *core.APIResult, err error) {
  93. var (
  94. localVarHTTPMethod = nethttp.MethodGet
  95. localVarPostBody interface{}
  96. localVarQueryParams neturl.Values
  97. localVarHeaderParams = nethttp.Header{}
  98. )
  99. // Make sure Path Params are properly set
  100. if req.TransactionId == nil {
  101. return nil, nil, fmt.Errorf("field `TransactionId` is required and must be specified in QueryOrderByIdRequest")
  102. }
  103. localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/id/{transaction_id}"
  104. // Build Path with Path Params
  105. localVarPath = strings.Replace(localVarPath, "{"+"transaction_id"+"}", neturl.PathEscape(core.ParameterToString(*req.TransactionId, "")), -1)
  106. // Make sure All Required Params are properly set
  107. if req.SpMchid == nil {
  108. return nil, nil, fmt.Errorf("field `SpMchid` is required and must be specified in QueryOrderByIdRequest")
  109. }
  110. if req.SubMchid == nil {
  111. return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in QueryOrderByIdRequest")
  112. }
  113. // Setup Query Params
  114. localVarQueryParams = neturl.Values{}
  115. localVarQueryParams.Add("sp_mchid", core.ParameterToString(*req.SpMchid, ""))
  116. localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, ""))
  117. // Determine the Content-Type Header
  118. localVarHTTPContentTypes := []string{}
  119. // Setup Content-Type
  120. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  121. // Perform Http Request
  122. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  123. if err != nil {
  124. return nil, result, err
  125. }
  126. // Extract partnerpayments.Transaction from Http Response
  127. resp = new(partnerpayments.Transaction)
  128. err = core.UnMarshalResponse(result.Response, resp)
  129. if err != nil {
  130. return nil, result, err
  131. }
  132. return resp, result, nil
  133. }
  134. // QueryOrderByOutTradeNo 商户订单号查询订单
  135. //
  136. // 商户可以通过查询订单接口主动查询订单状态
  137. func (a *NativeApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *partnerpayments.Transaction, result *core.APIResult, err error) {
  138. var (
  139. localVarHTTPMethod = nethttp.MethodGet
  140. localVarPostBody interface{}
  141. localVarQueryParams neturl.Values
  142. localVarHeaderParams = nethttp.Header{}
  143. )
  144. // Make sure Path Params are properly set
  145. if req.OutTradeNo == nil {
  146. return nil, nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in QueryOrderByOutTradeNoRequest")
  147. }
  148. localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/out-trade-no/{out_trade_no}"
  149. // Build Path with Path Params
  150. localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1)
  151. // Make sure All Required Params are properly set
  152. if req.SpMchid == nil {
  153. return nil, nil, fmt.Errorf("field `SpMchid` is required and must be specified in QueryOrderByOutTradeNoRequest")
  154. }
  155. if req.SubMchid == nil {
  156. return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in QueryOrderByOutTradeNoRequest")
  157. }
  158. // Setup Query Params
  159. localVarQueryParams = neturl.Values{}
  160. localVarQueryParams.Add("sp_mchid", core.ParameterToString(*req.SpMchid, ""))
  161. localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, ""))
  162. // Determine the Content-Type Header
  163. localVarHTTPContentTypes := []string{}
  164. // Setup Content-Type
  165. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  166. // Perform Http Request
  167. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  168. if err != nil {
  169. return nil, result, err
  170. }
  171. // Extract partnerpayments.Transaction from Http Response
  172. resp = new(partnerpayments.Transaction)
  173. err = core.UnMarshalResponse(result.Response, resp)
  174. if err != nil {
  175. return nil, result, err
  176. }
  177. return resp, result, nil
  178. }