Skip to content

Commit

Permalink
Merge pull request #121 from lmsqueezy/pre-release
Browse files Browse the repository at this point in the history
Pre release
  • Loading branch information
JustSteveKing authored Feb 13, 2025
2 parents c877e18 + 312a986 commit 836edac
Show file tree
Hide file tree
Showing 37 changed files with 147 additions and 100 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: juststeveking
41 changes: 35 additions & 6 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
name: coding standards
name: fix code styling

on: [push]

permissions:
contents: write
on:
workflow_call:
inputs:
php:
default: "8.2"
type: string
message:
default: Fix code styling
type: string
fix:
default: true
type: boolean

jobs:
lint:
uses: laravel/.github/.github/workflows/coding-standards.yml@main
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php }}
tools: composer:v2, laravel/pint
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Run Pint
run: pint

- name: Commit linted files
if: ${{ inputs.fix }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ${{ inputs.message }}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"nesbot/carbon": "^2.0|^3.0"
},
"require-dev": {
"laravel/pint": "^1.20",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^2.0|^3.0",
"phpstan/phpstan": "^2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
public function up(): void
{
Schema::create('lemon_squeezy_customers', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
public function up(): void
{
Schema::create('lemon_squeezy_subscriptions', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
public function up(): void
{
Schema::create('lemon_squeezy_orders', function (Blueprint $table) {
Expand Down
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "per"
}
8 changes: 4 additions & 4 deletions src/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public function withCustomData(array $custom): self
}

$this->custom = collect(array_replace_recursive($this->custom, $custom))
->map(fn ($value) => is_string($value) ? trim($value) : $value)
->filter(fn ($value) => ! is_null($value))
->map(fn($value) => is_string($value) ? trim($value) : $value)
->filter(fn($value) => ! is_null($value))
->toArray();

return $this;
Expand Down Expand Up @@ -211,8 +211,8 @@ public function url(): string
'attributes' => [
'custom_price' => $this->customPrice,
'checkout_data' => array_merge(
array_filter($this->checkoutData, fn ($value) => $value !== ''),
['custom' => $this->custom]
array_filter($this->checkoutData, fn($value) => $value !== ''),
['custom' => $this->custom],
),
'checkout_options' => array_filter([
'embed' => $this->embed,
Expand Down
10 changes: 5 additions & 5 deletions src/Console/ListLicensesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function handle(): int
return static::FAILURE;
}

$storeResponse = spin(fn () => $this->fetchStore(), '🍋 Fetching store information...');
$storeResponse = spin(fn() => $this->fetchStore(), '🍋 Fetching store information...');
$store = $storeResponse->json('data.attributes');

return $this->handleLicenses($store);
Expand All @@ -52,7 +52,7 @@ protected function validate(): bool
$arr = array_merge(
config('lemon-squeezy'),
['page' => $this->option('page')],
['size' => $this->option('size')]
['size' => $this->option('size')],
);
$validator = Validator::make($arr, [
'api_key' => [
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function fetchStore(): Response
protected function handleLicenses(array $store): int
{
$licensesResponse = spin(
fn () => LemonSqueezy::api(
fn() => LemonSqueezy::api(
'GET',
sprintf('license-keys'),
[
Expand All @@ -103,7 +103,7 @@ protected function handleLicenses(array $store): int
'filter[product_id]' => $this->argument('product'),
'filter[order_id]' => $this->option('order'),
'filter[status]' => $this->option('status'),
]
],
),
'🍋 Fetching licenses...',
);
Expand Down Expand Up @@ -163,7 +163,7 @@ protected function displayLicense(array $license, bool $long): void

$this->components->twoColumnDetail(
sprintf('<fg=green;options=bold>%s</>', $key),
$this->displayStatus($license)
$this->displayStatus($license),
);
$this->displayProductInfo($license);
$this->displayCustomer($license);
Expand Down
28 changes: 14 additions & 14 deletions src/Console/ListProductsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle(): int
return static::FAILURE;
}

$storeResponse = spin(fn () => $this->fetchStore(), '🍋 Fetching store information...');
$storeResponse = spin(fn() => $this->fetchStore(), '🍋 Fetching store information...');
$store = $storeResponse->json('data.attributes');

$productId = $this->argument('product');
Expand Down Expand Up @@ -82,12 +82,12 @@ protected function fetchStore(): Response
protected function handleProduct(array $store, string $productId): int
{
$response = spin(
fn () => LemonSqueezy::api(
fn() => LemonSqueezy::api(
'GET',
sprintf('products/%s', $productId),
['include' => 'variants']
['include' => 'variants'],
),
'🍋 Fetching product information...'
'🍋 Fetching product information...',
);

$product = $response->json('data');
Expand All @@ -99,13 +99,13 @@ protected function handleProduct(array $store, string $productId): int
$this->displayProduct($product);

$variants = collect($response->json('included'))
->filter(fn ($item) => $item['type'] === 'variants')
->filter(fn($item) => $item['type'] === 'variants')
->sortBy('sort');

$variants->each(fn (array $variant) => $this->displayVariant(
$variants->each(fn(array $variant) => $this->displayVariant(
$variant,
Arr::get($store, 'currency'),
$variants->count() > 1
$variants->count() > 1,
));

$this->newLine();
Expand All @@ -116,14 +116,14 @@ protected function handleProduct(array $store, string $productId): int
protected function handleProducts(array $store): int
{
$productsResponse = spin(
fn () => LemonSqueezy::api(
fn() => LemonSqueezy::api(
'GET',
'products',
[
'include' => 'variants',
'filter[store_id]' => config('lemon-squeezy.store'),
'page[size]' => 100,
]
],
),
'🍋 Fetching products information...',
);
Expand All @@ -139,14 +139,14 @@ protected function handleProducts(array $store): int

$variantIds = collect(Arr::get($product, 'relationships.variants.data'))->pluck('id');
$variants = collect($productsResponse->json('included'))
->filter(fn ($item) => $item['type'] === 'variants')
->filter(fn ($item) => $variantIds->contains($item['id']))
->filter(fn($item) => $item['type'] === 'variants')
->filter(fn($item) => $variantIds->contains($item['id']))
->sortBy('sort');

$variants->each(fn ($variant) => $this->displayVariant(
$variants->each(fn($variant) => $this->displayVariant(
$variant,
Arr::get($store, 'currency'),
$variants->count() > 1
$variants->count() > 1,
));

$this->newLine();
Expand All @@ -164,7 +164,7 @@ protected function displayProduct(array $product): void
{
$this->components->twoColumnDetail(
sprintf('<fg=green;options=bold>%s</>', Arr::get($product, 'attributes.name')),
Arr::get($product, 'id')
Arr::get($product, 'id'),
);
}

Expand Down
20 changes: 10 additions & 10 deletions src/Console/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,24 @@ protected function handleCleanup(): ?int

protected function handleService(): int
{
note('Setting up webhooks domain with '.$this->argument('service').'...');
note('Setting up webhooks domain with ' . $this->argument('service') . '...');

$this->trap([SIGINT], fn (int $signal) => $this->teardownWebhook());
$this->trap([SIGINT], fn(int $signal) => $this->teardownWebhook());

return $this->{$this->argument('service')}();
}

protected function promptForMissingArgumentsUsing(): array
{
return [
'service' => fn () => select(
'service' => fn() => select(
label: 'Please choose a service',
options: [
'expose',
'ngrok',
],
default: 'expose',
validate: fn ($val) => in_array($val, ['expose', 'ngrok'])
validate: fn($val) => in_array($val, ['expose', 'ngrok'])
? null
: 'Please choose a valid service.',
),
Expand All @@ -174,7 +174,7 @@ protected function cleanOutput($output): string
if (preg_match(
'/Remaining time:\s+\d{2}:\d{2}:\d{2}\\n/',
$output,
$matches
$matches,
)) {
$output = preg_replace('/Remaining time:\s+\d{2}:\d{2}:\d{2}\\n/', '', $output);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function expose(): int
if (is_null($tunnel) && preg_match(
'/Public HTTPS:\s+(http[s]?:\/\/[^\s]+)/',
$this->process->latestOutput(),
$matches
$matches,
)) {
$tunnel = $matches[1];

Expand Down Expand Up @@ -310,7 +310,7 @@ protected function setupWebhook(string $tunnel): ?int
'data' => [
'type' => 'webhooks',
'attributes' => [
'url' => $tunnel.'/'.config('lemon-squeezy.path').'/webhook',
'url' => $tunnel . '/' . config('lemon-squeezy.path') . '/webhook',
'events' => [
'order_created',
'order_refunded',
Expand Down Expand Up @@ -344,7 +344,7 @@ protected function setupWebhook(string $tunnel): ?int

$result = Http::withToken(config('lemon-squeezy.api_key'))
->retry(3, 250)
->post(LemonSqueezy::API.'/webhooks', $data);
->post(LemonSqueezy::API . '/webhooks', $data);

if ($result->status() !== 201) {
error('Failed to setup webhook.');
Expand Down Expand Up @@ -384,7 +384,7 @@ protected function cleanupWebhooks(): int
return collect($this->fetchWebhooks())
->filter(function ($url, $id) {
collect($this->services[$this->argument('service')]['domain'])
->reduce(fn ($carry, $domain) => $carry || Str::endsWith($url, $domain), false);
->reduce(fn($carry, $domain) => $carry || Str::endsWith($url, $domain), false);
})
->each(function ($url, $id) {
$this->deleteWebhook($id)->status() === 204
Expand Down Expand Up @@ -431,6 +431,6 @@ protected function deleteWebhook(int $webhookId): Response
{
return Http::withToken(config('lemon-squeezy.api_key'))
->retry(3, 250)
->delete(LemonSqueezy::API."/webhooks/{$webhookId}");
->delete(LemonSqueezy::API . "/webhooks/{$webhookId}");
}
}
3 changes: 2 additions & 1 deletion src/Events/LicenseKeyCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class LicenseKeyCreated
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
3 changes: 2 additions & 1 deletion src/Events/LicenseKeyUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class LicenseKeyUpdated
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
3 changes: 2 additions & 1 deletion src/Events/OrderCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class OrderCreated
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
3 changes: 2 additions & 1 deletion src/Events/OrderRefunded.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class OrderRefunded
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
3 changes: 2 additions & 1 deletion src/Events/SubscriptionCancelled.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class SubscriptionCancelled
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
3 changes: 2 additions & 1 deletion src/Events/SubscriptionCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class SubscriptionCreated
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
3 changes: 2 additions & 1 deletion src/Events/SubscriptionExpired.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class SubscriptionExpired
{
use Dispatchable, SerializesModels;
use Dispatchable;
use SerializesModels;

/**
* The billable entity.
Expand Down
Loading

0 comments on commit 836edac

Please # to comment.