mbdpay

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 9 Imported by: 0

README

mbdpay (面包多支付 mbd.pub) SDK for Go

接口基于 deepmap/oapi-codegen 生成

Build Status Code Coverage

安装

go get github.com/GanymedeNil/mbdpay

已支持的功能

  • 微信支付
  • 支付宝支付
  • 退款
  • 订单查询

更多详细用法,可以参考 mbdpay_test.go

更新日志

请查看 CHANGELOG 了解更新信息。

贡献者

授权

The MIT License (MIT). 请查看 License File 了解更多信息。

Documentation

Overview

Package mbdpay provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.11.0 DO NOT EDIT.

Index

Constants

View Source
const API = "https://api.mianbaoduo.com"

Variables

This section is empty.

Functions

func NewAlipayPayRequest

func NewAlipayPayRequest(server string, body AlipayPayJSONRequestBody) (*http.Request, error)

NewAlipayPayRequest calls the generic AlipayPay builder with application/json body

func NewAlipayPayRequestWithBody

func NewAlipayPayRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewAlipayPayRequestWithBody generates requests for AlipayPay with any type of body

func NewRefundRequest

func NewRefundRequest(server string, body RefundJSONRequestBody) (*http.Request, error)

NewRefundRequest calls the generic Refund builder with application/json body

func NewRefundRequestWithBody

func NewRefundRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewRefundRequestWithBody generates requests for Refund with any type of body

func NewSearchOrderRequest

func NewSearchOrderRequest(server string, body SearchOrderJSONRequestBody) (*http.Request, error)

NewSearchOrderRequest calls the generic SearchOrder builder with application/json body

func NewSearchOrderRequestWithBody

func NewSearchOrderRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewSearchOrderRequestWithBody generates requests for SearchOrder with any type of body

func NewWxPrepayRequest

func NewWxPrepayRequest(server string, body WxPrepayJSONRequestBody) (*http.Request, error)

NewWxPrepayRequest calls the generic WxPrepay builder with application/json body

func NewWxPrepayRequestWithBody

func NewWxPrepayRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewWxPrepayRequestWithBody generates requests for WxPrepay with any type of body

Types

type AlipayPayJSONBody

type AlipayPayJSONBody = AlipayPayReq

AlipayPayJSONBody defines parameters for AlipayPay.

type AlipayPayJSONRequestBody

type AlipayPayJSONRequestBody = AlipayPayJSONBody

AlipayPayJSONRequestBody defines body for AlipayPay for application/json ContentType.

type AlipayPayReq

type AlipayPayReq struct {
	// 金额,单位为分
	AmountTotal int `json:"amount_total"`

	// 你的 app_id,可在控制台查看
	AppId string `json:"app_id"`

	// 支付后跳转地址,如不填会只显示「支付成功」
	CallbackUrl *string `json:"callback_url,omitempty"`

	// 支付描述,一般为商品名称
	Description string `json:"description"`

	// 订单号,如不填,面包多将随机生成订单号
	OutTradeNo *string `json:"out_trade_no,omitempty"`

	// 分账参数,需先开通分账权限
	ShareCode *string `json:"share_code,omitempty"`

	// 请求签名,参照签名算法
	Sign string `json:"sign"`

	// 支付后跳转的URL地址
	Url string `json:"url"`
}

AlipayPayReq defines model for AlipayPayReq.

type AlipayPayRes

type AlipayPayRes struct {
	Body *string `json:"body,omitempty"`
	Code *string `json:"code,omitempty"`

	// 错误说明
	Error   *string `json:"error,omitempty"`
	Message *string `json:"message,omitempty"`
}

AlipayPayRes defines model for AlipayPayRes.

type AlipayPayResponse

type AlipayPayResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *AlipayPayRes
	JSONDefault  *Error
}

func ParseAlipayPayResponse

func ParseAlipayPayResponse(rsp *http.Response) (*AlipayPayResponse, error)

ParseAlipayPayResponse parses an HTTP response from a AlipayPayWithResponse call

func (AlipayPayResponse) Status

func (r AlipayPayResponse) Status() string

Status returns HTTPResponse.Status

func (AlipayPayResponse) StatusCode

func (r AlipayPayResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) AlipayPay

func (c *Client) AlipayPay(ctx context.Context, body AlipayPayJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) AlipayPayWithBody

func (c *Client) AlipayPayWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) Refund

func (c *Client) Refund(ctx context.Context, body RefundJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) RefundWithBody

func (c *Client) RefundWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) SearchOrder

func (c *Client) SearchOrder(ctx context.Context, body SearchOrderJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) SearchOrderWithBody

func (c *Client) SearchOrderWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) WxPrepay

func (c *Client) WxPrepay(ctx context.Context, body WxPrepayJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) WxPrepayWithBody

