// Copyright 2021 Tencent Inc. All rights reserved. // // Native支付 // // Native支付API // // API version: 1.2.3 // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT. package native 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" "git.nanodreamtech.com/sg/wechatpay-go/services/partnerpayments" ) type NativeApiService services.Service // CloseOrder 关闭订单 // // 以下情况需要调用关单接口: // 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; // 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 func (a *NativeApiService) CloseOrder(ctx context.Context, req CloseOrderRequest) (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.OutTradeNo == nil { return nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in CloseOrderRequest") } localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/out-trade-no/{out_trade_no}/close" // Build Path with Path Params localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1) // Make sure All Required Params are properly set // Setup Body Params localVarPostBody = &CloseRequest{ SpMchid: req.SpMchid, SubMchid: req.SubMchid, } // 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 result, err } return result, nil } // Prepay Native支付预下单 // // 商户Native支付统一下单接口,微信后台系统返回链接参数code_url,商户后台系统将code_url值生成二维码图片,用户使用微信客户端扫码后发起支付。 func (a *NativeApiService) Prepay(ctx context.Context, req PrepayRequest) (resp *PrepayResponse, result *core.APIResult, err error) { var ( localVarHTTPMethod = nethttp.MethodPost localVarPostBody interface{} localVarQueryParams neturl.Values localVarHeaderParams = nethttp.Header{} ) localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/native" // 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 PrepayResponse from Http Response resp = new(PrepayResponse) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // QueryOrderById 微信支付订单号查询订单 // // 商户可以通过查询订单接口主动查询订单状态 func (a *NativeApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *partnerpayments.Transaction, 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.TransactionId == nil { return nil, nil, fmt.Errorf("field `TransactionId` is required and must be specified in QueryOrderByIdRequest") } localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/id/{transaction_id}" // Build Path with Path Params localVarPath = strings.Replace(localVarPath, "{"+"transaction_id"+"}", neturl.PathEscape(core.ParameterToString(*req.TransactionId, "")), -1) // Make sure All Required Params are properly set if req.SpMchid == nil { return nil, nil, fmt.Errorf("field `SpMchid` is required and must be specified in QueryOrderByIdRequest") } if req.SubMchid == nil { return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in QueryOrderByIdRequest") } // Setup Query Params localVarQueryParams = neturl.Values{} localVarQueryParams.Add("sp_mchid", core.ParameterToString(*req.SpMchid, "")) localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, "")) // 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 partnerpayments.Transaction from Http Response resp = new(partnerpayments.Transaction) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil } // QueryOrderByOutTradeNo 商户订单号查询订单 // // 商户可以通过查询订单接口主动查询订单状态 func (a *NativeApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *partnerpayments.Transaction, 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.OutTradeNo == nil { return nil, nil, fmt.Errorf("field `OutTradeNo` is required and must be specified in QueryOrderByOutTradeNoRequest") } localVarPath := consts.WechatPayAPIServer + "/v3/pay/partner/transactions/out-trade-no/{out_trade_no}" // Build Path with Path Params localVarPath = strings.Replace(localVarPath, "{"+"out_trade_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutTradeNo, "")), -1) // Make sure All Required Params are properly set if req.SpMchid == nil { return nil, nil, fmt.Errorf("field `SpMchid` is required and must be specified in QueryOrderByOutTradeNoRequest") } if req.SubMchid == nil { return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in QueryOrderByOutTradeNoRequest") } // Setup Query Params localVarQueryParams = neturl.Values{} localVarQueryParams.Add("sp_mchid", core.ParameterToString(*req.SpMchid, "")) localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, "")) // 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 partnerpayments.Transaction from Http Response resp = new(partnerpayments.Transaction) err = core.UnMarshalResponse(result.Response, resp) if err != nil { return nil, result, err } return resp, result, nil }