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 :sandbox environment, You need to use mix wechat_pay.get_sandbox_signkey to fetch the Sandbox API Key.

Payment methods

When use WechatPay in MyApp.Pay module, it will generate following payment method modules for you:

Plug

We will also generate some Plugs to simplify the process of handling notification from Wechat’s Payment Gateway:

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

Types

The Configuration

Link to this section Types

Link to this type config() View Source
config() :: [env: :sandbox | :production, appid: String.t, mch_id: String.t, apikey: String.t, ssl_cacert: String.t, ssl_cert: String.t, ssl_key: String.t]

The Configuration

  • env - :sandbox or :production
  • appid - APP ID
  • mch_id - Merchant ID
  • apikey - API key
  • ssl_cacert - CA Root certificate in PEM
  • ssl_cert - Certificate in PEM
  • ssl_key - Private key in PEM