func (c *Client) WxPrepayWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// AlipayPay request with any body
	AlipayPayWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	AlipayPay(ctx context.Context, body AlipayPayJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// Refund request with any body
	RefundWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	Refund(ctx context.Context, body RefundJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// SearchOrder request with any body
	SearchOrderWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	SearchOrder(ctx context.Context, body SearchOrderJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// WxPrepay request with any body
	WxPrepayWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	WxPrepay(ctx context.Context, body WxPrepayJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func NewMbdPay

func NewMbdPay() (*ClientWithResponses, error)

func (*ClientWithResponses) AlipayPayWithBodyWithResponse

func (c *ClientWithResponses) AlipayPayWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AlipayPayResponse, error)

AlipayPayWithBodyWithResponse request with arbitrary body returning *AlipayPayResponse

func (*ClientWithResponses) AlipayPayWithResponse

func (c *ClientWithResponses) AlipayPayWithResponse(ctx context.Context, body AlipayPayJSONRequestBody, reqEditors ...RequestEditorFn) (*AlipayPayResponse, error)

func (*ClientWithResponses) RefundWithBodyWithResponse

func (c *ClientWithResponses) RefundWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RefundResponse, error)

RefundWithBodyWithResponse request with arbitrary body returning *RefundResponse

func (*ClientWithResponses) RefundWithResponse

func (c *ClientWithResponses) RefundWithResponse(ctx context.Context, body RefundJSONRequestBody, reqEditors ...RequestEditorFn) (*RefundResponse, error)

func (*ClientWithResponses) SearchOrderWithBodyWithResponse

func (c *ClientWithResponses) SearchOrderWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SearchOrderResponse, error)

SearchOrderWithBodyWithResponse request with arbitrary body returning *SearchOrderResponse

func (*ClientWithResponses) SearchOrderWithResponse

func (c *ClientWithResponses) SearchOrderWithResponse(ctx context.Context, body SearchOrderJSONRequestBody, reqEditors ...RequestEditorFn) (*SearchOrderResponse, error)

func (*ClientWithResponses) WxPrepayWithBodyWithResponse

func (c *ClientWithResponses) WxPrepayWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*WxPrepayResponse, error)

WxPrepayWithBodyWithResponse request with arbitrary body returning *WxPrepayResponse

func (*ClientWithResponses) WxPrepayWithResponse

func (c *ClientWithResponses) WxPrepayWithResponse(ctx context.Context, body WxPrepayJSONRequestBody, reqEditors ...RequestEditorFn) (*WxPrepayResponse, error)

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// AlipayPay request with any body
	AlipayPayWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AlipayPayResponse, error)

	AlipayPayWithResponse(ctx context.Context, body AlipayPayJSONRequestBody, reqEditors ...RequestEditorFn) (*AlipayPayResponse, error)

	// Refund request with any body
	RefundWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RefundResponse, error)

	RefundWithResponse(ctx context.Context, body RefundJSONRequestBody, reqEditors ...RequestEditorFn) (*RefundResponse, error)

	// SearchOrder request with any body
	SearchOrderWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SearchOrderResponse, error)

	SearchOrderWithResponse(ctx context.Context, body SearchOrderJSONRequestBody, reqEditors ...RequestEditorFn) (*SearchOrderResponse, error)

	// WxPrepay request with any body
	WxPrepayWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*WxPrepayResponse, error)

	WxPrepayWithResponse(ctx context.Context, body WxPrepayJSONRequestBody, reqEditors ...RequestEditorFn) (*WxPrepayResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type Error

type Error struct {
	Code *string `json:"code,omitempty"`

	// 错误说明
	Error   *string `json:"error,omitempty"`
	Message *string `json:"message,omitempty"`
}

Error defines model for Error.

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type RefundJSONBody

type RefundJSONBody = RefundReq

RefundJSONBody defines parameters for Refund.

type RefundJSONRequestBody

type RefundJSONRequestBody = RefundJSONBody

RefundJSONRequestBody defines body for Refund for application/json ContentType.

type RefundReq

type RefundReq struct {
	// 你的 app_id,可在控制台查看
	AppId string `json:"app_id"`

	// 订单号
	OrderId string `json:"order_id"`

	// 请求签名,参照签名算法
	Sign string `json:"sign"`
}

RefundReq defines model for RefundReq.

type RefundRes

type RefundRes struct {
	Code *string `json:"code,omitempty"`

	// 错误说明
	Error   *string `json:"error,omitempty"`
	Info    *string `json:"info,omitempty"`
	Message *string `json:"message,omitempty"`
}

RefundRes defines model for RefundRes.

type RefundResponse

type RefundResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *RefundRes
	JSONDefault  *Error
}

func ParseRefundResponse

func ParseRefundResponse(rsp *http.Response) (*RefundResponse, error)

ParseRefundResponse parses an HTTP response from a RefundWithResponse call

func (RefundResponse) Status

func (r RefundResponse) Status() string

Status returns HTTPResponse.Status

func (RefundResponse) StatusCode

