Skip to content

Commit

Permalink
PISHOS-325: Add GDPR Checkbox for express checkout (#831)
Browse files Browse the repository at this point in the history
* NTR: PISHPS-325: Add GDPR Checkbox

* NTR: use upload artifact v4 version

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Sep 9, 2024
1 parent 4a8bfb0 commit 9405c55
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build-plugin/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ runs:
unzip ~/.build/MolliePayments.zip -d ~/.build/MolliePayments
- name: Store ZIP file in Github
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: MolliePayments-Shopware
retention-days: 4
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/run-e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ runs:
- name: Store Cypress Results
if: ${{ inputs.RUN_CYPRESS == 'true' && always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: cypress_results_v${{ inputs.SHOPWARE }}${{ inputs.CYPRESS_RESULTS_SUFFIX }}
retention-days: 1
Expand Down
3 changes: 2 additions & 1 deletion src/Components/ApplePayDirect/ApplePayDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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 $phone, 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, int $acceptedDataProtection, SalesChannelContext $context): SalesChannelContext
{
if (empty($paymentToken)) {
throw new \Exception('PaymentToken not found!');
Expand All @@ -369,6 +369,7 @@ public function prepareCustomer(string $firstname, string $lastname, string $ema
$zipcode,
$city,
$countryCode,
$acceptedDataProtection,
$context
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public function pay(RequestDataBag $data, SalesChannelContext $context): StoreAp
$countryCode = (string)$data->get('countryCode', '');
$phone = (string)$data->get('phone', '');

$acceptedDataProtection = (int)$data->get('acceptedDataProtection', '0');

$paymentToken = (string)$data->get('paymentToken', '');
$finishUrl = (string)$data->get('finishUrl', '');
$errorUrl = (string)$data->get('errorUrl', '');
Expand All @@ -217,6 +219,7 @@ public function pay(RequestDataBag $data, SalesChannelContext $context): StoreAp
$countryCode,
$phone,
$paymentToken,
$acceptedDataProtection,
$context
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public function startPayment(SalesChannelContext $context, Request $request): Re
$city = (string)$request->get('city', '');
$countryCode = (string)$request->get('countryCode', '');
$phone = (string)$request->get('phone', '');
$acceptedDataProtection = (int)$request->get('acceptedDataProtection', '0');

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

Expand All @@ -342,6 +343,7 @@ public function startPayment(SalesChannelContext $context, Request $request): Re
$countryCode,
$phone,
$paymentToken,
$acceptedDataProtection,
$context
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ export default class MollieApplePayDirect extends Plugin {
}



const submitForm = document.querySelector('#productDetailPageBuyProductForm');

if(submitForm !== null){
if (submitForm !== null) {
this.checkSubmitButton(submitForm);
submitForm.addEventListener('change', (event) => {
this.checkSubmitButton(event.target.closest('form#productDetailPageBuyProductForm'));
Expand Down Expand Up @@ -86,7 +85,6 @@ export default class MollieApplePayDirect extends Plugin {
const shopUrl = me.getShopUrl(applePayButtons[0]);



// verify if apple pay is even allowed
// in our current sales channel
me.client.get(
Expand All @@ -102,7 +100,7 @@ export default class MollieApplePayDirect extends Plugin {

applePayButtons.forEach(function (button) {

if(button.hasAttribute('disabled')){
if (button.hasAttribute('disabled')) {
button.classList.add('d-none');
button.removeEventListener('click', me.onButtonClick);
return;
Expand All @@ -118,24 +116,24 @@ export default class MollieApplePayDirect extends Plugin {
);
}

checkSubmitButton(form){
checkSubmitButton(form) {
const buyButton = form.querySelector('.btn-buy');

if(buyButton === null){
if (buyButton === null) {
return;
}

const applePayButton = form.querySelector('.js-apple-pay');

if(applePayButton === null){
if (applePayButton === null) {
return;
}

if(applePayButton.hasAttribute('disabled')){
if (applePayButton.hasAttribute('disabled')) {
applePayButton.removeAttribute('disabled');
}
if(buyButton.hasAttribute('disabled')){
applePayButton.setAttribute('disabled','disabled');
if (buyButton.hasAttribute('disabled')) {
applePayButton.setAttribute('disabled', 'disabled');
}

}
Expand Down Expand Up @@ -164,7 +162,20 @@ export default class MollieApplePayDirect extends Plugin {
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);
const dataProtection = form.querySelector('input[name="acceptedDataProtection"]');

form.classList.remove('was-validated');

if (dataProtection !== null) {
const dataProtectionValue = dataProtection.checked ? 1: 0;
form.classList.add('was-validated');

dataProtection.classList.remove('is-invalid');
if (dataProtectionValue === 0) {
dataProtection.classList.add('is-invalid');
return;
}
}

// this helps us to figure out if we are in
// "product" mode to purchase a single product, or in "cart" mode
Expand Down Expand Up @@ -192,7 +203,7 @@ export default class MollieApplePayDirect extends Plugin {

}
const applePaySessionFactory = new ApplePaySessionFactory();
const session = applePaySessionFactory.create(isProductMode,countryCode,currency,withPhone,shopSlug);
const session = applePaySessionFactory.create(isProductMode, countryCode, currency, withPhone, shopSlug, dataProtection);
session.begin();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export default class ApplePaySessionFactory {
* @param currency
* @param shopSlug
* @param withPhone
* @param dataProtection
* @returns {ApplePaySession}
*/
create(isProductMode, country, currency, withPhone, shopSlug) {
create(isProductMode, country, currency, withPhone, shopSlug, dataProtection) {

const me = this;
var shippingFields = [
Expand All @@ -32,6 +33,10 @@ export default class ApplePaySessionFactory {
if (withPhone === 1) {
shippingFields.push('phone');
}
let dataProtectionValue = false;
if(dataProtection !== null){
dataProtectionValue = dataProtection.value;
}

var request = {
countryCode: country,
Expand Down Expand Up @@ -160,7 +165,7 @@ export default class ApplePaySessionFactory {

// now finish our payment by filling a form
// and submitting it along with our payment token
me.finishPayment(shopSlug + '/mollie/apple-pay/start-payment', paymentToken, event.payment);
me.finishPayment(shopSlug + '/mollie/apple-pay/start-payment', paymentToken, event.payment,dataProtectionValue);
};

session.oncancel = function () {
Expand All @@ -181,7 +186,7 @@ export default class ApplePaySessionFactory {
* @param paymentToken
* @param payment
*/
finishPayment(checkoutURL, paymentToken, payment) {
finishPayment(checkoutURL, paymentToken, payment,dataProtectionValue) {
const createInput = function (name, val) {
const input = document.createElement('input');
input.type = 'hidden';
Expand All @@ -208,6 +213,7 @@ export default class ApplePaySessionFactory {
form.insertAdjacentElement('beforeend', createInput('street', street));
form.insertAdjacentElement('beforeend', createInput('postalCode', payment.shippingContact.postalCode));
form.insertAdjacentElement('beforeend', createInput('city', payment.shippingContact.locality));
form.insertAdjacentElement('beforeend', createInput('acceptedDataProtection', dataProtectionValue));

if (payment.shippingContact.phoneNumber !== undefined && payment.shippingContact.phoneNumber.length > 0) {
form.insertAdjacentElement('beforeend', createInput('phone', payment.shippingContact.phoneNumber));
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<argument type="service" id="Kiener\MolliePayments\Repository\OrderTransaction\OrderTransactionRepository"/>
</service>

<service id="Kiener\MolliePayments\Service\Cart\CartBackupService" class="Kiener\MolliePayments\Service\Cart\CartBackupService">
<service id="Kiener\MolliePayments\Service\Cart\CartBackupService" class="Kiener\MolliePayments\Service\Cart\CartBackupService" public="true">
<argument type="service" id="Shopware\Core\Checkout\Cart\SalesChannel\CartService"/>
</service>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% block mollie_apple_pay_direct %}

<div class="mollie-apple-pay-direct {{ cols }}">
{% if page.product %}
{# this is for older shopware versions #}
Expand Down Expand Up @@ -32,6 +33,11 @@
<input type="hidden" name="mode" value="{{ mode }}"/>

{% block mollie_apple_pay_direct_button %}

{% if mollie_express_required_data_protection %}
{% sw_include '@Storefront/storefront/component/privacy-notice.html.twig' %}
{% endif %}

<button type="submit" data-shop-url="{{ seoUrl('frontend.home.page') }}" class="btn btn-primary btn-block btn-buy apple-pay-button-with-text apple-pay-button-black js-apple-pay w-100 d-none">
{# space to match height other buttons #}
&nbsp;
Expand Down
6 changes: 5 additions & 1 deletion src/Service/CustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextPersister;
Expand Down Expand Up @@ -435,7 +436,7 @@ public function getAddressArray($address, CustomerEntity $customer): array
* @param SalesChannelContext $context
* @return null|CustomerEntity
*/
public function createApplePayDirectCustomerIfNotExists(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2, SalesChannelContext $context): ?CustomerEntity
public function createApplePayDirectCustomerIfNotExists(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2, int $acceptedDataProtection, SalesChannelContext $context): ?CustomerEntity
{
$countryId = $this->getCountryId($countryISO2, $context->getContext());
$salutationId = $this->getSalutationId($context->getContext());
Expand All @@ -451,6 +452,7 @@ public function createApplePayDirectCustomerIfNotExists(string $firstname, strin
$data->set('firstName', $firstname);
$data->set('lastName', $lastname);
$data->set('email', $email);
$data->set('acceptedDataProtection', $acceptedDataProtection);

$billingAddress = new RequestDataBag();
$billingAddress->set('street', $street);
Expand Down Expand Up @@ -601,6 +603,8 @@ private function findCustomerByEmail(string $email, SalesChannelContext $context
$criteria->addFilter(new EqualsFilter('email', $email));
$criteria->addFilter(new EqualsFilter('guest', true));
$criteria->addFilter(new EqualsFilter('active', true));
$criteria->addSorting(new FieldSorting('createdAt', FieldSorting::DESCENDING));


$searchResult = $this->customerRepository->search($criteria, $context->getContext());

Expand Down
2 changes: 1 addition & 1 deletion src/Service/CustomerServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getCustomerStruct(string $customerId, Context $context): Custome
* @return array<string, mixed>
*/
public function getAddressArray($address, CustomerEntity $customer): array;
public function createApplePayDirectCustomerIfNotExists(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2, SalesChannelContext $context): ?CustomerEntity;
public function createApplePayDirectCustomerIfNotExists(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2, int $acceptedDataProtection, SalesChannelContext $context): ?CustomerEntity;
public function getCountryId(string $countryCode, Context $context): ?string;
public function getSalutationId(Context $context): ?string;
public function createMollieCustomer(string $customerId, string $salesChannelId, Context $context): void;
Expand Down
4 changes: 4 additions & 0 deletions src/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SettingsService implements PluginSettingsServiceInterface

private const PHONE_NUMBER_FIELD = 'showPhoneNumberField';

private const REQUIRE_DATA_PROTECTION ='requireDataProtectionCheckbox';

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

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

$structData[self::REQUIRE_DATA_PROTECTION] = $coreSettings[self::REQUIRE_DATA_PROTECTION] ?? 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
15 changes: 15 additions & 0 deletions src/Setting/MollieSettingStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ class MollieSettingStruct extends Struct
*/
protected $paymentFinalizeTransactionTime;

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

/**
* @return string
*/
Expand Down Expand Up @@ -1013,4 +1018,14 @@ public function setPaymentFinalizeTransactionTime(int $paymentFinalizeTransactio
{
$this->paymentFinalizeTransactionTime = $paymentFinalizeTransactionTime;
}

public function isRequireDataProtectionCheckbox(): bool
{
return $this->requireDataProtectionCheckbox;
}

public function setRequireDataProtectionCheckbox(bool $requireDataProtectionCheckbox): void
{
$this->requireDataProtectionCheckbox = $requireDataProtectionCheckbox;
}
}
1 change: 1 addition & 0 deletions src/Subscriber/ApplePayDirectSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void
$event->setParameter('mollie_applepaydirect_phonenumber_required', (int)$shoPhoneNumberField);
$event->setParameter('mollie_applepaydirect_enabled', $applePayDirectEnabled);
$event->setParameter('mollie_applepaydirect_restrictions', $settings->getRestrictApplePayDirect());
$event->setParameter('mollie_express_required_data_protection', $settings->isRequireDataProtectionCheckbox() && $event->getSalesChannelContext()->getCustomer() == null);
}
}
2 changes: 1 addition & 1 deletion tests/PHPUnit/Fakes/FakeCustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getAddressArray($address, CustomerEntity $customer): array
return [];
}

public function createApplePayDirectCustomerIfNotExists(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2, SalesChannelContext $context): ?CustomerEntity
public function createApplePayDirectCustomerIfNotExists(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2,int $acceptedDataProtection, SalesChannelContext $context): ?CustomerEntity
{
return null;
}
Expand Down

0 comments on commit 9405c55

Please sign in to comment.