Commerce Wechatpay

Component ID

2612324

Component name

Commerce Wechatpay

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

270

Component created

Component changed

Component body

Wechat (Weixin) payment solution for Drupal Commerce

This module is currently under maintenance and keep updating in Github

Requirements

  1. SDK package overtrue/wechat

    在安装本模块前,请下载overtrue的wechatSDK,并放入"libraries"文件夹中

    Please download SDK package and put inside "libraries" folder before install this module

    cd PATH_TO_DRUPAL/sites/all/libraries
    git clone https://github.com/overtrue/wechat.git overtrue_wechat
    cd overtrue_wechat
    git checkout 3.3.13 # Recommended version is 3.3.13
    composer install -vvv # Install dependencies.
    

    更多关于此SDK的信息请参考文档

    More inforamtion about overtrue_wechat please see docs

Installation

  1. Follow the default way of set-up a payment module for Drupal Commerce, take a look at commerce_paypal installation if you don't understand.
  2. Configure Wechat payment (only for Merchat pay - 公众号支付)

    Set an authorized URL alias in Wechat back-office, image example

    在微信公众平台的后台,将如下地址设置为一个支付授权目录, 图片示例

    http://YOUR_DOMAIN.COM/ALIAS_TO_DRUPAL_ROOT/commerce_wechatpay/checkout/

Payment methods

  • Merchant pay (jsapi)(公众号支付)

    Requires opening payment page in Wechat browser, otherwise will return error. This method is good when developing all-browse-in-wechat web page.

  • QR code pay (native)(扫码支付)

    (本模块使用的是扫码支付的支付模式二,所以无需设置扫码支付的支付回调URL)

    (This module uses wechat scan&pay mode 2, so no need to set redirect URL on scan&pay settings area)

    Provides a QR code image when going to the off-site payment gateway, allows user to scan the QR code and pay directly in Wechat. If opening payment page in Wechat browser, user can long-press the QRcode to pay (wechat build-in feature) but will not be returned back to successful page.

API docs

Overwrite main class handler

use the API to change to your class first

    function YOUR_MODULE_commerce_wechatpay_class_name_alter(&$class_name) {
      $class_name = 'YOUR_OWN_HANDLER_CLASS';
    }

then define your class, it's recommand if you extend from the original class

    Class YOUR_OWN_HANDLER_CLASS extends CommerceWechatpay {
      public function orderId2outTradeNo ($order_num)
      {
        // I want my own way for transfering order_id to out_trade_no
        return md5('some_secret_string'.md5($order_num));
      }

      // other overwritten, blabla
    }

Overwrite javascript process handler

use the API to change to your js process handler first

    function YOUR_MODULE_commerce_wechatpay_javascript_handler_name_alter(&$js_function_name) {
      $js_function_name = 'YOUR_OWN_JS_HANDLER_FUNCTION';
    }

then define your javascript function

    window.YOUR_OWN_JS_HANDLER_FUNCTION = function(configs, return_success_url, return_failure_url)
    {
      // some overwritten, blabla
    }

Sponsorship

Current maintainers:

This module is sponsored by: