native

package
v0.2.1-dev Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: Apache-2.0 Imports: 11 Imported by: 25

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount struct {
	// 订单总金额,单位为分
	Total *int32 `json:"total"`
	// CNY:人民币,境内商户号仅支持人民币。
	Currency *string `json:"currency,omitempty"`
}

Amount

func (Amount) MarshalJSON

func (o Amount) MarshalJSON() ([]byte, error)

func (Amount) String

func (o Amount) String() string

type CloseOrderRequest

type CloseOrderRequest struct {
	OutTradeNo *string `json:"out_trade_no"`
	// 直连商户号
	Mchid *string `json:"mchid"`
}

CloseOrderRequest

func (CloseOrderRequest) MarshalJSON

func (o CloseOrderRequest) MarshalJSON() ([]byte, error)

func (CloseOrderRequest) String

func (o CloseOrderRequest) String() string

type CloseRequest

type CloseRequest struct {
	// 直连商户号
	Mchid *string `json:"mchid"`
}

CloseRequest

func (CloseRequest) MarshalJSON

func (o CloseRequest) MarshalJSON() ([]byte, error)

func (CloseRequest) String

func (o CloseRequest) String() string

type Detail

type Detail struct {
	// 1.商户侧一张小票订单可能被分多次支付,订单原价用于记录整张小票的交易金额。 2.当订单原价与支付金额不相等,则不享受优惠。 3.该字段主要用于防止同一张小票分多次支付,以享受多次优惠的情况,正常支付订单不必上传此参数。
	CostPrice *int32 `json:"cost_price,omitempty"`
	// 商家小票ID。
	InvoiceId   *string       `json:"invoice_id,omitempty"`
	GoodsDetail []GoodsDetail `json:"goods_detail,omitempty"`
}

Detail 优惠功能

func (Detail) MarshalJSON

func (o Detail) MarshalJSON() ([]byte, error)

func (Detail) String

func (o Detail) String() string

type GoodsDetail

type GoodsDetail struct {
	// 由半角的大小写字母、数字、中划线、下划线中的一种或几种组成。
	MerchantGoodsId *string `json:"merchant_goods_id"`
	// 微信支付定义的统一商品编号(没有可不传)。
	WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"`
	// 商品的实际名称。
	GoodsName *string `json:"goods_name,omitempty"`
	// 用户购买的数量。
	Quantity *int32 `json:"quantity"`
	// 商品单价,单位为分。
	UnitPrice *int32 `json:"unit_price"`
}

GoodsDetail

func (GoodsDetail) MarshalJSON

func (o GoodsDetail) MarshalJSON() ([]byte, error)

func (GoodsDetail) String

func (o GoodsDetail) String() string

type NativeApiService

type NativeApiService services.Service

func (*NativeApiService) CloseOrder

func (a *NativeApiService) CloseOrder(ctx context.Context, req CloseOrderRequest) (result *core.APIResult, err error)

CloseOrder 关闭订单

以下情况需要调用关单接口: 1. 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; 2. 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。

Example
package main

import (
	"context"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	svc := native.NativeApiService{Client: client}
	result, err := svc.CloseOrder(ctx,
		native.CloseOrderRequest{
			OutTradeNo: core.String("outTradeNo_example"),
			Mchid:      core.String("1230000109"),
		},
	)

	// TODO: 处理返回结果
	_, _ = result, err
}
Output:

func (*NativeApiService) Prepay

func (a *NativeApiService) Prepay(ctx context.Context, req PrepayRequest) (resp *PrepayResponse, result *core.APIResult, err error)

Prepay Native支付预下单

商户Native支付统一下单接口,微信后台系统返回链接参数code_url,商户后台系统将code_url值生成二维码图片,用户使用微信客户端扫码后发起支付。

Example
package main

