denisneuf/ thinkphp-paypal-api
ThinkPHP 用于使用 PayPal Rest API 的包装器
v0.0.4
2023-03-27 01:56 UTC
Requires
- php: >=7.2.5
- ext-curl: *
README
ThinkPHP Paypal Api
一个库,用于支持来自ThinkPHP框架的 PayPal Rest API。
安装
首先安装你的 ThinkPHP 项目
ThinkPHP6.1 的运行环境需要 PHP7.2.5+,最大兼容到 PHP8.2
使用 Composer 安装 ThinkPHP
composer create-project topthink/think tp
初始化服务
cd tp
php think run
你可以在浏览器中访问它
https://:8000
如果需要更新框架
composer update topthink/framework
需要安装 THINKPHP-PAYPAL-API
composer require denisneuf/thinkphp-paypal-api
运行更新来安装包
composer update
在控制器中使用它
<?php declare (strict_types = 1); namespace app\controller; use app\BaseController; use think\facade\Env; use think\facade\View; use think\Request; use think\Log; use PayPalSdk\Core\PayPalClient; use PayPalSdk\disputes\DisputesGetRequest; use PayPalHttp\HttpException; class YourController extends BaseController { /** * 显示资源列表 * * @return \think\Response */ public function index(Log $log) { $request = new DisputesGetRequest(); try{ $client = PayPalClient::client(); $response = $client->execute($request); } catch(HttpException $exception){ $message = json_decode($exception->getMessage(), true); dump($message); exit; } finally { $log->info(gettype($response->result->items)); } View::assign('title','View Disputes'); View::assign('lang', Env::get('lang.default_lang')); View::assign('description','View Disputes'); View::assign('list', $response->result->items); return View::fetch('admin/list/dispute'); } }
设置
创建或编辑你的 .env 文件,并将其放置在 thinkphp 项目的根目录下(沙盒或生产环境)
# environment variables defined inside a .env file
[PAYPAL]
#SandBox LeadTech
client_id = "your-client-id-sandbox"
client_secret = "your-client-secret-sandbox"
#Production LeadTech
#client_id = "your-client-id-production"
#client_secret = "your-client-secret-production"
#client_environment = "PRODUCTION"
ThinkPHP 集成
这个库使用 ThinkPHP 框架的 Cache 和 Env。
use think\facade\Cache;
将令牌存储在 ThinkPHP Cache 中
use think\facade\Env;
从 ThinkPHP Env 获取凭证
use \think\facade\Filesystem; To upload files from ThinkPHP Filesystem
免责声明
此包基于 paypal/paypal-checkout-sdk,所有者已于 2022 年 7 月 21 日存档。现在为只读。
我们与 PayPal 没有联系。