Skip to content

Commit

Permalink
PISHPS-328: applied requested todos
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muxfeld-diw committed Jul 11, 2024
1 parent fc8fcc2 commit f792781
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/Components/ApplePayDirect/ApplePayDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Kiener\MolliePayments\Components\ApplePayDirect\Exceptions\ApplePayDirectDomainNotInAllowListException;
use Kiener\MolliePayments\Components\ApplePayDirect\Gateways\ApplePayDirectDomainAllowListGateway;
use Kiener\MolliePayments\Components\ApplePayDirect\Models\ApplePayCart;
use Kiener\MolliePayments\Components\ApplePayDirect\Services\ApplePayDirectDomainSanitizer;
use Kiener\MolliePayments\Components\ApplePayDirect\Services\ApplePayDomainVerificationService;
use Kiener\MolliePayments\Components\ApplePayDirect\Services\ApplePayFormatter;
use Kiener\MolliePayments\Components\ApplePayDirect\Services\ApplePayShippingBuilder;
use Kiener\MolliePayments\Components\ApplePayDirect\Services\ApplePayDirectDomainSanitizer;
use Kiener\MolliePayments\Facade\MolliePaymentDoPay;
use Kiener\MolliePayments\Factory\MollieApiFactory;
use Kiener\MolliePayments\Handler\Method\ApplePayPayment;
Expand Down Expand Up @@ -281,10 +281,10 @@ public function setShippingMethod(string $shippingMethodID, SalesChannelContext
* @param string $validationURL
* @param string $domain
* @param SalesChannelContext $context
* @return string
* @throws ApiException
* @throws ApplePayDirectDomainAllowListCanNotBeEmptyException
* @throws ApplePayDirectDomainNotInAllowListException
* @return string
*/
public function createPaymentSession(string $validationURL, string $domain, SalesChannelContext $context): string
{
Expand Down Expand Up @@ -529,9 +529,9 @@ private function buildApplePayCart(Cart $cart): ApplePayCart
*
* @param SalesChannelContext $context
* @param string $domain
* @return string
* @throws ApplePayDirectDomainAllowListCanNotBeEmptyException
* @throws ApplePayDirectDomainNotInAllowListException
* @return string
*/
private function getValidDomain(string $domain, SalesChannelContext $context): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function __construct(SettingsService $settingsService)
public function getAllowList(SalesChannelContext $context): ApplePayDirectDomainAllowList
{
$settings = $this->settingsService->getSettings($context->getSalesChannel()->getId());
$allowList = $settings->applePayDirectDomainAllowList ?? '';
$allowList = $settings->getApplePayDirectDomainAllowList();

if (empty($allowList) || !is_string($allowList)) {
if (empty($allowList)) {
return ApplePayDirectDomainAllowList::create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Kiener\MolliePayments\Components\ApplePayDirect\Models;

use Kiener\MolliePayments\Components\ApplePayDirect\Services\ApplePayDirectDomainSanitizer;

class ApplePayDirectDomainAllowListItem
{
/**
Expand Down Expand Up @@ -32,15 +34,7 @@ public static function create(string $value): self
throw new \InvalidArgumentException(sprintf('The value of %s must not be empty', self::class));
}

# we need to have a protocol before the parse url command
# in order to have it work correctly
if (strpos($value, 'http') !== 0) {
$value = 'https://' . $value;
}

# now extract the raw domain without protocol
# and without any sub shop urls
$value = (string)parse_url($value, PHP_URL_HOST);
$value = (new ApplePayDirectDomainSanitizer())->sanitizeDomain($value);

return new self($value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class ApplePayDirectDomainSanitizer
/**
* Sanitize the given domain
*
* @param string $url
* @param string $domain
* @return string
*/
public function sanitizeDomain(string $url): string
public function sanitizeDomain(string $domain): string
{
# we need to have a protocol before the parse url command
# in order to have it work correctly
if (strpos($url, 'http') !== 0) {
$url = 'https://' . $url;
if (strpos($domain, 'http') !== 0) {
$domain = 'https://' . $domain;
}

# now extract the raw domain without protocol
# and without any sub shop urls
return (string)parse_url($url, PHP_URL_HOST);
return (string)parse_url($domain, PHP_URL_HOST);
}
}
1 change: 0 additions & 1 deletion src/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class SettingsService implements PluginSettingsServiceInterface
const TEST_API_KEY = 'testApiKey';
const LIVE_PROFILE_ID = 'liveProfileId';
const TEST_PROFILE_ID = 'testProfileId';
const APPLE_PAY_DIRECT_DOMAIN_ALLOW_LIST = 'applePayDirectDomainAllowList';

/**
* @var SystemConfigService
Expand Down
17 changes: 17 additions & 0 deletions src/Setting/MollieSettingStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class MollieSettingStruct extends Struct
public const ORDER_EXPIRES_AT_MIN_DAYS = 1;
public const ORDER_EXPIRES_AT_MAX_DAYS = 100;

const APPLE_PAY_DIRECT_DOMAIN_ALLOW_LIST = 'applePayDirectDomainAllowList';

/**
* @var string
*/
Expand Down Expand Up @@ -248,6 +250,11 @@ class MollieSettingStruct extends Struct
*/
protected $phoneNumberFieldRequired = false;

/**
* @var string
*/
protected $applePayDirectDomainAllowList = '';

/**
* @return string
*/
Expand Down Expand Up @@ -965,4 +972,14 @@ public function setPhoneNumberFieldRequired(bool $phoneNumberFieldRequired): voi
{
$this->phoneNumberFieldRequired = $phoneNumberFieldRequired;
}

public function getApplePayDirectDomainAllowList(): string
{
return $this->applePayDirectDomainAllowList;
}

public function setApplePayDirectDomainAllowList(string $applePayDirectDomainAllowList): void
{
$this->applePayDirectDomainAllowList = $applePayDirectDomainAllowList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Kiener\MolliePayments\Components\ApplePayDirect\Gateways\ApplePayDirectDomainAllowListGateway;
use Kiener\MolliePayments\Service\SettingsService;
use Kiener\MolliePayments\Setting\MollieSettingStruct;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\Context;
Expand Down Expand Up @@ -45,8 +46,7 @@ protected function setUp(): void

public function testProvidesEmptyAllowList(): void
{
$struct = $this->createMock(\Kiener\MolliePayments\Setting\MollieSettingStruct::class);
$struct->{SettingsService::APPLE_PAY_DIRECT_DOMAIN_ALLOW_LIST} = '';
$struct = $this->createConfiguredMock(MollieSettingStruct::class, ['getApplePayDirectDomainAllowList' => '']);
$this->service->expects($this->once())->method('getSettings')->willReturn($struct);
$allowList = $this->gateway->getAllowList($this->scContext);

Expand All @@ -56,8 +56,7 @@ public function testProvidesEmptyAllowList(): void
public function testProvidesAllowList(): void
{
$allowListString = 'https://example.com,https://example-url.org';
$struct = $this->createMock(\Kiener\MolliePayments\Setting\MollieSettingStruct::class);
$struct->{SettingsService::APPLE_PAY_DIRECT_DOMAIN_ALLOW_LIST} = $allowListString;
$struct = $this->createConfiguredMock(MollieSettingStruct::class, ['getApplePayDirectDomainAllowList' => $allowListString]);
$this->service->expects($this->once())->method('getSettings')->willReturn($struct);

$allowList = $this->gateway->getAllowList($this->scContext);
Expand Down

0 comments on commit f792781

Please sign in to comment.