Skip to content

Commit

Permalink
NEXT-30813 - Checkout gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
lernhart committed May 14, 2024
1 parent 9be7711 commit 2090cba
Show file tree
Hide file tree
Showing 66 changed files with 1,287 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/infection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
run: composer update --no-ansi --no-interaction --no-progress

- name: Infection PHP
run: vendor/bin/infection --min-msi=90 --min-covered-msi=95 --threads=4
run: vendor/bin/infection --min-covered-msi=95 --threads=4
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"cuyz/valinor": "^1.12",
"lcobucci/jwt": "^4.0 || ^5.0",
"lcobucci/clock": "^3",
"php-http/discovery": "^1.17",
"psr/clock-implementation": "*",
"psr/event-dispatcher": "^1.0",
"psr/http-client": "^1.0",
"psr/http-client-implementation": "*",
"psr/http-factory": "^1.0",
"psr/http-factory-implementation": "*",
"psr/http-message": "^1.0 || ^2.0",
"psr/simple-cache": "^3.0",
"psr/clock-implementation": "*"
"psr/simple-cache": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16",
Expand Down
2 changes: 2 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
{
languages.php.enable = true;
languages.php.extensions = [ "xdebug" ];

processes = {};
}
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
Expand Down
4 changes: 2 additions & 2 deletions src/Authentication/RequestVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ public function authenticateStorefrontRequest(RequestInterface $request, ShopInt
*/
private function getSignatureFromQuery(RequestInterface $request): string
{
parse_str($request->getUri()->getQuery(), $queries);
\parse_str($request->getUri()->getQuery(), $queries);

if (!isset($queries[self::SHOPWARE_SHOP_SIGNATURE_HEADER])) {
throw new SignatureNotFoundException($request);
}

$header = $queries[self::SHOPWARE_SHOP_SIGNATURE_HEADER];

if (!is_string($header)) {
if (!\is_string($header)) {
/** @infection-ignore-all */
throw new SignatureNotFoundException($request);
}
Expand Down
31 changes: 17 additions & 14 deletions src/Context/Cart/CalculatedPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Shopware\App\SDK\Context\Cart;

use Shopware\App\SDK\Context\ArrayStruct;
use Shopware\App\SDK\Framework\Collection;

class CalculatedPrice extends ArrayStruct
{
Expand All @@ -27,38 +28,40 @@ public function getQuantity(): int
}

/**
* @return array<CalculatedTax>
* @return Collection<CalculatedTax>
*/
public function getCalculatedTaxes(): array
public function getCalculatedTaxes(): Collection

Check failure on line 33 in src/Context/Cart/CalculatedPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Method Shopware\App\SDK\Context\Cart\CalculatedPrice::getCalculatedTaxes() has invalid return type Shopware\App\SDK\Context\Cart\CalculatedTax.
{
\assert(is_array($this->data['calculatedTaxes']));
return array_map(static function (array $calculatedTax): CalculatedTax {

return new Collection(\array_map(static function (array $calculatedTax): CalculatedTax {

Check failure on line 37 in src/Context/Cart/CalculatedPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Anonymous function has invalid return type Shopware\App\SDK\Context\Cart\CalculatedTax.
return new CalculatedTax($calculatedTax);

Check failure on line 38 in src/Context/Cart/CalculatedPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Instantiated class Shopware\App\SDK\Context\Cart\CalculatedTax not found.
}, $this->data['calculatedTaxes']);
}, $this->data['calculatedTaxes']));
}

/**
* @return array<TaxRule>
* @return Collection<TaxRule>
*/
public function getTaxRules(): array
public function getTaxRules(): Collection
{
\assert(is_array($this->data['taxRules']));
return array_map(static function (array $taxRule): TaxRule {

return new Collection(\array_map(static function (array $taxRule): TaxRule {
return new TaxRule($taxRule);
}, $this->data['taxRules']);
}, $this->data['taxRules']));
}

/**
* @param array<CalculatedPrice> $prices
* @param Collection<CalculatedPrice> $prices
*/
public static function sum(array $prices): CalculatedPrice
public static function sum(Collection $prices): CalculatedPrice
{
return new CalculatedPrice([
'unitPrice' => array_sum(array_map(static fn (CalculatedPrice $price): float => $price->getUnitPrice(), $prices)),
'totalPrice' => array_sum(array_map(static fn (CalculatedPrice $price): float => $price->getTotalPrice(), $prices)),
'unitPrice' => \array_sum($prices->map(static fn (CalculatedPrice $price): float => $price->getUnitPrice())),
'totalPrice' => \array_sum($prices->map(static fn (CalculatedPrice $price): float => $price->getTotalPrice())),
'quantity' => 1,
'calculatedTaxes' => array_map(static fn (CalculatedTax $tax) => $tax->toArray(), CalculatedTax::sum(array_merge(...array_map(static fn (CalculatedPrice $price): array => $price->getCalculatedTaxes(), $prices)))),
'taxRules' => array_map(static fn (TaxRule $rule) => $rule->toArray(), array_merge(...array_map(static fn (CalculatedPrice $price): array => $price->getTaxRules(), $prices))),
'calculatedTaxes' => $prices->map(static fn (CalculatedPrice $price) => CalculatedTax::sum($price->getCalculatedTaxes())),

Check failure on line 63 in src/Context/Cart/CalculatedPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Call to static method sum() on an unknown class Shopware\App\SDK\Context\Cart\CalculatedTax.
'taxRules' => $prices->map(static fn (CalculatedPrice $price) => $price->getTaxRules()),
]);
}
}
32 changes: 19 additions & 13 deletions src/Context/Cart/CalculatedTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Shopware\App\SDK\Context\Cart;

use Shopware\App\SDK\Context\ArrayStruct;
use Shopware\App\SDK\Framework\Collection;

class CalculatedTax extends ArrayStruct
{
Expand All @@ -27,28 +28,33 @@ public function getTax(): float
}

/**
* @param array<CalculatedTax> $calculatedTaxes
* @return array<CalculatedTax>
* @param Collection<CalculatedTax> $calculatedTaxes
* @return array<array-key, CalculatedTax>
*/
public static function sum(array $calculatedTaxes): array
public static function sum(Collection $calculatedTaxes): array
{
$new = [];
$new = new Collection();

foreach ($calculatedTaxes as $calculatedTax) {
$exists = isset($new[$calculatedTax->getTaxRate()]);
if (!$exists) {
$new[$calculatedTax->getTaxRate()] = $calculatedTax;
if (!$new->has((string) $calculatedTax->getTaxRate())) {
$new->set((string) $calculatedTax->getTaxRate(), $calculatedTax);

continue;
}

$new[$calculatedTax->getTaxRate()] = new CalculatedTax([
'taxRate' => $calculatedTax->getTaxRate(),
'price' => $new[$calculatedTax->getTaxRate()]->getPrice() + $calculatedTax->getPrice(),
'tax' => $new[$calculatedTax->getTaxRate()]->getTax() + $calculatedTax->getTax(),
]);
$new->set(
(string) $calculatedTax->getTaxRate(),
new CalculatedTax([
'taxRate' => $calculatedTax->getTaxRate(),
'price' => $new->get((string) $calculatedTax->getTaxRate())->getPrice() + $calculatedTax->getPrice(),
'tax' => $new->get((string) $calculatedTax->getTaxRate())->getTax() + $calculatedTax->getTax(),
])
);

}

return $new;
var_dump($new->());

Check failure on line 56 in src/Context/Cart/CalculatedTax.php

View workflow job for this annotation

GitHub Actions / static-analyse

Syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$' on line 56

return $new->all();
}
}
34 changes: 19 additions & 15 deletions src/Context/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Shopware\App\SDK\Context\Cart;

use Shopware\App\SDK\Context\ArrayStruct;
use Shopware\App\SDK\Framework\Collection;

class Cart extends ArrayStruct
{
Expand Down Expand Up @@ -33,39 +34,42 @@ public function getCampaignCode(): ?string
}

/**
* @return array<LineItem>
* @return Collection<LineItem>
*/
public function getLineItems(): array
public function getLineItems(): Collection
{
\assert(is_array($this->data['lineItems']));
return array_map(
\assert(\is_array($this->data['lineItems']));

return new Collection(\array_map(
static fn (array $lineItem) => new LineItem($lineItem),
$this->data['lineItems']
);
));
}

/**
* @return array<Delivery>
* @return Collection<Delivery>
*/
public function getDeliveries(): array
public function getDeliveries(): Collection
{
\assert(is_array($this->data['deliveries']));
return array_map(
\assert(\is_array($this->data['deliveries']));

return new Collection(\array_map(
static fn (array $delivery) => new Delivery($delivery),
$this->data['deliveries']
);
));
}

/**
* @return array<CartTransaction>
* @return Collection<CartTransaction>
*/
public function getTransactions(): array
public function getTransactions(): Collection
{
\assert(is_array($this->data['transactions']));
return array_map(
\assert(\is_array($this->data['transactions']));

return new Collection(\array_map(
static fn (array $transaction) => new CartTransaction($transaction),
$this->data['transactions']
);
));
}

public function getPrice(): CartPrice
Expand Down
20 changes: 11 additions & 9 deletions src/Context/Cart/CartPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Shopware\App\SDK\Context\Cart;

use Shopware\App\SDK\Context\ArrayStruct;
use Shopware\App\SDK\Framework\Collection;

class CartPrice extends ArrayStruct
{
Expand All @@ -25,14 +26,15 @@ public function getTotalPrice(): float
}

/**
* @return array<CalculatedTax>
* @return Collection<CalculatedTax>
*/
public function getCalculatedTaxes(): array
public function getCalculatedTaxes(): Collection

Check failure on line 31 in src/Context/Cart/CartPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Method Shopware\App\SDK\Context\Cart\CartPrice::getCalculatedTaxes() has invalid return type Shopware\App\SDK\Context\Cart\CalculatedTax.
{
\assert(is_array($this->data['calculatedTaxes']));
return array_map(static function (array $calculatedTax): CalculatedTax {

return new Collection(\array_map(static function (array $calculatedTax): CalculatedTax {

Check failure on line 35 in src/Context/Cart/CartPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Anonymous function has invalid return type Shopware\App\SDK\Context\Cart\CalculatedTax.
return new CalculatedTax($calculatedTax);

Check failure on line 36 in src/Context/Cart/CartPrice.php

View workflow job for this annotation

GitHub Actions / static-analyse

Instantiated class Shopware\App\SDK\Context\Cart\CalculatedTax not found.
}, $this->data['calculatedTaxes']);
}, $this->data['calculatedTaxes']));
}

public function getTaxStatus(): string
Expand All @@ -42,15 +44,15 @@ public function getTaxStatus(): string
}

/**
* @return array<TaxRule>
* @return Collection<TaxRule>
*/
public function getTaxRules(): array
public function getTaxRules(): Collection
{
\assert(is_array($this->data['taxRules']));
\assert(\is_array($this->data['taxRules']));

return array_map(static function (array $taxRule): TaxRule {
return new Collection(\array_map(static function (array $taxRule): TaxRule {
return new TaxRule($taxRule);
}, $this->data['taxRules']);
}, $this->data['taxRules']));
}

public function getPositionPrice(): float
Expand Down
9 changes: 5 additions & 4 deletions src/Context/Cart/Delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
use Shopware\App\SDK\Context\ArrayStruct;
use Shopware\App\SDK\Context\SalesChannelContext\ShippingLocation;
use Shopware\App\SDK\Context\SalesChannelContext\ShippingMethod;
use Shopware\App\SDK\Framework\Collection;

class Delivery extends ArrayStruct
{
/**
* @return array<DeliveryPosition>
* @return Collection<DeliveryPosition>
*/
public function getPositions(): array
public function getPositions(): Collection
{
\assert(is_array($this->data['positions']));

return array_map(static function (array $position) {
return new Collection(\array_map(static function (array $position) {
return new DeliveryPosition($position);
}, $this->data['positions']);
}, $this->data['positions']));
}

public function getLocation(): ShippingLocation
Expand Down
12 changes: 12 additions & 0 deletions src/Context/Cart/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Shopware\App\SDK\Context\Cart;

final class Error
{
public const LEVEL_NOTICE = 0;
public const LEVEL_WARNING = 10;
public const LEVEL_ERROR = 20;
}
7 changes: 4 additions & 3 deletions src/Context/Cart/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Shopware\App\SDK\Context\Cart;

use Shopware\App\SDK\Context\ArrayStruct;
use Shopware\App\SDK\Framework\Collection;

class LineItem extends ArrayStruct
{
Expand Down Expand Up @@ -82,12 +83,12 @@ public function getStates(): array
}

/**
* @return array<LineItem>
* @return Collection<LineItem>
*/
public function getChildren(): array
public function getChildren(): Collection
{
\assert(is_array($this->data['children']));

return array_map(static fn (array $child): LineItem => new LineItem($child), $this->data['children']);
return new Collection(\array_map(static fn (array $child): LineItem => new LineItem($child), $this->data['children']));
}
}
Loading

0 comments on commit 2090cba

Please sign in to comment.