epay_http (erlang_pay v0.3.2)

View Source

支付出站 HTTP 客户端 / Outbound HTTP for payment gateways

基于 OTP httpc(同步、低频下单退款场景足够),强制 TLS 证书 + 主机名 校验(防中间人劫持支付请求)。绝不打印请求/响应报文(含密钥/签名/单据)。

EP-21 HTTPS-only 出站边界:所有 URL 在发起网络调用前经 validate_url/1 校验 —— 仅接受 https scheme(大小写不敏感),拒绝明文 http/ftp、 无 scheme 裸字符串、携带 userinfo(user:pass@host)及无 host 的 URL。 支付凭据 / 签名请求绝不走明文 HTTP 通道;校验失败在 httpc 之前返回 {error, {insecure_url, binary()}},绝不起任何网络调用。

与 imboy 的 elib_req 区别:elib_req 硬编码 JSON、且 DEBUG 打印整个响应、 未校验对端证书 —— 不可用于支付。本模块为支付专用安全客户端。

Summary

Functions

GET(主动查单 / 对账用)。Headers 通常含 Authorization。无请求体。

POST application/x-www-form-urlencoded(Stripe)。Body 为已编码表单串。

POST application/json。Body 为已序列化的 JSON 二进制。

Types

headers()

-type headers() :: [{binary() | string(), binary() | string()}].

result()

-type result() ::
          {ok, Status :: pos_integer(), RespHeaders :: list(), Body :: binary()} | {error, term()}.

Functions

get(Url, Headers)

-spec get(binary() | string(), headers()) -> result().

GET(主动查单 / 对账用)。Headers 通常含 Authorization。无请求体。

get(Url, Headers, Opts)

-spec get(binary() | string(), headers(), map()) -> result().

post_form(Url, Headers, Body)

-spec post_form(binary() | string(), headers(), binary()) -> result().

POST application/x-www-form-urlencoded(Stripe)。Body 为已编码表单串。

post_form(Url, Headers, Body, Opts)

-spec post_form(binary() | string(), headers(), binary(), map()) -> result().

post_json(Url, Headers, Body)

-spec post_json(binary() | string(), headers(), binary()) -> result().

POST application/json。Body 为已序列化的 JSON 二进制。

post_json(Url, Headers, Body, Opts)

-spec post_json(binary() | string(), headers(), binary(), map()) -> result().