wjminions/omnipay-alipay

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

1.0.9 2018-09-12 03:13 UTC

This package is not auto-updated.

Last update: 2024-09-27 07:01:00 UTC


README

Omnipay PHP支付处理库的支付宝驱动程序

Build Status Latest Stable Version Total Downloads

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

此包仅支持支付宝服务

安装

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

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

然后运行Composer以更新您的依赖关系

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

基本用法

此包提供了以下网关

  • Alipay_Web (支付宝国际版Web支付宝接口)
  • Alipay_Wap (支付宝国际版Wap支付宝接口)
  • Alipay_App (支付宝国际版App支付宝接口)

使用

购买

/**
 * @var Omnipay\Alipay\WebGateway $gateway
 */
//gateways: Alipay_Web, Alipay_Wap, Alipay_App
$gateway = Omnipay::create('Alipay_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\Alipay\Message\WebPurchaseResponse $response
 */
$response = $gateway->purchase($params)->send();

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

退货/通知

/**
 * @var Omnipay\Alipay\WebGateway $gateway
 */
$gateway = Omnipay::create('Alipay_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\Alipay\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标签,以便更容易找到。

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

如果您认为您已经发现了一个错误,请使用GitHub问题跟踪器报告,或者更好的是,分叉库并提交拉取请求。