func (r RefundResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type SearchOrderJSONBody

type SearchOrderJSONBody = SearchOrderReq

SearchOrderJSONBody defines parameters for SearchOrder.

type SearchOrderJSONRequestBody

type SearchOrderJSONRequestBody = SearchOrderJSONBody

SearchOrderJSONRequestBody defines body for SearchOrder for application/json ContentType.

type SearchOrderReq

type SearchOrderReq struct {
	// 你的 app_id,可在控制台查看
	AppId string `json:"app_id"`

	// 订单号(也支持微信/支付宝流水号)
	OutTradeNo string `json:"out_trade_no"`

	// 请求签名,参照签名算法
	Sign string `json:"sign"`
}

SearchOrderReq defines model for SearchOrderReq.

type SearchOrderRes

type SearchOrderRes struct {
	// 支付金额,单位为分
	Amount *int `json:"amount,omitempty"`

	// 支付渠道流水号
	ChargeId *string `json:"charge_id,omitempty"`
	Code     *string `json:"code,omitempty"`

	// 支付时间(时间戳)
	CreateTime *int `json:"create_time,omitempty"`

	// 商品描述
	Description *string `json:"description,omitempty"`

	// 错误说明
	Error   *string `json:"error,omitempty"`
	Message *string `json:"message,omitempty"`

	// 订单号
	OrderId *string `json:"order_id,omitempty"`

	// 支付渠道,1为微信支付,2为支付宝
	Payway *int `json:"payway,omitempty"`

	// 附加参数(json格式)
	Plusinfo *string `json:"plusinfo,omitempty"`

	// 已退款金额,单位为分
	RefundAmount *int `json:"refund_amount,omitempty"`

	// 退款状态,0为无退款,1为部分退款,2为全部退款
	RefundState *int `json:"refund_state,omitempty"`

	// 结算ID
	ShareId *string `json:"share_id,omitempty"`

	// 结算状态
	ShareState *int `json:"share_state,omitempty"`

	// 支付状态,0-未支付,1-已支付,2-已结算,3-投诉中,4-投诉完结,5-投诉超时,6-投诉中(买家处理中)
	State *int `json:"state,omitempty"`
}

SearchOrderRes defines model for SearchOrderRes.

type SearchOrderResponse

type SearchOrderResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *SearchOrderRes
	JSONDefault  *Error
}

func ParseSearchOrderResponse

func ParseSearchOrderResponse(rsp *http.Response) (*SearchOrderResponse, error)

ParseSearchOrderResponse parses an HTTP response from a SearchOrderWithResponse call

func (SearchOrderResponse) Status

func (r SearchOrderResponse) Status() string

Status returns HTTPResponse.Status

func (SearchOrderResponse) StatusCode

func (r SearchOrderResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type WxPrepayJSONBody

type WxPrepayJSONBody = WxPrepayReq

WxPrepayJSONBody defines parameters for WxPrepay.

type WxPrepayJSONRequestBody

type WxPrepayJSONRequestBody = WxPrepayJSONBody

WxPrepayJSONRequestBody defines body for WxPrepay for application/json ContentType.

type WxPrepayReq

type WxPrepayReq struct {
	// 金额,单位为分
	AmountTotal int `json:"amount_total"`

	// 你的 app_id,可在控制台查看
	AppId string `json:"app_id"`

	// 支付后跳转地址(JSAPI支付该字段为必填)
	CallbackUrl *string `json:"callback_url,omitempty"`

	// 固定为 h5(h5支付该字段为必填)
	Channel *string `json:"channel,omitempty"`

	// 支付描述,一般为商品名称
	Description string `json:"description"`

	// 用户的openid (JSAPI支付该字段为必填)
	Openid *string `json:"openid,omitempty"`

	// 订单号,如不填,面包多将随机生成订单号
	OutTradeNo *string `json:"out_trade_no,omitempty"`

	// 分账参数,需先开通分账权限
	ShareCode *string `json:"share_code,omitempty"`

	// 请求签名
	Sign string `json:"sign"`
}

WxPrepayReq defines model for WxPrepayReq.

type WxPrepayRes

type WxPrepayRes struct {
	AppId *string `json:"appId,omitempty"`
	Code  *string `json:"code,omitempty"`

	// 错误说明
	Error     *string `json:"error,omitempty"`
	H5Url     *string `json:"h5_url,omitempty"`
	Message   *string `json:"message,omitempty"`
	NonceStr  *string `json:"nonceStr,omitempty"`
	Package   *string `json:"package,omitempty"`
	PaySign   *string `json:"paySign,omitempty"`
	SignType  *string `json:"signType,omitempty"`
	TimeStamp *string `json:"timeStamp,omitempty"`
}

WxPrepayRes defines model for WxPrepayRes.

type WxPrepayResponse

type WxPrepayResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *WxPrepayRes
	JSONDefault  *Error
}

func ParseWxPrepayResponse

func ParseWxPrepayResponse(rsp *http.Response) (*WxPrepayResponse, error)

ParseWxPrepayResponse parses an HTTP response from a WxPrepayWithResponse call

func (WxPrepayResponse) Status

func (r WxPrepayResponse) Status() string

Status returns HTTPResponse.Status

func (WxPrepayResponse) StatusCode

func (r WxPrepayResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL