WeChatPay driver for the Omnipay PHP payment processing library

Overview

Omnipay: WechatPay

WechatPay driver for the Omnipay PHP payment processing library

Build Status Latest Stable Version Total Downloads

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements WechatPay support for Omnipay.

Installation

Omnipay is installed via Composer. To install:

composer require lokielse/omnipay-wechatpay

Basic Usage

The following gateways are provided by this package:

  • WechatPay (Wechat Common Gateway) 微信支付通用网关
  • WechatPay_App (Wechat App Gateway) 微信APP支付网关
  • WechatPay_Native (Wechat Native Gateway) 微信原生扫码支付支付网关
  • WechatPay_Js (Wechat Js API/MP Gateway) 微信网页、公众号、小程序支付网关
  • WechatPay_Pos (Wechat Micro/POS Gateway) 微信刷卡支付网关
  • WechatPay_Mweb (Wechat H5 Gateway) 微信H5支付网关

Usage

Create Order doc

//gateways: WechatPay_App, WechatPay_Native, WechatPay_Js, WechatPay_Pos, WechatPay_Mweb
$gateway    = Omnipay::create('WechatPay_App');
$gateway->setAppId($config['app_id']);
$gateway->setMchId($config['mch_id']);
$gateway->setApiKey($config['api_key']);

$order = [
    'body'              => 'The test order',
    'out_trade_no'      => date('YmdHis').mt_rand(1000, 9999),
    'total_fee'         => 1, //=0.01
    'spbill_create_ip'  => 'ip_address',
    'fee_type'          => 'CNY'
];

/**
 * @var Omnipay\WechatPay\Message\CreateOrderRequest $request
 * @var Omnipay\WechatPay\Message\CreateOrderResponse $response
 */
$request  = $gateway->purchase($order);
$response = $request->send();

//available methods
$response->isSuccessful();
$response->getData(); //For debug
$response->getAppOrderData(); //For WechatPay_App
$response->getJsOrderData(); //For WechatPay_Js
$response->getCodeUrl(); //For Native Trade Type

Notify doc

$gateway    = Omnipay::create('WechatPay');
$gateway->setAppId($config['app_id']);
$gateway->setMchId($config['mch_id']);
$gateway->setApiKey($config['api_key']);

$response = $gateway->completePurchase([
    'request_params' => file_get_contents('php://input')
])->send();

if ($response->isPaid()) {
    //pay success
    var_dump($response->getRequestData());
}else{
    //pay fail
}

Query Order doc