import (
	"context"
	"time"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	svc := native.NativeApiService{Client: client}
	resp, result, err := svc.Prepay(ctx,
		native.PrepayRequest{
			Appid:         core.String("wxd678efh567hg6787"),
			Mchid:         core.String("1230000109"),
			Description:   core.String("Image形象店-深圳腾大-QQ公仔"),
			OutTradeNo:    core.String("1217752501201407033233368018"),
			TimeExpire:    core.Time(time.Now()),
			Attach:        core.String("自定义数据说明"),
			NotifyUrl:     core.String("https://www.weixin.qq.com/wxpay/pay.php"),
			GoodsTag:      core.String("WXG"),
			LimitPay:      []string{"LimitPay_example"},
			SupportFapiao: core.Bool(false),
			Amount: &native.Amount{
				Currency: core.String("CNY"),
				Total:    core.Int32(100),
			},
			Detail: &native.Detail{
				CostPrice: core.Int32(608800),
				GoodsDetail: []native.GoodsDetail{native.GoodsDetail{
					GoodsName:        core.String("iPhoneX 256G"),
					MerchantGoodsId:  core.String("ABC"),
					Quantity:         core.Int32(1),
					UnitPrice:        core.Int32(828800),
					WechatpayGoodsId: core.String("1001"),
				}},
				InvoiceId: core.String("wx123"),
			},
			SettleInfo: &native.SettleInfo{
				ProfitSharing: core.Bool(false),
			},
			SceneInfo: &native.SceneInfo{
				DeviceId:      core.String("013467007045764"),
				PayerClientIp: core.String("14.23.150.211"),
				StoreInfo: &native.StoreInfo{
					Address:  core.String("广东省深圳市南山区科技中一道10000号"),
					AreaCode: core.String("440305"),
					Id:       core.String("0001"),
					Name:     core.String("腾讯大厦分店"),
				},
			},
		},
	)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

func (*NativeApiService) QueryOrderById

func (a *NativeApiService) QueryOrderById(ctx context.Context, req QueryOrderByIdRequest) (resp *payments.Transaction, result *core.APIResult, err error)

QueryOrderById 微信支付订单号查询订单

商户可以通过查询订单接口主动查询订单状态

Example
package main

import (
	"context"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	svc := native.NativeApiService{Client: client}
	resp, result, err := svc.QueryOrderById(ctx,
		native.QueryOrderByIdRequest{
			TransactionId: core.String("transactionId_example"),
			Mchid:         core.String("mchid_example"),
		},
	)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

func (*NativeApiService) QueryOrderByOutTradeNo

func (a *NativeApiService) QueryOrderByOutTradeNo(ctx context.Context, req QueryOrderByOutTradeNoRequest) (resp *payments.Transaction, result *core.APIResult, err error)

QueryOrderByOutTradeNo 商户订单号查询订单

商户可以通过查询订单接口主动查询订单状态

Example
package main

import (
	"context"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	svc := native.NativeApiService{Client: client}
	resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
		native.QueryOrderByOutTradeNoRequest{
			OutTradeNo: core.String("outTradeNo_example"),
			Mchid:      core.String("mchid_example"),
		},
	)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

type PrepayRequest

type PrepayRequest struct {
	// 公众号ID
	Appid *string `json:"appid"`
	// 直连商户号
	Mchid *string `json:"mchid"`
	// 商品描述
	Description *string `json:"description"`
	// 商户订单号
	OutTradeNo *string `json:"out_trade_no"`
	// 订单生成时间,格式为rfc3339格式
	TimeExpire *time.Time `json:"time_expire,omitempty"`
	// 附加数据
	Attach *string `json:"attach,omitempty"`
	// 有效性:1. HTTPS;2. 不允许携带查询串。
	NotifyUrl *string `json:"notify_url"`
	// 商品标记,代金券或立减优惠功能的参数。
	GoodsTag *string `json:"goods_tag,omitempty"`
	// 指定支付方式
	LimitPay []string `json:"limit_pay,omitempty"`
	// 传入true时,支付成功消息和支付详情页将出现开票入口。需要在微信支付商户平台或微信公众平台开通电子发票功能,传此字段才可生效。
	SupportFapiao *bool       `json:"support_fapiao,omitempty"`
	Amount        *Amount     `json:"amount"`
	Detail        *Detail     `json:"detail,omitempty"`
	SettleInfo    *SettleInfo `json:"settle_info,omitempty"`
	SceneInfo     *SceneInfo  `json:"scene_info,omitempty"`
}

PrepayRequest

func (PrepayRequest) MarshalJSON

func (o PrepayRequest) MarshalJSON() ([]byte, error)

func (PrepayRequest) String

func (o PrepayRequest) String() string

type PrepayResponse

type PrepayResponse struct {
	// 二维码链接
	CodeUrl *string `json:"code_url"`
}

PrepayResponse

func (PrepayResponse) MarshalJSON

func (o PrepayResponse) MarshalJSON() ([]byte, error)

func (PrepayResponse) String

func (o PrepayResponse) String() string

type QueryOrderByIdRequest

type QueryOrderByIdRequest struct {
	TransactionId *string `json:"transaction_id"`
	// 直连商户号
	Mchid *string `json:"mchid"`
}

QueryOrderByIdRequest

func (QueryOrderByIdRequest) MarshalJSON

func (o QueryOrderByIdRequest) MarshalJSON() ([]byte, error)

func (QueryOrderByIdRequest) String

func (o QueryOrderByIdRequest) String() string

type QueryOrderByOutTradeNoRequest

type QueryOrderByOutTradeNoRequest struct {
	OutTradeNo *string `json:"out_trade_no"`
	// 直连商户号
	Mchid *string `json:"mchid"`
}

QueryOrderByOutTradeNoRequest

func (QueryOrderByOutTradeNoRequest) MarshalJSON

func (o QueryOrderByOutTradeNoRequest) MarshalJSON() ([]byte, error)

func (QueryOrderByOutTradeNoRequest) String

type SceneInfo

type SceneInfo struct {
	// 用户终端IP
	PayerClientIp *string `json:"payer_client_ip"`
	// 商户端设备号
	DeviceId  *string    `json:"device_id,omitempty"`
	StoreInfo *StoreInfo `json:"store_info,omitempty"`
}

SceneInfo 支付场景描述

func (SceneInfo) MarshalJSON

func (o SceneInfo) MarshalJSON() ([]byte, error)

func (SceneInfo) String

func (o SceneInfo) String() string

type SettleInfo

type SettleInfo struct {
	// 是否指定分账
	ProfitSharing *bool `json:"profit_sharing,omitempty"`
}

SettleInfo

func (SettleInfo) MarshalJSON

func (o SettleInfo) MarshalJSON() ([]byte, error)

func (SettleInfo) String

func (o SettleInfo) String() string

type StoreInfo

type StoreInfo struct {
	// 商户侧门店编号
	Id *string `json:"id"`
	// 商户侧门店名称
	Name *string `json:"name,omitempty"`
	// 地区编码,详细请见微信支付提供的文档
	AreaCode *string `json:"area_code,omitempty"`
	// 详细的商户门店地址
	Address *string `json:"address,omitempty"`
}

StoreInfo 商户门店信息

func (StoreInfo) MarshalJSON

func (o StoreInfo) MarshalJSON() ([]byte, error)

func (StoreInfo) String

func (o StoreInfo) String() string

Jump to

Keyboard shortcuts

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