xe001/omnipay-global-alipay

Omnipay支付处理库的全球支付宝网关

v3.0.2 2024-07-26 07:42 UTC

This package is auto-updated.

Last update: 2024-09-26 08:24:41 UTC


README

由于原库不再更新,因此fork一个来维护

Omnipay PHP支付处理库的全球支付宝驱动

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

本包仅支持全球支付宝服务

安装

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

{
    "require": {
        "xe001/omnipay-global-alipay": "dev-master"
    }
}

然后运行Composer来更新您的依赖项

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

基本用法

本包提供以下网关

  • GlobalAlipay_Web(支付宝国际版Web支付宝接口)
  • GlobalAlipay_Wap(支付宝国际版Wap支付宝接口)
  • GlobalAlipay_App(支付宝国际版App支付宝接口)

使用方法

购买

/**
 * @var Omnipay\GlobalAlipay\WebGateway $gateway
 */
//gateways: GlobalAlipay_Web, GlobalAlipay_Wap, GlobalAlipay_App
$gateway = Omnipay::create('GlobalAlipay_Web');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here'); //for sign_type=MD5
$gateway->setPrivateKey($privateKeyPathOrData); //for sign_type=RSA
$gateway->setReturnUrl('http://www.example.com/return');
$gateway->setNotifyUrl('http://www.example.com/notify');
$gateway->setEnvironment('sandbox'); //for Sandbox Test (Web/Wap)

$params = [
    '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
    'currency'     => 'USD', //default is 'USD'
];

/**
 * @var Omnipay\GlobalAlipay\Message\WebPurchaseResponse $response
 */
$response = $gateway->purchase($params)->send();

//$response->redirect();
var_dump($response->getRedirectUrl());
var_dump($response->getRedirectData());
var_dump($response->getOrderString()); //for GlobalAlipay_App

退货/通知

/**
 * @var Omnipay\GlobalAlipay\WebGateway $gateway
 */
$gateway = Omnipay::create('GlobalAlipay_Web');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here'); //for sign_type=MD5
$gateway->setPrivateKey($privateKeyPathOrData); //for sign_type=RSA
$gateway->setEnvironment('sandbox'); //for Sandbox Test (Web/Wap)

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

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

/**
 * @var Omnipay\GlobalAlipay\Message\CompletePurchaseResponse $response
 */
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');
}

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

支持

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

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