All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Using new
:crypto
API::crypto.crypto_one_time/4
(https://erlang.org/doc/apps/crypto/new_api.html) in theWechatPay.Plug.Refund
module. - Require Elixir >= 1.10
- Require Elixir >= 1.7
- No magic macros
- Simplified functional interface
- Added
WechatPay.API.download_fund_flow/3
. - Added
WechatPay.API.batch_query_comments/3
. - Added support for two sign types:
:md5
and:sha256
.
- Update
Mix.Tasks.WechatPay.GetSandboxSignkey
to print friendly error message.
- Require Elixir >= 1.6
- Make the config
ssl_cacert
an optional option. (#11)
- Update dependency
:httpoison
to~> 1.0
. - Added new config option
:api_host
. Which make it possible to use oversea nodes such as https://apihk.mch.weixin.qq.com/ and https://apius.mch.weixin.qq.com/. This also replace the:env
config. - Added a flexible configuration system to fit more usage scenarios.
- Make JSON library an optional dependency, Jason is recommended.
- Fixes
:xmerl
is missing in the application list.
- Added
WechatPay.Plug.Refund
to handle refund notification from Wechat's Payment Gateway - Parse XML with
:xmerl
, drop dependency onsweet_xml
.
- Added task
mix wechat_pay.get_sandbox_signkey
to get the Sandbox API Key. - Fixes wrong return value of
WechatPay.Helper.get_sandbox_signkey/2
.
Guides are added on the Online documentation. I strongly recommend you to go through it aftre reading this changelog.
Now you have to define you own pay module, then use
WechatPay,
with an :otp_app
option.
defmodule MyPay do
use WechatPay, otp_app: :my_app
end
Then config with:
config :my_app, MyPay,
env: :production,
appid: "wx8888888888888888",
mch_id: "1900000109",
api_key: "192006250b4c09247ec02edce69f6a2d",
ssl_cacert: File.read!("fixture/certs/rootca.pem"),
ssl_cert: File.read!("fixture/certs/apiclient_cert.pem"),
ssl_key: File.read!("fixture/certs/apiclient_key.pem")
This change makes it possible to define multiple pay modules with their own configuration.
When use
WechatPay in MyPay
module, it will generate following
payment method modules for you:
MyPay.App
MyPay.JSAPI
MyPay.Native
Each refers to a pay scenario of WechatPay.
A new module WechatPay.Handler
is added to assist processing the data from
Wechat's Payment Gateway.
Now the Plugs are only takes the responsibility to commutate with Wechat's Payment Gateway, so you should passed in your own handler:
post "/pay/cb/payment", MyPay.Plug.Payment, [handler: MyPaymentHandler]
and the handler implementation should looks like this:
defmodule MyPaymentHandler do
use WechatPay.Handler
@impl WechatPay.Handler
def handle_data(conn, data) do
# do something with data
:ok
end
# This is optional
@impl WechatPay.Handler
def handle_error(conn, error, data) do
Logger.error(inspect(error))
end
end
As the Sandbox API Key is required to be fetched before configuring,
so the WechatPay.API.get_sandbox_signkey/0
is moved to
WechatPay.Helper.get_sandbox_signkey/2
, which accept api_key
and mch_id
to generate the Sandbox API Key.
iex> WechatPay.Helper.get_sandbox_signkey("wx8888888888888888", "1900000109")
...> {:ok, "the-key"}
The ssl_cacertfile
, ssl_certfile
, ssl_keyfile
and ssl_password
configuration are removed.
Instead, the ssl_cacert
, ssl_cert
and ssl_key
configuration is added, these
new configs accepts binary. Which make it possible to read these sensitive data
from an ENV.
config :wechat_pay, MyPay,
ssl_cacert: File.read!("fixture/certs/rootca.pem"),
ssl_cert: File.read!("fixture/certs/apiclient_cert.pem"),
ssl_key: "${MY_APP_WECHAT_PAY_SSL_KEY}"
- Added
MyPay.App.generate_pay_request/1
to generate pay request for App.
- Correctly handle malformed XML data.
- Added
WechatPay.Error
. - Fixes warnings on Elixir 1.4.
- Added
WechatPay.API.get_sandbox_signkey/0
to get sandbox signkey. - Rename
WechatPay.Plug.Notify
->WechatPay.Plug.Callback
, and rewrite the flow. Now it's easier to handle callbacks from Wehcat's Payment Gateway. - Drop support for loading config from
{:system, ENV}
. It seems not a good idea to do this, consider https://github.com/bitwalker/conform.
- Fixes hexdocs.pm does not recognize upcase in URL.
- Improve docs.
- Initial support Wechat Pay's JSAPI, Native and App.