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

NTR: fix #764 #773

Merged
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
4 changes: 2 additions & 2 deletions src/Components/ApplePayDirect/ApplePayDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function restoreCart(SalesChannelContext $context): void
* @throws \Exception
* @return SalesChannelContext
*/
public function prepareCustomer(string $firstname, string $lastname, string $email, string $street, string $zipcode, string $city, string $countryCode, string $paymentToken, SalesChannelContext $context): SalesChannelContext
public function prepareCustomer(string $firstname, string $lastname, string $email, string $street, string $zipcode, string $city, string $countryCode, string $phone, string $paymentToken, SalesChannelContext $context): SalesChannelContext
{
if (empty($paymentToken)) {
throw new \Exception('PaymentToken not found!');
Expand All @@ -356,7 +356,7 @@ public function prepareCustomer(string $firstname, string $lastname, string $ema
$firstname,
$lastname,
$email,
'',
$phone,
$street,
$zipcode,
$city,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function pay(RequestDataBag $data, SalesChannelContext $context): StoreAp
$city = (string)$data->get('city', '');
$zipcode = (string)$data->get('postalCode', '');
$countryCode = (string)$data->get('countryCode', '');
$phone = (string)$data->get('phone', '');

$paymentToken = (string)$data->get('paymentToken', '');
$finishUrl = (string)$data->get('finishUrl', '');
Expand All @@ -215,6 +216,7 @@ public function pay(RequestDataBag $data, SalesChannelContext $context): StoreAp
$zipcode,
$city,
$countryCode,
$phone,
$paymentToken,
$context
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function createPaymentSession(SalesChannelContext $context, Request $requ
]
);

return new JsonResponse(['success' => false,], 500);
return new JsonResponse(['success' => false], 500);
}
}

Expand Down Expand Up @@ -342,6 +342,7 @@ public function startPayment(SalesChannelContext $context, Request $request): Re
$zipcode = (string)$request->get('postalCode', '');
$city = (string)$request->get('city', '');
$countryCode = (string)$request->get('countryCode', '');
$phone = (string)$request->get('phone', '');

$paymentToken = (string)$request->get('paymentToken', '');

Expand All @@ -358,6 +359,7 @@ public function startPayment(SalesChannelContext $context, Request $request): Re
$zipcode,
$city,
$countryCode,
$phone,
$paymentToken,
$context
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export default class MollieApplePayDirect extends Plugin {
const countryCode = form.querySelector('input[name="countryCode"]').value;
const currency = form.querySelector('input[name="currency"]').value;
const mode = form.querySelector('input[name="mode"]').value;
const withPhone = parseInt(form.querySelector('input[name="withPhone"]').value);


// this helps us to figure out if we are in
// "product" mode to purchase a single product, or in "cart" mode
Expand All @@ -152,7 +154,7 @@ export default class MollieApplePayDirect extends Plugin {
me.addProductToCart(productId, quantity, shopUrl);
}

var session = me.createApplePaySession(isProductMode, countryCode, currency, shopUrl);
var session = me.createApplePaySession(isProductMode, countryCode, currency,withPhone, shopUrl);
session.begin();
}

Expand All @@ -178,20 +180,26 @@ export default class MollieApplePayDirect extends Plugin {
* @param country
* @param currency
* @param shopSlug
* @param withPhone
* @returns {ApplePaySession}
*/
createApplePaySession(isProductMode, country, currency, shopSlug) {
createApplePaySession(isProductMode, country, currency, withPhone, shopSlug) {

const me = this;
var shippingFields = [
'name',
'email',
'postalAddress',
];

if(withPhone === 1){
shippingFields.push('phone');
}

var request = {
countryCode: country,
currencyCode: currency,
requiredShippingContactFields: [
'name',
'email',
'postalAddress',
],
requiredShippingContactFields: shippingFields,
supportedNetworks: [
'amex',
'maestro',
Expand All @@ -216,6 +224,9 @@ export default class MollieApplePayDirect extends Plugin {
validationUrl: event.validationURL,
}),
(validationData) => {
if(validationData.success === false){
throw new Error('Validation failed for URL: '+ event.validationURL);
}
const data = JSON.parse(validationData.session);
session.completeMerchantValidation(data);
},
Expand Down Expand Up @@ -360,6 +371,11 @@ export default class MollieApplePayDirect extends Plugin {
form.insertAdjacentElement('beforeend', createInput('street', street));
form.insertAdjacentElement('beforeend', createInput('postalCode', payment.shippingContact.postalCode));
form.insertAdjacentElement('beforeend', createInput('city', payment.shippingContact.locality));

if(payment.shippingContact.phoneNumber.length > 0){
form.insertAdjacentElement('beforeend', createInput('phone', payment.shippingContact.phoneNumber));
}

form.insertAdjacentElement('beforeend', createInput('countryCode', payment.shippingContact.countryCode));
// also add our payment token
form.insertAdjacentElement('beforeend', createInput('paymentToken', paymentToken));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<input type="hidden" name="id" value="{{ productId }}"/>
<input type="hidden" name="currency" value="{{ context.currency.translated.shortName }}"/>
<input type="hidden" name="countryCode" value="{{ context.shippingLocation.country.iso }}"/>
<input type="hidden" name="withPhone" value="{{ mollie_applepaydirect_phonenumber_required }}">

{% if productId %}
{% set mode = 'productMode' %}
Expand Down
23 changes: 22 additions & 1 deletion src/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
class SettingsService implements PluginSettingsServiceInterface
{
public const SYSTEM_CONFIG_DOMAIN = 'MolliePayments.config.';
private const SYSTEM_CORE_CONFIG_DOMAIN = 'core';

private const PHONE_NUMBER_FIELD_REQUIRED = 'phoneNumberFieldRequired';
const LIVE_API_KEY = 'liveApiKey';
const TEST_API_KEY = 'testApiKey';
const LIVE_PROFILE_ID = 'liveProfileId';
const TEST_PROFILE_ID = 'testProfileId';

/**
* @var array<MollieSettingStruct>
*/
private $settings = [];

/**
* @var SystemConfigService
Expand Down Expand Up @@ -70,6 +76,11 @@ public function __construct(SystemConfigService $systemConfigService, SalesChann
*/
public function getSettings(?string $salesChannelId = null): MollieSettingStruct
{
$cacheKey = $salesChannelId ?? 'all';

if (isset($this->settings[$cacheKey]) && $this->settings[$cacheKey] instanceof MollieSettingStruct) {
return $this->settings[$cacheKey];
}
$structData = [];
$systemConfigData = $this->systemConfigService->getDomain(self::SYSTEM_CONFIG_DOMAIN, $salesChannelId, true);

Expand All @@ -81,7 +92,17 @@ public function getSettings(?string $salesChannelId = null): MollieSettingStruct
}
}

return (new MollieSettingStruct())->assign($structData);
$coreSettings = $this->systemConfigService->getDomain(self::SYSTEM_CORE_CONFIG_DOMAIN, $salesChannelId, true);
foreach ($coreSettings as $key => $value) {
if (strpos($key, self::PHONE_NUMBER_FIELD_REQUIRED)) {
$structData[self::PHONE_NUMBER_FIELD_REQUIRED] = $value;
break;
}
}


$this->settings[$cacheKey] = (new MollieSettingStruct())->assign($structData);
return $this->settings[$cacheKey] ;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Setting/MollieSettingStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ class MollieSettingStruct extends Struct
*/
protected $useShopwareJavascript = false;


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

/**
* @return string
*/
Expand Down Expand Up @@ -950,4 +956,14 @@ public function setUseShopwareJavascript(bool $useShopwareJavascript): void
{
$this->useShopwareJavascript = $useShopwareJavascript;
}

public function isPhoneNumberFieldRequired(): bool
{
return $this->phoneNumberFieldRequired;
}

public function setPhoneNumberFieldRequired(bool $phoneNumberFieldRequired): void
{
$this->phoneNumberFieldRequired = $phoneNumberFieldRequired;
}
}
1 change: 1 addition & 0 deletions src/Subscriber/ApplePayDirectSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void

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

$event->setParameter('mollie_applepaydirect_phonenumber_required', $settings->isPhoneNumberFieldRequired());
$event->setParameter('mollie_applepaydirect_enabled', $applePayDirectEnabled);
$event->setParameter('mollie_applepaydirect_restrictions', $settings->getRestrictApplePayDirect());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ context("Checkout Failure Tests", () => {

// select giro pay and mark it as "paid"
mollieSandbox.initSandboxCookie();
molliePaymentList.selectiDEAL();
molliePaymentList.selectSOFORT();
molliePaymentStatus.selectPaid();

cy.url().should('include', '/checkout/finish');
Expand Down Expand Up @@ -102,7 +102,7 @@ context("Checkout Failure Tests", () => {

// select giro pay and mark it as "paid"
mollieSandbox.initSandboxCookie();
molliePaymentList.selectiDEAL();
molliePaymentList.selectSOFORT();
molliePaymentStatus.selectPaid();

cy.url().should('include', '/checkout/finish');
Expand Down Expand Up @@ -173,7 +173,7 @@ context("Checkout Failure Tests", () => {
}


paymentAction.switchPaymentMethod('iDEAL');
paymentAction.switchPaymentMethod('SOFORT');

checkout.placeOrderOnEdit();

Expand Down Expand Up @@ -206,7 +206,7 @@ context("Checkout Failure Tests", () => {
cy.contains('We received your order, but the payment was aborted');
}

paymentAction.switchPaymentMethod('iDEAL');
paymentAction.switchPaymentMethod('SOFORT');

checkout.placeOrderOnEdit();

Expand Down
Loading