daygarcia / laravel-vtex
一个用于连接 VTEX API 的 Laravel 扩展包
dev-main
2023-03-24 12:38 UTC
This package is auto-updated.
Last update: 2024-09-24 15:47:46 UTC
README
用于连接 VTEX API 的包
要求
PHP 8 及以上版本
安装与使用
Composer
通过 Composer 安装
composer require daygarcia/laravel-vtex
配置
Configuration
构造函数接受一个参数:一个包含连接到 VTEX API 所需所有配置的数组
<?php // Still under development use Illuminate\Http\Request; use LaravelVtex\Configuration; ... $config = new Configuration([ 'app_token' => config('vtex.app_token'), 'app_key' => config('vtex.app_key'), 'store_name' => config('vtex.store_name') ]);
为 Configuration
类提供了获取和设置方法。您可以直接获取和设置 app_token
、app_key
和 store_name
示例
<?php use LaravelVtex\Configuration; use LaravelVtex\Api\PromotionApi; ... public function index(Request $request) { $config = new Configuration([ 'app_token' => config('vtex.app_token'), 'app_key' => config('vtex.app_key'), 'store_name' => config('vtex.store_name') ]); try { $vtex = new PromotionAndTaxesApi($config); $response = $vtex->getAllPromotions(); return $this->success($response); } catch (Exception $e) { return $this->error($e->getMessage(), $e->getCode()); } }
文档与重要说明
不要忘记查看 VTEX 开发者网站 开发者网站
待办事项
- 改进错误处理