$response = $gateway->query([
    'transaction_id' => '1217752501201407033233368018', //The wechat trade no
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

Close Order doc

$response = $gateway->close([
    'out_trade_no' => '201602011315231245', //The merchant trade no
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

Refund doc

$gateway->setCertPath($certPath);
$gateway->setKeyPath($keyPath);

$response = $gateway->refund([
    'transaction_id' => '1217752501201407033233368018', //The wechat trade no
    'out_refund_no' => $outRefundNo,
    'total_fee' => 1, //=0.01
    'refund_fee' => 1, //=0.01
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

QueryRefund doc

$response = $gateway->queryRefund([
    'refund_id' => '1217752501201407033233368018', //Your site trade no, not union tn.
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

Shorten URL (for WechatPay_Native) doc

$response = $gateway->shortenUrl([
    'long_url' => $longUrl
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
var_dump($response->getShortUrl());

Query OpenId (for WechatPay_Pos) doc

$response = $gateway->queryOpenId([
    'auth_code' => $authCode
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
var_dump($response->getOpenId());

For general usage instructions, please see the main Omnipay repository.

Related

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

Comments
  • Wechat timeStamp is string

    Wechat timeStamp is string

    公众号 iphone 6s plus error "微信支付调用JSAPI缺少参数:timeStamp"

    public function getOrderData()
    {
        if ($this->isSuccessful()) {
            $timestamp = time();
            $data = array (
                'app_id'    => $this->request->getAppId(),
                'mch_id'    => $this->request->getMchId(),
                'prepay_id' => $this->getPrepayId(),
                'package'   => 'Sign=WXPay',
                'nonce'     => md5(uniqid()),
                'timestamp' => "$timestamp",
            );
    
            $data['sign'] = Helper::sign($data, $this->request->getApiKey());
        } else {
            $data = null;
        }
    
        return $data;
    }
    

    很迷芒 虽然这是官方的写法 但按照你以前写的 , 安卓 iphone5s 并没有报错,唯独在 6s plus 下面报这个错

    opened by getpu 17
  • 有获取openid的方法吗?

    有获取openid的方法吗?

    用的WechatPay_Js 公众号支付,而公众号支付,需要用户OPENID,找许久,源码里没有关于获取OPENID的代码,不知楼主是否有做相关功能?或者说是否有公众号支付的相关案例。以下是提示错误: The open_id parameter is required

    我的代码是: ` $gateway = Omnipay::create('WechatPay_Js'); $gateway->setAppId(config('pay.wechatpay.appid')); $gateway->setMchId(config('pay.wechatpay.mchid')); $gateway->setApiKey(config('pay.wechatpay.key')); $gateway->setNotifyUrl('http://example.com/notify'); $gateway->setTradeType('JSAPI');

        $order = [
            'body'              => 'The test order',
            'out_trade_no'      => date('YmdHis').mt_rand(1000, 9999),
            'total_fee'         => 1, //=0.01
            'spbill_create_ip'  => 'ip_address',
            'fee_type'          => 'CNY'
        ];
    

    `

    opened by esolo0121 11
  • fixed  CreateOrderRequest中的openid参数错误

    fixed CreateOrderRequest中的openid参数错误

    公众号支付-统一下单接口文档说明结合本地代码测试,此字段应为openid而不是open_id,与企业付款接口中的openid一致。

    另外,为了代码风格一致,将参数变量由openId改为open_id。

    ps. 怪微信接口的文档不够规范,感觉像是多个部门分开弄的,像商户号在统一下单是叫mch_id,而在企业付款接口中却是mchid。

    opened by SuccessGo 7
  • 很诡异的退款证书问题

    很诡异的退款证书问题

    感谢开发了很实用的类库。在实际使用中,退款这块偶尔报错,要说如果证书有问题,会无法退款,但是大部分时候没问题,偶尔报错,很是诡异,具体堆栈: 服务器环境是 PHP 7.0.6

    2016-08-27 16:56:57
    [171.83.121.13][9778][5r160sfns012mcr9j0r1i4m844][error][Guzzle\Http\Exception\CurlException]
    Guzzle\Http\Exception\CurlException: [curl] 58: unable to use client
    certificate (no key found or wrong pass phrase?) [url]
    https://api.mch.weixin.qq.com/secapi/pay/refund in
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:359
    Stack trace:
    #0
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(292):
    Guzzle\Http\Curl\CurlMulti->isCurlException(Object(Guzzle\Http\Message\EntityEnclosingRequest),
    Object(Guzzle\Http\Curl\CurlHandle), Array)
    #1
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(257):
    Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest),
    Object(Guzzle\Http\Curl\CurlHandle), Array)
    #2
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(240):
    Guzzle\Http\Curl\CurlMulti->processMessages()
    #3
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(224):
    Guzzle\Http\Curl\CurlMulti->executeHandles()
    #4
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(111):
    Guzzle\Http\Curl\CurlMulti->perform()
    #5
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMultiProxy.php(94):
    Guzzle\Http\Curl\CurlMulti->send()
    #6
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php(284):
    Guzzle\Http\Curl\CurlMultiProxy->send()
    #7
    /data/wwwroot/site.shenghuotianxia.com/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php(198):
    Guzzle\Http\Client->send(Object(Guzzle\Http\Message\EntityEnclosingRequest))
    #8
    /data/wwwroot/site.shenghuotianxia.com/vendor/lokielse/omnipay-wechatpay/src/Message/RefundOrderRequest.php(252):
    Guzzle\Http\Message\Request->send()
    #9
    /data/wwwroot/site.shenghuotianxia.com/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php(675):
    Omnipay\WechatPay\Message\RefundOrderRequest->sendData(Array)
    #10
    /data/wwwroot/site.shenghuotianxia.com/wechat/models/DepositOrder.php(261):
    Omnipay\Common\Message\AbstractRequest->send()
    
    opened by lonestonewy 6
  • 商户号该产品权限未开通

    商户号该产品权限未开通

    { "return_code": "FAIL", "return_msg": "商户号该产品权限未开通,请前往商户平台>产品中心检查后重试" }

    APP微信支付时,返回这个错误。这是什么问题,开放平台已经绑定该公众号了。后台填的是公众号app_id,商户号mch_id,支付密钥api_key。我在网页中测试微信扫码支付时正常,可以支付。

    opened by zhu6621 5
  •  企业付款到零钱双向证书配置添加

    企业付款到零钱双向证书配置添加

    Enterprise payment to change two-way certificate configuration added! Otherwise an error will occur! "err_code" => "CA_ERROR" "err_code_des" => "证书出错,请登录微信支付商户平台下载证书" I can't control composer.json submission

    opened by sunanzhi 3
  • WechatPay_Native 微信支付问题

    WechatPay_Native 微信支付问题

    $gateway = Omnipay::create('WechatPay_Native'); $gateway->setAppId('wx0b2cb4687763f2c5'); $gateway->setMchId('1303570701'); $gateway->setApiKey('qK2Szcejbv19r9hI6VbaqodqpH3x5mXd'); $order = [ 'body' => 'The test order', 'out_trade_no' => date('YmdHis').mt_rand(1000, 9999), 'total_fee' => 0.01, //=0.01 'spbill_create_ip' => 'ip_address', 'fee_type' => 'CNY' ];

        $request  = $gateway->purchase($order);
        $response = $request->send();
    
        $response->isSuccessful();
        $response->getData(); //For debug
        $response->getAppOrderData(); //For WechatPay_App
        $response->getJsOrderData(); //For WechatPay_Js
        $response->getCodeUrl(); //For Native Trade Type
    

    Omnipay \ Common \ Exception \ InvalidRequestException The notify_url parameter is required

    opened by pangxioujiang 3
  • Can't find the certificate

    Can't find the certificate

    路径 /Users/Breeze/yeli_network/youbao_php/private/wechat/pay/apiclient_cert.pem 是从微信开放平台下载api证书并且内容正确

    异常捕获的错误 SSL: Can't find the certificate "/Users/Breeze/yeli_network/youbao_php/private/wechat/pay/apiclient_cert.pem" and its private key in the Keychain.

    路径文件是存在的 Breeze-MacBook-Pro:~ Breeze$ cat /Users/Breeze/yeli_network/youbao_php/private/wechat/pay/apiclient_cert.pem -----BEGIN CERTIFICATE----- MIIEaDCCA9GgAwIBAgIDZCtgMA0GCSqGSIb3DQEBBQUAMIGKMQswCQYDVQQGEwJD TjESMBAGA1UECBMJR3Vhbmdkb25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UE ChMHVGVuY2VudDEMMAoGA1UECxMDV1hHMRMwEQYDVQQDEwpNbXBheW1jaENBMR8w HQYJKoZIhvcNAQkBFhBtbXBheW1jaEB0ZW5jZW50MB4XDTE2MTEyMjA0MDEwMloX....

    以下是配置

    /** * @var $gateway Gateway */ $gateway = Omnipay::create('WechatPay'); $gateway->setAppId(Config::get('payment.wechat.appId')); $gateway->setMchId(Config::get('payment.wechat.mchId')); $gateway->setApiKey(Config::get('payment.wechat.apiKey')); $gateway->setKeyPath('/Users/Breeze/yeli_network/youbao_php/private/wechat/pay/apiclient_key.pem'); $gateway->setCertPath('/Users/Breeze/yeli_network/youbao_php/private/wechat/pay/apiclient_cert.pem');

    opened by breeze-ev 3
  • Please update dependency

    Please update dependency "omnipay/common" to version 3

    We use this package with our Symfony 3 project, the package "omnipay/common" is dependent on "symfony/event-dispatcher" 2 version, which will conflict with same package in Symfony3, Please update the dependency to version 3, thanks a lot.

    opened by videni 3
  • 作者你好,我想同时使用微信、银联、支付宝支付、但是他们之间好像有冲突

    作者你好,我想同时使用微信、银联、支付宝支付、但是他们之间好像有冲突

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Conclusion: don't install lokielse/omnipay-wechatpay v3.0.8
        - Conclusion: don't install omnipay/common 2.5.2
        - Conclusion: don't install lokielse/omnipay-wechatpay v3.0.7
        - Installation request for ignited/laravel-omnipay ^2.3 -> satisfiable by ignited/laravel-omnipay[2.3.0].
        - lokielse/omnipay-wechatpay v3.0.3 requires omnipay/common ^3.0 -> satisfiable by omnipay/common[v3.0.0, v3.0.1, v3.0.2].
        - lokielse/omnipay-wechatpay v3.0.4 requires omnipay/common ^3.0 -> satisfiable by omnipay/common[v3.0.0, v3.0.1, v3.0.2].
        - lokielse/omnipay-wechatpay v3.0.5 requires omnipay/common ^3.0 -> satisfiable by omnipay/common[v3.0.0, v3.0.1, v3.0.2].
        - lokielse/omnipay-wechatpay v3.0.6 requires omnipay/common ^3.0 -> satisfiable by omnipay/common[v3.0.0, v3.0.1, v3.0.2].
        - Can only install one of: omnipay/common[v3.0.0, v2.5.0].
        - Can only install one of: omnipay/common[v3.0.1, v2.5.0].
        - Can only install one of: omnipay/common[v3.0.2, v2.5.0].
        - ignited/laravel-omnipay 2.3.0 requires omnipay/common 2.5.* -> satisfiable by omnipay/common[2.5.2, v2.5.0, v2.5.1].
        - Conclusion: don't install omnipay/common v2.5.1
        - Installation request for lokielse/omnipay-wechatpay ^3.0 -> satisfiable by lokielse/omnipay-wechatpay[v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8].
    

    composer.json

      "require": {
        "php": ">=7.0.0",
        "barryvdh/laravel-ide-helper": "^2.4",
        "econea/nusoap": "v0.9.5.4",
        "fideloper/proxy": "~3.3",
        "gzero/eloquent-tree": "^3.1",
        "ignited/laravel-omnipay": "^2.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "lokielse/omnipay-alipay": "^2.3",
        "lokielse/omnipay-unionpay": "^0.4",
        "lokielse/omnipay-wechatpay": "^3.0",
        "maatwebsite/excel": "2.1.*",
        "mews/captcha": "^2.1",
        "omnipay/paypal": "^2.6",
        "symfony/event-dispatcher": "2.8"
      },
    

    我看见issues有16年的解决方法,不知道是否有其他更好的解决方法、困扰了一早上、这个问题

    opened by FatherGodHz 2
  • 帅哥,queryRefund 是不是参数检查哪里有点问题?

    帅哥,queryRefund 是不是参数检查哪里有点问题?

    $response = $gateway->queryRefund([
        'refund_id' => '1217752501201407033233368018', //Your site trade no, not union tn.
    ])->send();
    

    The 'transaction_id' or 'out_trade_no' parameter is required

    貌似和查询订单没有区分开. 多谢.

    opened by xjdata 2
  • Confirming to Omnipay

    Confirming to Omnipay

    Someone one says omnipay-wechatpay does not confirm as from the link, https://aimeos.org/help/viewtopic.php?f=18&t=2287&start=0

    Please comment.

    Regards,

    opened by godadada 3
  • Missing Notify URL

    Missing Notify URL

    I would expect to see a notify_url parameter to make an order request but this seems to be missing. Can someone explain why or the assumption used here?

    opened by larrytech7 1
  • 退款通知验证有问题

    退款通知验证有问题

    官方文档可以看出,异步通知的参数中,并没有签名参数,只需要对req_info解密即可。 但是在代码中发现 `if (isset($data['sign']) && $data['sign'] && $sign === $data['sign']) { $responseData['sign_match'] = true; } else { $responseData['sign_match'] = false; }

        if ($responseData['sign_match'] && isset($data['refund_status']) && $data['refund_status'] == 'SUCCESS') {
            $responseData['refunded'] = true;
        } else {
            $responseData['refunded'] = false;
        }`
    

    $data['sign']是不存在的,所以在前面调用response的data,sign_match一定是false,refunded也是false @lokielse 如果有空看看吧,现在我用的是1.x

    opened by wcj343169893 0
Releases(v3.0.11)
Owner
Loki Else
加关注,不迷路 (´∀`*)
Loki Else
Implementation of a library to process SISP vinti4 payment in a easy way.

Implementation of a library to process SISP vinti4 payment in a easy way.

Faxi 6 Nov 3, 2022
A Laravel SQS driver that removes the 256KB payload limit by saving the payloads into S3.

Simple SQS Extended Client Introduction Simple SQS Extended Client is a Laravel queue driver that was designed to work around the AWS SQS 256KB payloa

Simple Software LLC 7 Dec 8, 2022
2c2p payment gateway Redirect PHP-SDK

2c2p payment gateway Redirect PHP-SDK

Bilions 2 Oct 1, 2022
WHMCS USDT Payment Gateway.

WHMCS USDT Payment Gateway 支持 TRC-20 USDT 转账交易,系统可完成自动化分配地址,入账等操作,配置简单,无需第三方支付平台中转,所有交易直达您的私人账户。 Requirements PHP 7.2 or greater. WHMCS 8.1 or greater

Licson 59 Jan 7, 2023
API client for ThePay - payment gate API

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

ThePay.cz s.r.o. 3 Oct 27, 2022
Simple papara payment api that you can use without the need for an activation key

PaparaQrApi Papara QR Api Simple papara payment api that you can use without the need for an activation key. Explore the docs » View Demo About The Pr

Azad 6 Dec 20, 2022
BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

null 3 May 18, 2022
Lightweight PHP library for WhatsApp API to send the whatsapp messages in PHP provided by ultramsg.com

Ultramsg.com WhatsApp API PHP SDK Lightweight PHP library for WhatsApp API to send the whatsappp messages in PHP provided by Ultramsg.com Installation

Ultramsg 117 Dec 26, 2022
Google-api-php-client - A PHP client library for accessing Google APIs

Google APIs Client Library for PHP Reference Docs https://googleapis.github.io/google-api-php-client/main/ License Apache 2.0 The Google API Client Li

Google APIs 8.4k Dec 30, 2022
Wise-php - This library is written to accommodate the wise API's use in php projects With Wise

Wise-php - This library is written to accommodate the wise API's use in php projects With Wise you can automate payments, connect your business tools, and create ways to manage your finances. You can also power your cross-border and domestic payouts.

Albert Xhani 15 Nov 17, 2022
A framework agnostic PHP library to build chat bots

BotMan If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course. About BotMa

BotMan 5.8k Jan 3, 2023
PHP library for the Stripe API.

Stripe PHP bindings The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a p

Stripe 3.3k Jan 5, 2023
A PHP library for communicating with the Twilio REST API and generating TwiML.

twilio-php The default branch name for this repository has been changed to main as of 07/27/2020. Documentation The documentation for the Twilio API c

Twilio 1.4k Jan 2, 2023
A PHP library for the Campaign Monitor API

createsend A PHP library which implements the complete functionality of the Campaign Monitor API. Installation Composer If you use Composer, you can r

Campaign Monitor 287 Jan 6, 2023
PHP 5.3+ library which helps you to interact with the DigitalOcean API

DigitalOcean The version 2 of the API will be available soon ! Please visit DigitalOceanV2 and contribute :) This PHP 5.3+ library helps you to intera

Antoine Kirk 156 Jul 30, 2022
A versatile PHP Library for Google PageSpeed Insights

PhpInsights An easy-to-use API Wrapper for Googles PageSpeed Insights. The JSON response is mapped to objects for an headache-free usage. Installation

Daniel Sentker 110 Dec 28, 2022
PHP library for the GitHub API v3

GitHub API v3 - PHP Library Currently under construction. Overview Provides access to GitHub API v3 via an Object Oriented PHP library. The goal of th

Darren Rees 62 Jul 28, 2022
PHP library to use IOTA REST API to help node management and tangle queries

iota.php About PHP library to use IOTA REST API to help node management and tangle queries. Please be aware that this library is in an early developme

IOTA Community 45 Dec 13, 2022
A Class Library enabling Asterisk ARI functionality for PHP

phpari A Class Library enabling Asterisk ARI functionality for PHP Dependencies These are the minimum requirements to have phpari installed on your se

Nir Simionovich 87 Jan 5, 2023