Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/spatie/spatie.be into blog-…
Browse files Browse the repository at this point in the history
…statamic

# Conflicts:
#	composer.lock
  • Loading branch information
riasvdv committed Oct 4, 2024
2 parents de13991 + cdbf55e commit 1ceff5e
Show file tree
Hide file tree
Showing 12 changed files with 1,759 additions and 1,541 deletions.
2 changes: 2 additions & 0 deletions app/Domain/Shop/Actions/HandlePurchaseLicensingAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Domain\Shop\Actions;

use App\Domain\Shop\Exceptions\CouldNotRenewLicenseForPurchase;
use App\Domain\Shop\Models\License;
use App\Domain\Shop\Models\Purchasable;
use App\Domain\Shop\Models\Purchase;
use App\Domain\Shop\Models\PurchaseAssignment;
Expand Down Expand Up @@ -61,6 +62,7 @@ protected function handleRenewal(PurchaseAssignment $assignment): void
if (! $license) {
$product = $assignment->purchasable->originalPurchasable->product;

/** @var License|null $license */
$license = $assignment->user
->licenses()
->forProduct($product)
Expand Down
3 changes: 3 additions & 0 deletions app/Filament/Resources/Customers/ReceiptResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public static function form(Form $form): Form
->columnStart(1),
TextInput::make('currency')
->columnStart(1),
TextInput::make('billable_type')
->readOnly()
->columnStart(1),
]),
]);
}
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace App\Http\Controllers;

use App\Models\User;
use App\Support\Paddle\ProcessPaymentSucceededJob;
use Illuminate\Database\Eloquent\Relations\Relation;
use Laravel\Paddle\Exceptions\InvalidPassthroughPayload;
use Laravel\Paddle\Http\Controllers\WebhookController as CashierWebhookController;

class WebhookController extends CashierWebhookController
Expand All @@ -18,4 +21,18 @@ public function handlePaymentSucceeded($payload): void

dispatch(new ProcessPaymentSucceededJob($payload));
}

protected function findOrCreateCustomer(string $passthrough)
{
$passthroughData = json_decode($passthrough, true);

$morphAlias = Relation::getMorphAlias(User::class);

// The passthrough data comes from the shop front-end. We cannot trust it.
if (! is_array($passthroughData) || $passthroughData['billable_type'] !== $morphAlias) {
throw new InvalidPassthroughPayload();
}

return parent::findOrCreateCustomer($passthrough);
}
}
62 changes: 54 additions & 8 deletions app/Livewire/RepositoriesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Livewire;

use App\Models\Repository;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed;
use Livewire\Component;

class RepositoriesComponent extends Component
Expand All @@ -21,29 +24,72 @@ class RepositoriesComponent extends Component

protected $queryString = ['search', 'sort'];

public Collection $repositories;

public function mount(
$type = 'packages',
$filterable = true,
$sort = '-downloads'
$sort = '-downloads',
): void {
$this->type = $type;
$this->filterable = $filterable;
$this->sort = request()->query('sort', $sort);
$this->search = request()->query('search', '');
$this->repositories = collect();
$this->loadRepositories();
}

private function getRepositories(): Collection
private function loadRepositories(bool $loadingMore = false): void
{
return Repository::visible()
Repository::query()
->visible()
->when(
$loadingMore,
fn (Builder $query) => $query->offset($this->repositories->count()),
)
->search($this->search)
->applySort($this->sort)
->get();
->limit(9)
->get()
->each(function (Repository $repository) {
$this->repositories->push($repository);
});
}

public function updatedSearch(): void
{
$this->repositories = collect();
$this->loadRepositories();
}

public function updatedSort(): void
{
$this->repositories = collect();
$this->loadRepositories();
}

public function loadMore(): void
{
$this->loadRepositories(loadingMore: true);
}

#[Computed]
public function total(): int
{
return Repository::query()
->visible()
->search($this->search)
->count();
}

#[Computed]
public function hasMore(): bool
{
return $this->repositories->count() < $this->total;
}

public function render()
public function render(): View
{
return view('front.livewire.repositories', [
'repositories' => $this->getRepositories(),
]);
return view('front.livewire.repositories');
}
}
5 changes: 1 addition & 4 deletions app/Support/Paddle/ProcessPaymentSucceededJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Support\Paddle;

use App\Domain\Shop\Actions\HandlePurchaseAction;
use App\Domain\Shop\Exceptions\CouldNotHandlePaymentSucceeded;
use App\Domain\Shop\Models\Bundle;
use App\Domain\Shop\Models\Purchasable;
use App\Domain\Shop\Models\Purchase;
Expand Down Expand Up @@ -50,9 +49,7 @@ public function handle()
return;
}

if (! $user = (new $passthrough['billable_type']())->find($passthrough['billable_id'])) {
throw CouldNotHandlePaymentSucceeded::userNotFound($this->payload);
}
$user = $receipt->billable;

if ($purchasable) {
$purchaseForPurchasable = Purchase::where('user_id', $user->id)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"laravel/envoy": "^2.9",
"mockery/mockery": "^1.5.1",
"nunomaduro/collision": "^8.1",
"nunomaduro/larastan": "^2.4",
"larastan/larastan": "^2.4",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.2",
Expand Down
Loading

0 comments on commit 1ceff5e

Please sign in to comment.