ExWechatpay.Typespecs (ex_wechatpay v0.3.5)
View Source类型定义模块
该模块定义了 ExWechatpay 中使用的各种类型,为代码提供了更精确的类型规范。 包括基础类型、请求/响应类型、配置类型、错误类型等,以支持更好的类型检查和文档生成。
Summary
Types
交易金额信息
API 路径
HTTP 请求体
配置类型,使用 Schema 定义的类型
通用字典类型,用于表示各种数据结构
微信支付通知加密资源
错误返回类型
商品信息
订单优惠标记,用于指定订单支持的优惠类型
H5 支付请求参数
H5 支付响应参数
HTTP 请求头列表
HTTP 请求结构
HTTP 响应结构
HTTP 状态码
JSAPI 支付请求参数
JSAPI 支付响应参数
HTTP 请求方法
进程名称,可以是原子、全局名称或通过注册表访问的名称
Native 支付请求参数(二维码支付)
Native 支付响应参数
成功返回类型
GenServer 启动返回值
选项列表,通常用于配置和参数传递
HTTP 查询参数
支付者信息
支付通知数据
退款金额信息
退款查询响应参数
退款请求参数
退款响应参数
通用操作结果类型
支付场景描述
结算信息
微信支付签名信息
商户门店信息
交易查询响应参数
微信平台证书信息
Types
@type amount() :: %{total: non_neg_integer(), currency: String.t()}
交易金额信息
total- 总金额(单位:分)currency- 货币类型,默认为 CNY(人民币)
@type api() :: String.t()
API 路径
@type body() :: binary() | nil
HTTP 请求体
@type config_t() :: ExWechatpay.Config.Schema.t()
配置类型,使用 Schema 定义的类型
通用字典类型,用于表示各种数据结构
@type encrypted_resource() :: %{ algorithm: String.t(), ciphertext: String.t(), associated_data: String.t(), original_type: String.t(), nonce: String.t() }
微信支付通知加密资源
algorithm- 加密算法ciphertext- 密文associated_data- 附加数据original_type- 原始类型nonce- 随机串
@type err_t() :: {:error, ExWechatpay.Exception.t()}
错误返回类型
@type goods() :: %{ cost_price: non_neg_integer(), quantity: non_neg_integer(), goods_name: String.t(), goods_detail: String.t() | nil }
商品信息
cost_price- 商品单价(单位:分)quantity- 商品数量goods_name- 商品名称goods_detail- 商品详情
@type goods_tag() :: String.t()
订单优惠标记,用于指定订单支持的优惠类型
@type h5_transaction_req() :: %{ :description => String.t(), :out_trade_no => String.t(), :amount => amount(), :scene_info => scene_info(), optional(:notify_url) => String.t(), optional(:goods_tag) => goods_tag(), optional(:settle_info) => settle_info() }
H5 支付请求参数
必需字段:
description- 商品描述out_trade_no- 商户订单号amount- 订单金额信息scene_info- 支付场景描述
可选字段:
notify_url- 通知地址,默认使用配置中的通知地址goods_tag- 订单优惠标记settle_info- 结算信息
H5 支付响应参数
返回包含 H5 支付跳转链接的 map,键为字符串类型:
- "h5_url" - H5 支付跳转链接
HTTP 请求头列表
HTTP 请求结构
method- HTTP 方法url- 请求 URLheaders- 请求头body- 请求体
@type http_response() :: %{status: http_status(), headers: headers(), body: body()}
HTTP 响应结构
status- HTTP 状态码headers- 响应头body- 响应体
@type http_status() :: non_neg_integer()
HTTP 状态码
@type jsapi_transaction_req() :: %{ :description => String.t(), :out_trade_no => String.t(), :amount => amount(), :payer => payer(), optional(:notify_url) => String.t(), optional(:goods_tag) => goods_tag(), optional(:scene_info) => scene_info(), optional(:settle_info) => settle_info() }
JSAPI 支付请求参数
必需字段:
description- 商品描述out_trade_no- 商户订单号amount- 订单金额信息payer- 支付者信息
可选字段:
notify_url- 通知地址,默认使用配置中的通知地址goods_tag- 订单优惠标记scene_info- 支付场景描述settle_info- 结算信息
JSAPI 支付响应参数
返回包含预支付交易会话标识的 map,键为字符串类型:
- "prepay_id" - 预支付交易会话标识
@type method() :: :get | :post | :head | :patch | :delete | :options | :put
HTTP 请求方法
进程名称,可以是原子、全局名称或通过注册表访问的名称
@type native_transaction_req() :: %{ :description => String.t(), :out_trade_no => String.t(), :amount => amount(), optional(:notify_url) => String.t(), optional(:goods_tag) => goods_tag(), optional(:scene_info) => scene_info(), optional(:settle_info) => settle_info() }
Native 支付请求参数(二维码支付)
必需字段:
description- 商品描述out_trade_no- 商户订单号amount- 订单金额信息
可选字段:
notify_url- 通知地址,默认使用配置中的通知地址goods_tag- 订单优惠标记scene_info- 支付场景描述settle_info- 结算信息
Native 支付响应参数
返回包含二维码链接的 map,键为字符串类型:
- "code_url" - 二维码链接
@type ok_t(ret) :: {:ok, ret}
成功返回类型
GenServer 启动返回值
@type opts() :: keyword()
选项列表,通常用于配置和参数传递
HTTP 查询参数
@type payer() :: %{openid: String.t()}
支付者信息
openid- 用户在商户 appid 下的唯一标识
@type payment_notification() :: %{ id: String.t(), create_time: String.t(), event_type: String.t(), resource_type: String.t(), resource: transaction_query_resp() | refund_query_resp(), summary: String.t() }
支付通知数据
id- 通知 IDcreate_time- 通知创建时间event_type- 通知类型resource_type- 资源类型resource- 通知资源数据summary- 通知简要说明
@type refund_amount() :: %{ refund: non_neg_integer(), total: non_neg_integer(), currency: String.t() }
退款金额信息
refund- 退款金额(单位:分)total- 原订单金额(单位:分)currency- 货币类型,默认为 CNY(人民币)
退款查询响应参数
返回包含退款查询详情的 map,键为字符串类型,包含以下字段:
- "refund_id" - 微信支付退款号
- "out_refund_no" - 商户退款单号
- "transaction_id" - 微信支付订单号
- "out_trade_no" - 商户订单号
- "channel" - 退款渠道
- "user_received_account" - 退款入账账户
- "success_time" - 退款成功时间
- "create_time" - 退款创建时间
- "status" - 退款状态
- "amount" - 金额信息
- "promotion_detail" - 优惠退款信息
@type refund_req() :: %{ :out_refund_no => String.t(), :amount => refund_amount(), optional(:out_trade_no) => String.t(), optional(:transaction_id) => String.t(), optional(:reason) => String.t(), optional(:notify_url) => String.t(), optional(:funds_account) => String.t() }
退款请求参数
必需字段:
out_refund_no- 商户退款单号amount- 退款金额信息
可选字段:
out_trade_no- 商户订单号(与 transaction_id 二选一)transaction_id- 微信支付订单号(与 out_trade_no 二选一)reason- 退款原因notify_url- 退款结果通知地址funds_account- 退款资金来源
退款响应参数
返回包含退款详情的 map,键为字符串类型,包含以下字段:
- "refund_id" - 微信支付退款号
- "out_refund_no" - 商户退款单号
- "transaction_id" - 微信支付订单号
- "out_trade_no" - 商户订单号
- "channel" - 退款渠道
- "user_received_account" - 退款入账账户
- "success_time" - 退款成功时间
- "create_time" - 退款创建时间
- "status" - 退款状态
- "amount" - 金额信息
通用操作结果类型
@type scene_info() :: %{ payer_client_ip: String.t(), device_id: String.t(), store_info: store_info() | nil }
支付场景描述
payer_client_ip- 用户客户端 IPdevice_id- 设备 IDstore_info- 商户门店信息
@type settle_info() :: %{profit_sharing: boolean()}
结算信息
profit_sharing- 是否分账
微信支付签名信息
timestamp- 签名时间戳nonce_str- 随机字符串signature- 签名字符串
@type store_info() :: %{ id: String.t(), name: String.t(), area_code: String.t(), address: String.t() }
商户门店信息
id- 门店 IDname- 门店名称area_code- 门店行政区划码address- 门店详细地址
交易查询响应参数
返回包含完整交易详情的 map,键为字符串类型,包含以下字段:
- "appid" - 应用 ID
- "mchid" - 商户号
- "out_trade_no" - 商户订单号
- "transaction_id" - 微信支付订单号
- "trade_type" - 交易类型
- "trade_state" - 交易状态
- "trade_state_desc" - 交易状态描述
- "bank_type" - 付款银行
- "success_time" - 支付完成时间
- "payer" - 支付者信息
- "amount" - 订单金额信息
- "scene_info" - 支付场景描述
- "promotion_detail" - 优惠信息
@type wx_cert() :: %{ serial_no: String.t(), effective_time: String.t(), expire_time: String.t(), cert: term() }
微信平台证书信息
serial_no- 证书序列号effective_time- 证书生效时间expire_time- 证书过期时间cert- 证书内容