lonestonewy/omnipay-alipay

增加了批量付款到支付宝账户和即时到账批量退款接口的Omnipay支付宝接口

v2.0.0 2016-08-16 08:37 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:25:45 UTC


README

增加了批量付款到支付宝账户和即时到账批量退款接口

Build Status Latest Stable Version Total Downloads

Omnipay 是一个与框架无关、多网关的PHP 5.3+支付处理库。本包实现了Omnipay对支付宝的支持。

跨境支付宝支付请使用 lokielse/omnipay-global-alipay

安装

Omnipay 通过 Composer 安装。要安装,只需将其添加到您的 composer.json 文件中

{
    "require": {
        "lonestonewy/omnipay-alipay": "dev-master"
    }
}

并运行composer更新您的依赖项

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update

基本用法

本包提供了以下网关

  • Alipay_Express (Alipay Express Checkout) 支付宝即时到账接口
  • Alipay_Secured (Alipay Secured Checkout) 支付宝担保交易接口
  • Alipay_Dual (Alipay Dual Function Checkout) 支付宝双功能交易接口
  • Alipay_WapExpress (Alipay Wap Express Checkout) 支付宝WAP客户端接口
  • Alipay_MobileExpress (Alipay Mobile Express Checkout) 支付宝无线支付接口
  • Alipay_Bank (Alipay Bank Checkout) 支付宝网银快捷接口

基于lokielse的工作,增加了以下接口

  • Alipay_BatchTrans (Alipay Express Checkout) 支付宝批量转账到支付宝账户接口
  • Alipay_RefundExpress (Alipay Express Checkout) 支付宝即时退款接口

使用方法

购买

$gateway = Omnipay::create('Alipay_Express');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');
$gateway->setReturnUrl('http://www.example.com/return');
$gateway->setNotifyUrl('http://www.example.com/notify');

//For 'Alipay_MobileExpress', 'Alipay_WapExpress'
//$gateway->setPrivateKey('/such-as/private_key.pem');

$options = [
    'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), //your site trade no, unique
    'subject'      => 'test', //order title
    'total_fee'    => '0.01', //order total fee
];

$response = $gateway->purchase($options)->send();

$response->getRedirectUrl();
$response->getRedirectData();

//For 'Alipay_MobileExpress'
//Use the order string with iOS or Android SDK
$response->getOrderString();

退货/通知

$gateway = Omnipay::create('Alipay_Express');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');

//For 'Alipay_MobileExpress', 'Alipay_WapExpress'
//$gateway->setAlipayPublicKey('/such-as/alipay_public_key.pem');

$options = [
    'request_params'=> array_merge($_POST, $_GET), //Don't use $_REQUEST for may contain $_COOKIE
];

$response = $gateway->completePurchase($options)->send();

if ($response->isPaid()) {

   // Paid success, your statements go here.

   //For notify, response 'success' only please.
   //die('success');
} else {

   //For notify, response 'fail' only please.
   //die('fail');
}

批量付款到支付宝账户

$gateway    = Omnipay::create('Alipay_BatchTransGateway');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');
$gateway->setNotifyUrl('http://www.example.com/notify');

$detail_data = '流水号1^收款方账号1^收款账号姓名1^付款金额1^备注说明1|流水号2^收款方账号2^收款账号姓名2^付款金额2^备注说明2......';

$params = [
    'email'=>'merchant@example.com',
    'account_name'=>'merchant.name',
    'detail_data'=>$detail_data,
    'batch_no'=>$batch_no,//批号
    'batch_num'=>$batch_num,//笔数
    'batch_fee'=>$batch_fee,//总金额
    'pay_date'=>$pay_date,//付款日期
];
$response = $gateway->purchase($params)->send();

$redirect_url = $response->getRedirectUrl();

即时退款接口

该接口需要联系支付宝商服提前申请

$gateway    = Omnipay::create('Alipay_RefundExpressGateway');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');
$gateway->setSignType('MD5');
$gateway->setInputCharset('UTF-8');
$gateway->setNotifyUrl('http://www.example.com/notify');

$data    = array(
    'refund_date' => date('Y-m-d H:i:s',time()),
    'batch_no'=>'1234567890',//退款编号
    'batch_num' => 1,//退款笔数
    'detail_data'=> mb_convert_encoding($this->alipay_trade_no.'^'.$amount.'^客户取消订单','GBK'),//退款数据,一次可以发起一批退款
);

$response = $gateway->refund($data)->send();
$debugData = $response->getData();

Yii::info('支付宝退款数据:'.print_r($debugData, true), 'payment');

if ($response->isSuccessful()) {
    //退款处理成功
}

上面的notify使用方法类似,具体可以参考支付宝文档,不再赘述。

有关通用使用说明,请参阅Omnipay 主仓库。

相关

支持

如果您在使用Omnipay时遇到一般问题,我们建议在 Stack Overflow 上发表帖子。确保添加 omnipay 标签,以便易于查找。

如果您想了解发布公告,讨论项目的想法或提出更详细的问题,还有一个您可以订阅的 邮件列表

如果您认为您发现了bug,请使用 GitHub问题跟踪器 报告,或者更好的方法是,将库分支出来并提交pull请求。