api_h5.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // H5支付
  4. //
  5. // H5支付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 h5
  10. import (
  11. "context"
  12. "encoding/json"
  13. "fmt"
  14. nethttp "net/http"
  15. neturl "net/url"
  16. "strings"
  17. "git.nanodreamtech.com/sg/wechatpay-go/core"
  18. "git.nanodreamtech.com/sg/wechatpay-go/core/consts"
  19. "git.nanodreamtech.com/sg/wechatpay-go/services"
  20. "git.nanodreamtech.com/sg/wechatpay-go/services/payments"
  21. )
  22. type H5ApiService services.Service
  23. // CloseOrder 关闭订单
  24. //
  25. // 以下情况需要调用关单接口:
  26. // 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;
  27. // 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。
  28. func (a *H5ApiService) CloseOrder(ctx context.Context, req CloseOrderRequest) (result *core.APIResult, err error) {
  29. var (
  30. localVarHTTPMethod = nethttp.MethodPost
  31. localVarPostBody interface{}
  32. localVarQueryParams neturl.Values
  33. localVarHeaderParams = nethttp.Header{}
  34. )
  35. // Make sure Path Params are properly set
  36. if req.OutTradeNo == nil {
  37. return nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in CloseOrderRequest")
  38. }
  39. localVarPath := consts.WechatPayAPIServer + "/v3/pay/transactions/out-trade-no/{out_trade_no}/close"
  40. // Build Path with Path Params
  41. localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1)
  42. // Make sure All Required Params are properly set
  43. // Setup Body Params
  44. localVarPostBody = &CloseRequest{
  45. Mchid: req.Mchid,
  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 H5支付下单
  59. //
  60. // 商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再按Native、JSAPI、APP等不同场景生成交易串调起支付。
  61. func (a *H5ApiService) 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/global/transactions/mweb"
  69. // Make sure All Required Params are properly set
  70. // Setup Body Params
  71. localVarPostBody = req
  72. jsonData,_:=json.Marshal(req)
  73. fmt.Println(string(jsonData))
  74. // Determine the Content-Type Header
  75. localVarHTTPContentTypes := []string{"application/json"}
  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 PrepayResponse from Http Response
  84. resp = new(PrepayResponse)
  85. err = core.UnMarshalResponse(result.Response, resp)
  86. if err != nil {
  87. return nil, result, err
  88. }
  89. return resp, result, nil
  90. }
  91. // QueryOrderById 微信支付订单号查询订单
  92. //
  93. // 商户可以通过查询订单接口主动查询订单状态
  94. func (a *H5ApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *payments.Transaction, result *core.APIResult, err error) {
  95. var (
  96. localVarHTTPMethod = nethttp.MethodGet
  97. localVarPostBody interface{}
  98. localVarQueryParams neturl.Values
  99. localVarHeaderParams = nethttp.Header{}
  100. )
  101. // Make sure Path Params are properly set
  102. if req.TransactionId == nil {
  103. return nil, nil, fmt.Errorf("field `TransactionId` is required and must be specified in QueryOrderByIdRequest")
  104. }
  105. localVarPath := consts.WechatPayAPIServer + "/v3/pay/transactions/id/{transaction_id}"
  106. // Build Path with Path Params
  107. localVarPath = strings.Replace(localVarPath, "{"+"transaction_id"+"}", neturl.PathEscape(core.ParameterToString(*req.TransactionId, "")), -1)
  108. // Make sure All Required Params are properly set
  109. if req.Mchid == nil {
  110. return nil, nil, fmt.Errorf("field `Mchid` is required and must be specified in QueryOrderByIdRequest")
  111. }
  112. // Setup Query Params
  113. localVarQueryParams = neturl.Values{}
  114. localVarQueryParams.Add("mchid", core.ParameterToString(*req.Mchid, ""))
  115. // Determine the Content-Type Header
  116. localVarHTTPContentTypes := []string{}
  117. // Setup Content-Type
  118. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  119. // Perform Http Request
  120. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  121. if err != nil {
  122. return nil, result, err
  123. }
  124. // Extract payments.Transaction from Http Response
  125. resp = new(payments.Transaction)
  126. err = core.UnMarshalResponse(result.Response, resp)
  127. if err != nil {
  128. return nil, result, err
  129. }
  130. return resp, result, nil
  131. }
  132. // QueryOrderByOutTradeNo 商户订单号查询订单
  133. //
  134. // 商户可以通过查询订单接口主动查询订单状态
  135. func (a *H5ApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *payments.Transaction, result *core.APIResult, err error) {
  136. var (
  137. localVarHTTPMethod = nethttp.MethodGet
  138. localVarPostBody interface{}
  139. localVarQueryParams neturl.Values
  140. localVarHeaderParams = nethttp.Header{}
  141. )
  142. // Make sure Path Params are properly set
  143. if req.OutTradeNo == nil {
  144. return nil, nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in QueryOrderByOutTradeNoRequest")
  145. }
  146. localVarPath := consts.WechatPayAPIServer + "/v3/pay/transactions/out-trade-no/{out_trade_no}"
  147. // Build Path with Path Params
  148. localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1)
  149. // Make sure All Required Params are properly set
  150. if req.Mchid == nil {
  151. return nil, nil, fmt.Errorf("field `Mchid` is required and must be specified in QueryOrderByOutTradeNoRequest")
  152. }
  153. // Setup Query Params
  154. localVarQueryParams = neturl.Values{}
  155. localVarQueryParams.Add("mchid", core.ParameterToString(*req.Mchid, ""))
  156. // Determine the Content-Type Header
  157. localVarHTTPContentTypes := []string{}
  158. // Setup Content-Type
  159. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  160. // Perform Http Request
  161. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  162. if err != nil {
  163. return nil, result, err
  164. }
  165. // Extract payments.Transaction from Http Response
  166. resp = new(payments.Transaction)
  167. err = core.UnMarshalResponse(result.Response, resp)
  168. if err != nil {
  169. return nil, result, err
  170. }
  171. return resp, result, nil
  172. }