api_jsapi.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // JSAPI支付
  4. //
  5. // JSAPI支付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 jsapi
  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/payments"
  20. )
  21. type JsapiApiService services.Service
  22. // CloseOrder 关闭订单
  23. //
  24. // 以下情况需要调用关单接口:
  25. // 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;
  26. // 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。
  27. func (a *JsapiApiService) 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/global/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. Mchid: req.Mchid,
  45. }
  46. // Determine the Content-Type Header
  47. localVarHTTPContentTypes := []string{"application/json"}
  48. // Setup Content-Type
  49. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  50. // Perform Http Request
  51. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  52. if err != nil {
  53. return result, err
  54. }
  55. return result, nil
  56. }
  57. // Prepay JSAPI支付下单
  58. //
  59. // 商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再按Native、JSAPI、APP等不同场景生成交易串调起支付。
  60. func (a *JsapiApiService) Prepay(ctx context.Context, req PrepayRequest) (resp *PrepayResponse, result *core.APIResult, err error) {
  61. var (
  62. localVarHTTPMethod = nethttp.MethodPost
  63. localVarPostBody interface{}
  64. localVarQueryParams neturl.Values
  65. localVarHeaderParams = nethttp.Header{}
  66. )
  67. localVarPath := consts.WechatPayAPIServer + "/v3/global/transactions/jsapi"
  68. // Make sure All Required Params are properly set
  69. // Setup Body Params
  70. localVarPostBody = req
  71. // Determine the Content-Type Header
  72. localVarHTTPContentTypes := []string{"application/json"}
  73. // Setup Content-Type
  74. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  75. // Perform Http Request
  76. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  77. if err != nil {
  78. return nil, result, err
  79. }
  80. // Extract PrepayResponse from Http Response
  81. resp = new(PrepayResponse)
  82. err = core.UnMarshalResponse(result.Response, resp)
  83. if err != nil {
  84. return nil, result, err
  85. }
  86. return resp, result, nil
  87. }
  88. // QueryOrderById 微信支付订单号查询订单
  89. //
  90. // 商户可以通过查询订单接口主动查询订单状态
  91. func (a *JsapiApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *payments.Transaction, result *core.APIResult, err error) {
  92. var (
  93. localVarHTTPMethod = nethttp.MethodGet
  94. localVarPostBody interface{}
  95. localVarQueryParams neturl.Values
  96. localVarHeaderParams = nethttp.Header{}
  97. )
  98. // Make sure Path Params are properly set
  99. if req.TransactionId == nil {
  100. return nil, nil, fmt.Errorf("field `TransactionId` is required and must be specified in QueryOrderByIdRequest")
  101. }
  102. localVarPath := consts.WechatPayAPIServer + "/v3/global/transactions/id/{transaction_id}"
  103. // Build Path with Path Params
  104. localVarPath = strings.Replace(localVarPath, "{"+"transaction_id"+"}", neturl.PathEscape(core.ParameterToString(*req.TransactionId, "")), -1)
  105. // Make sure All Required Params are properly set
  106. if req.Mchid == nil {
  107. return nil, nil, fmt.Errorf("field `Mchid` is required and must be specified in QueryOrderByIdRequest")
  108. }
  109. // Setup Query Params
  110. localVarQueryParams = neturl.Values{}
  111. localVarQueryParams.Add("mchid", core.ParameterToString(*req.Mchid, ""))
  112. // Determine the Content-Type Header
  113. localVarHTTPContentTypes := []string{}
  114. // Setup Content-Type
  115. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  116. // Perform Http Request
  117. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  118. if err != nil {
  119. return nil, result, err
  120. }
  121. // Extract payments.Transaction from Http Response
  122. resp = new(payments.Transaction)
  123. err = core.UnMarshalResponse(result.Response, resp)
  124. if err != nil {
  125. return nil, result, err
  126. }
  127. return resp, result, nil
  128. }
  129. // QueryOrderByOutTradeNo 商户订单号查询订单
  130. //
  131. // 商户可以通过查询订单接口主动查询订单状态
  132. func (a *JsapiApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *payments.Transaction, result *core.APIResult, err error) {
  133. var (
  134. localVarHTTPMethod = nethttp.MethodGet
  135. localVarPostBody interface{}
  136. localVarQueryParams neturl.Values
  137. localVarHeaderParams = nethttp.Header{}
  138. )
  139. // Make sure Path Params are properly set
  140. if req.OutTradeNo == nil {
  141. return nil, nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in QueryOrderByOutTradeNoRequest")
  142. }
  143. localVarPath := consts.WechatPayAPIServer + "/v3/global/transactions/out-trade-no/{out_trade_no}"
  144. // Build Path with Path Params
  145. localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1)
  146. // Make sure All Required Params are properly set
  147. if req.Mchid == nil {
  148. return nil, nil, fmt.Errorf("field `Mchid` is required and must be specified in QueryOrderByOutTradeNoRequest")
  149. }
  150. // Setup Query Params
  151. localVarQueryParams = neturl.Values{}
  152. localVarQueryParams.Add("mchid", core.ParameterToString(*req.Mchid, ""))
  153. // Determine the Content-Type Header
  154. localVarHTTPContentTypes := []string{}
  155. // Setup Content-Type
  156. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  157. // Perform Http Request
  158. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  159. if err != nil {
  160. return nil, result, err
  161. }
  162. // Extract payments.Transaction from Http Response
  163. resp = new(payments.Transaction)
  164. err = core.UnMarshalResponse(result.Response, resp)
  165. if err != nil {
  166. return nil, result, err
  167. }
  168. return resp, result, nil
  169. }