Skip to content

Commit

Permalink
NTR: apple pay direct, ask for phone number if not required
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Aug 22, 2024
1 parent bcbda5b commit bc1ee81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class SettingsService implements PluginSettingsServiceInterface
private const SYSTEM_CORE_CART_CONFIG_DOMAIN = 'core.cart';

private const PHONE_NUMBER_FIELD_REQUIRED = 'phoneNumberFieldRequired';

private const PHONE_NUMBER_FIELD = 'showPhoneNumberField';

private const PAYMENT_FINALIZE_TRANSACTION_TIME = 'paymentFinalizeTransactionTime';
const LIVE_API_KEY = 'liveApiKey';
const TEST_API_KEY = 'testApiKey';
Expand Down Expand Up @@ -90,6 +93,8 @@ public function getSettings(?string $salesChannelId = null): MollieSettingStruct

$structData[self::PHONE_NUMBER_FIELD_REQUIRED] = $coreSettings[self::PHONE_NUMBER_FIELD_REQUIRED] ?? false;

$structData[self::PHONE_NUMBER_FIELD] = $coreSettings[self::PHONE_NUMBER_FIELD] ?? false;

/** @var array<mixed> $cartSettings */
$cartSettings = $this->systemConfigService->get(self::SYSTEM_CORE_CART_CONFIG_DOMAIN, $salesChannelId);
$structData[self::PAYMENT_FINALIZE_TRANSACTION_TIME] = $cartSettings[self::PAYMENT_FINALIZE_TRANSACTION_TIME] ?? 1800;
Expand Down
16 changes: 16 additions & 0 deletions src/Setting/MollieSettingStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ class MollieSettingStruct extends Struct
*/
protected $phoneNumberFieldRequired = false;

/**
* @var bool
*/
protected $showPhoneNumberField = false;

/**
* @var string
*/
Expand Down Expand Up @@ -978,6 +983,17 @@ public function setPhoneNumberFieldRequired(bool $phoneNumberFieldRequired): voi
$this->phoneNumberFieldRequired = $phoneNumberFieldRequired;
}

public function isPhoneNumberFieldShown():bool
{
return $this->showPhoneNumberField;
}

public function setShowPhoneNumberField(bool $showPhoneNumberField): void
{
$this->showPhoneNumberField = $showPhoneNumberField;
}


public function getApplePayDirectDomainAllowList(): string
{
return $this->applePayDirectDomainAllowList;
Expand Down
4 changes: 3 additions & 1 deletion src/Subscriber/ApplePayDirectSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void

$applePayDirectEnabled = $this->applePay->isApplePayDirectEnabled($event->getSalesChannelContext());

$event->setParameter('mollie_applepaydirect_phonenumber_required', (int)$settings->isPhoneNumberFieldRequired());
$shoPhoneNumberField = $settings->isPhoneNumberFieldRequired() || $settings->isPhoneNumberFieldShown();

$event->setParameter('mollie_applepaydirect_phonenumber_required', (int)$shoPhoneNumberField);
$event->setParameter('mollie_applepaydirect_enabled', $applePayDirectEnabled);
$event->setParameter('mollie_applepaydirect_restrictions', $settings->getRestrictApplePayDirect());
}
Expand Down

0 comments on commit bc1ee81

Please sign in to comment.