Driver WechatPay untuk perpustakaan pemrosesan pembayaran Omnipay PHP
Omnipay adalah pustaka pemrosesan pembayaran multi-gateway agnostik kerangka kerja untuk PHP 5.3+ Paket ini mengimplementasikan dukungan WechatPay untuk Omnipay.
Omnipay diinstal melalui Komposer.
composer require lokielse/omnipay-wechatpay
Gateway berikut disediakan oleh paket ini:
//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 OmnipayWechatPayMessageCreateOrderRequest $request
* @var OmnipayWechatPayMessageCreateOrderResponse $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
$ 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
}
$ response = $ gateway -> query ([
' transaction_id ' => ' 1217752501201407033233368018 ' , //The wechat trade no
])-> send ();
var_dump ( $ response -> isSuccessful ());
var_dump ( $ response -> getData ());
$ response = $ gateway -> close ([
' out_trade_no ' => ' 201602011315231245 ' , //The merchant trade no
])-> send ();
var_dump ( $ response -> isSuccessful ());
var_dump ( $ response -> getData ());
$ 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 ());
$ response = $ gateway -> queryRefund ([
' refund_id ' => ' 1217752501201407033233368018 ' , //Your site trade no, not union tn.
])-> send ();
var_dump ( $ response -> isSuccessful ());
var_dump ( $ response -> getData ());
WechatPay_Native
). $ response = $ gateway -> shortenUrl ([
' long_url ' => $ longUrl
])-> send ();
var_dump ( $ response -> isSuccessful ());
var_dump ( $ response -> getData ());
var_dump ( $ response -> getShortUrl ());
WechatPay_Pos
). $ response = $ gateway -> queryOpenId ([
' auth_code ' => $ authCode
])-> send ();
var_dump ( $ response -> isSuccessful ());
var_dump ( $ response -> getData ());
var_dump ( $ response -> getOpenId ());
Untuk petunjuk penggunaan umum, silakan lihat repositori utama Omnipay.
Jika Anda mengalami masalah umum dengan Omnipay, kami sarankan untuk memposting di Stack Overflow. Pastikan untuk menambahkan tag omnipay agar mudah ditemukan.
Jika Anda ingin terus mengikuti perkembangan pengumuman rilis, mendiskusikan ide untuk proyek, atau mengajukan pertanyaan lebih rinci, ada juga milis yang dapat Anda berlangganan.
Jika Anda yakin telah menemukan bug, harap laporkan menggunakan pelacak masalah GitHub, atau lebih baik lagi, fork perpustakaan dan kirimkan permintaan penarikan.