WechatPay v0.3.1 WechatPay View Source
WechatPay provide toolkit for Wechat Payment Platform.
Setup
You need to define you own pay module, then use WechatPay, with an :otp_app
option.
defmodule MyApp.Pay do
use WechatPay, otp_app: :my_app
end
Then you can config your app with:
config :my_app, MyApp.Pay,
env: :production,
appid: "wx8888888888888888",
mch_id: "1900000109",
apikey: "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")
NOTE: If your are using the
:sandboxenvironment, You need to usemix wechat_pay.get_sandbox_signkeyto fetch the Sandbox API Key.
Payment methods
When use WechatPay in MyApp.Pay module, it will generate following
payment method modules for you:
MyApp.Pay.App- Implements theWechatPay.PaymentMethod.AppbehaviourMyApp.Pay.JSAPI- Implements theWechatPay.PaymentMethod.JSAPIbehaviourMyApp.Pay.Native- Implements theWechatPay.PaymentMethod.Nativebehaviour
Plug
We will also generate some Plugs to simplify the process of handling notification from Wechat’s Payment Gateway:
MyApp.Pay.Plug.Payment- Implements theWechatPay.Plug.Paymentbehaviour
Phoenix Example
In lib/my_app_web/router.ex:
post "/pay/cb/payment", MyApp.Pay.Plug.Payment, [handler: MyApp.PaymentHandler]
Link to this section Summary
Link to this section Types
The Configuration
env-:sandboxor:productionappid- APP IDmch_id- Merchant IDapikey- API keyssl_cacert- CA Root certificate in PEMssl_cert- Certificate in PEMssl_key- Private key in PEM