Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11 #17

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@
}
],
"require": {
"php": "^8.1",
"laravel/framework": "^9.0 || ^10.0",
"spatie/laravel-data": "^3.5",
"spatie/laravel-package-tools": "^1.14.0"
"php": "^8.2",
"laravel/framework": "^10.0|^11.0",
"spatie/laravel-data": "^4.0",
"spatie/laravel-package-tools": "^1.16.2"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.9",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.0",
"nunomaduro/collision": "^7.0|^8.0",
"larastan/larastan": "^2.0.1",
"orchestra/testbench": "^9.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0"
"pestphp/pest-plugin-laravel": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/HasExternalProductItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface HasExternalProductItem
{
public function toExternalProductItem(): ExternalProductItem;
public function toExternalProductItem(): ?ExternalProductItem;
public function externalProductItemRelationship(): string;
public function setAsCompleted(): bool;
public function setAsExternallyPaid(): bool;
Expand Down
2 changes: 2 additions & 0 deletions src/DTO/ExternalProductItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public function __construct(

public float $price_incl_vat,
public bool $is_paid,

public ?string $redirect_url = null,
) {}
}
11 changes: 10 additions & 1 deletion src/Helpers/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@

class UrlHelper
{
static public function redirectToCashRegister(Model&HasExternalProductItem ...$models)
static public function redirectToCashRegister(Model&HasExternalProductItem ...$models): string
{
$items = collect($models)
->map(fn(Model $model) => ['type' => $model::class, 'id' => $model->getKey()])
->all();

return route('cashregister.redirect', ['items' => $items]);
}

static public function redirectToCashRegisterAndBack(string $redirectUrl, Model&HasExternalProductItem ...$models): string
{
$items = collect($models)
->map(fn(Model $model) => ['type' => $model::class, 'id' => $model->getKey()])
->all();

return route('cashregister.redirect', ['items' => $items, 'redirect_url' => $redirectUrl]);
}
}
5 changes: 3 additions & 2 deletions src/Http/Controllers/CashRegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ public function redirectToCashRegister(RedirectToCashRegisterRequest $request)
'product_type',
'product_id',
'type',
'id'
'id',
))
->toArray();


$query = http_build_query(['items' => $data]);
$queryData = array_filter(['items' => $data, 'redirect_url' => $request->validated('redirect_url')]);
$query = http_build_query($queryData);

$hash = hash_hmac('sha256', $query, config('cashregister-bridge.secret'));

Expand Down
1 change: 1 addition & 0 deletions src/Http/Requests/RedirectToCashRegisterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function rules()
'items' => 'required|array',
'items.*.type' => 'required',
'items.*.id' => 'required|numeric|min:1',
'redirect_url' => 'nullable|string|url',
];
}
}
8 changes: 7 additions & 1 deletion src/Jobs/PushExternalProductItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ public function handle()
return;
}

$externalProductItem = $this->externalProductItem->toExternalProductItem();

if( is_null($externalProductItem)) {
return;
}

Http::acceptJson()->withSignature(config('cashregister-bridge.secret'))->post(
$url,
$this->externalProductItem->toExternalProductItem()->toArray(),
$externalProductItem->toArray(),
)->throw();
}
}