jeffgreco13/laravel-wave

用于在 Laravel 应用中使用 Wave GraphQL API 的包装器。

安装: 25

依赖: 1

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 10

类型:项目

v0.3.1 2023-11-25 21:00 UTC

This package is auto-updated.

Last update: 2024-08-25 22:26:10 UTC


README

在您的 Laravel 应用中使用 Wave 的 graphql api 的包装器。此包是从 subbe/waveapp 分支出来的,并为 Laravel 开发者添加了一些 QOL 改进。

Wave API 文档可以在以下位置找到:

应用设置

要使用 Laravel Wave,您需要在开发者门户上 创建一个应用

创建新应用后,点击编辑其设置。创建一个新的完全访问令牌并将其复制到安全的地方。您需要在 .env 中使用它。

此包不支持 OAuth 流。考虑使用 Socialite Wave Provider 然后在运行时将访问令牌传递给 Wave 类。

安装

使用 composer 需求此包

composer require jeffgreco13/laravel-wave

更新您的 .env 文件以包含

WAVE_ACCESS_TOKEN= *your full access token*
WAVE_BUSINESS_ID= *ID for the business you wish to interact with*
WAVE_GRAPHQL_URI= *defaults to https://gql.waveapps.com/graphql/public*

如果您不知道您企业的 ID,可以使用以下 tinker 命令

php artisan tinker
> (new \Jeffgreco13\Wave\Wave())->businesses()

用法

货币

一种简单的下载 Wave 货币并将其缓存以供应用程序使用的方法

首先运行 artisan 命令。这将下载静态货币到 json 文件并在您的存储路径中保存

php artisan wave:pull-currencies

现在您可以像这样使用 Currency 类

use Jeffgreco13\Wave\Currency;

$currencies = Currency::all(); // returns a Collection of Currency objects

$currency = Currency::firstWhere('code','ARS'); // returns a single Currency object if found, or null
echo $currency->name; // output: Argentinian peso

// Currency array attributes
array:5 [
  "code" => "ARS"
  "symbol" => "$"
  "name" => "Argentinian peso"
  "plural" => "Argentinian pesos"
  "exponent" => 2
]

所有查询

  • 用户
  • 国家
  • 国家
  • 企业
  • 企业
  • 货币
  • 货币
  • 账户类型
  • 账户子类型
  • customerExists
  • 客户
  • 产品
  • 税收

所有突变

  • customerCreate

  • customerPatch

  • customerDelete

  • accountCreate

  • accountPatch

  • accountArchive

  • productCreate

  • productPatch

  • productArchive

  • salesTaxCreate

  • salesTaxPatch

  • salesTaxArchive

  • salesTaxRateCreate

  • moneyTransactionCreate

  • invoiceCreate

  • invoiceClone

  • invoiceDelete

  • invoiceSend

  • invoiceApprove

  • invoiceMarkSent

用法

查询

$wave = new \Jeffgreco13\Wave\Wave();
$businesses = $wave->businesses();

或,使用参数...

$wave = new \Jeffgreco13\Wave\Wave();
$country = $wave->country(['code' => 'US']);

分页

businessescustomers 之类的查询可能需要分页。您可以轻松构建自己的循环并递增 'page' 输入,或者您可以使用此快捷方式

$wave = new Wave();
$response = $wave->customers(['pageSize'=>20]);
do {
    foreach ($wave->getNodes() as $node) {
        echo "Hello, {$node->firstName}!";
    }
} while($response = $wave->paginate());

突变

$wave = new \Jeffgreco13\Wave\Wave();
$customer = [
    "input" => [
        "businessId" => null, // Optional. Will use the businessId from your config/env by default
        "name" => "Genevieve Heidenreich",
        "firstName" => "Genevieve",
        "lastName" => "Heidenreich",
        "displayId" => "Genevieve",
        "email" => "genevieve.heidenreich@example.com",
        "mobile" => "011 8795",
        "phone" => "330 8738",
        "fax" => "566 5965",
        "tollFree" => "266 5698",
        "website" => "http://www.hermiston.com/architecto-commodi-possimus-esse-non-necessitatibus",
        "internalNotes" => "",
        "currency" => "USD",
        "address" => [
            "addressLine1" => "167 Iva Run",
            "addressLine2" => "Parker Mews, Monahanstad, 40778-7100",
            "city" => "West Tyrique",
            "postalCode" => "82271",
            "countryCode" => "EC",
       ],
       "shippingDetails" => [
            "name" => "Genevieve",
            "phone" => "011 8795",
            "instructions" => [
                "Delectus deleniti accusamus rerum voluptatem tempora.",
            ],
            "address" => [
                "addressLine1" => "167 Iva Run",
                "addressLine2" => "Parker Mews, Monahanstad, 40778-7100",
                "city" => "West Tyrique",
                "postalCode" => "82271",
                "countryCode" => "EC",
            ],
        ],
    ],
];

$newCustomer = $wave->customerCreate($customer);

贡献

欢迎拉取请求。对于重大更改,请首先打开一个问题来讨论您想要更改的内容。

许可

MIT