Skip to content

Commit c24419a

Browse files
BlackScorpVitalij Mik
and
Vitalij Mik
authored
NTR: some changes (#888)
- added loader to the button - button cannot be triggered multiple times - show PPE only if added to saleschannel - add error after failed payment Co-authored-by: Vitalij Mik <[email protected]>
1 parent a43d8fa commit c24419a

File tree

16 files changed

+68
-14
lines changed

16 files changed

+68
-14
lines changed

src/Components/PaypalExpress/PayPalExpress.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function isPaypalExpressEnabled(SalesChannelContext $context): bool
9797
*/
9898
public function getActivePaypalExpressID(SalesChannelContext $context): string
9999
{
100-
return $this->repoPaymentMethods->getActivePaypalExpressID($context->getContext());
100+
return $this->repoPaymentMethods->getActivePaypalExpressID($context);
101101
}
102102

103103

src/Components/PaypalExpress/Route/FinishCheckoutRoute.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public function finishCheckout(SalesChannelContext $context): FinishCheckoutResp
119119
);
120120
}
121121

122+
# create new account or find existing and login
123+
$this->paypalExpress->prepareCustomer($shippingAddress, $context, $acceptedDataProtection, $billingAddress);
124+
122125
# we have to update the cart extension before a new user is created and logged in, otherwise the extension is not saved
123126
$cartExtension = new ArrayStruct([
124127
CustomFieldsInterface::PAYPAL_EXPRESS_AUTHENTICATE_ID => $payPalExpressSession->authenticationId
@@ -130,8 +133,6 @@ public function finishCheckout(SalesChannelContext $context): FinishCheckoutResp
130133
$this->cartService->persistCart($cart, $context);
131134

132135

133-
# create new account or find existing and login
134-
$this->paypalExpress->prepareCustomer($shippingAddress, $context, $acceptedDataProtection, $billingAddress);
135136
return new FinishCheckoutResponse($payPalExpressSession->id, $payPalExpressSession->authenticationId);
136137
}
137138
}

src/Controller/Storefront/PaypalExpress/PaypalExpressControllerBase.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class PaypalExpressControllerBase extends StorefrontController
1919
{
2020
use RedirectTrait;
21-
21+
private const SNIPPET_ERROR = 'molliePayments.payments.paypalExpress.paymentError';
2222
/**
2323
* @var RouterInterface
2424
*/
@@ -67,6 +67,7 @@ public function startCheckout(Request $request, SalesChannelContext $context): R
6767
$redirectUrl = $responseRedirectUrl;
6868
}
6969
} catch (\Throwable $e) {
70+
$this->addFlash('danger', $this->trans(self::SNIPPET_ERROR));
7071
$this->logger->error(
7172
'Failed to start Paypal Express checkout',
7273
['message' => $e->getMessage()]
@@ -82,6 +83,7 @@ public function cancelCheckout(SalesChannelContext $context): Response
8283
try {
8384
$this->cancelCheckoutRoute->cancelCheckout($context);
8485
} catch (\Throwable $e) {
86+
$this->addFlash('danger', $this->trans(self::SNIPPET_ERROR));
8587
$this->logger->error(
8688
'Failed to cancel Paypal Express checkout',
8789
['message' => $e->getMessage()]
@@ -102,6 +104,7 @@ public function finishCheckout(SalesChannelContext $context): Response
102104
$returnUrl = $this->getCheckoutConfirmPage($this->router);
103105
} catch (\Throwable $e) {
104106
$returnUrl = $this->getCheckoutCartPage($this->router);
107+
$this->addFlash('danger', $this->trans(self::SNIPPET_ERROR));
105108
$this->logger->error(
106109
'Failed to finish Paypal Express Checkout',
107110
['message' => $e->getMessage()]

src/Repository/PaymentMethod/PaymentMethodRepository.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
1212
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
1313
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
14+
use Shopware\Core\System\SalesChannel\SalesChannelContext;
1415

1516
class PaymentMethodRepository implements PaymentMethodRepositoryInterface
1617
{
@@ -80,18 +81,20 @@ public function getActiveApplePayID(Context $context): string
8081
}
8182

8283
/**
83-
* @param Context $context
84+
* @param SalesChannelContext $context
8485
* @throws \Exception
8586
* @return string
8687
*/
87-
public function getActivePaypalExpressID(Context $context): string
88+
public function getActivePaypalExpressID(SalesChannelContext $context): string
8889
{
8990
$criteria = new Criteria();
91+
$criteria->addAssociation('salesChannels');
9092
$criteria->addFilter(new EqualsFilter('handlerIdentifier', PayPalExpressPayment::class));
9193
$criteria->addFilter(new EqualsFilter('active', true));
94+
$criteria->addFilter(new EqualsFilter('salesChannels.id', $context->getSalesChannelId()));
9295

9396
/** @var array<string> $paymentMethods */
94-
$paymentMethods = $this->repoPaymentMethods->searchIds($criteria, $context)->getIds();
97+
$paymentMethods = $this->repoPaymentMethods->searchIds($criteria, $context->getContext())->getIds();
9598

9699
if (count($paymentMethods) <= 0) {
97100
throw new \Exception('Payment Method PayPal Express not found in system');

src/Repository/PaymentMethod/PaymentMethodRepositoryInterface.php

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
88
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
99
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
10+
use Shopware\Core\System\SalesChannel\SalesChannelContext;
1011

1112
interface PaymentMethodRepositoryInterface
1213
{
@@ -37,4 +38,10 @@ public function search(Criteria $criteria, Context $context): EntitySearchResult
3738
* @return string
3839
*/
3940
public function getActiveApplePayID(Context $context): string;
41+
42+
/**
43+
* @param SalesChannelContext $context
44+
* @return string
45+
*/
46+
public function getActivePaypalExpressID(SalesChannelContext $context): string;
4047
}

src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class MollieApplePayDirect extends Plugin {
7474
}
7575

7676
const applePaySessionFactory = new ApplePaySessionFactory();
77-
const session = applePaySessionFactory.create(isProductMode, countryCode, currency, withPhone, shopSlug, dataProtection);
77+
const session = applePaySessionFactory.create(isProductMode, countryCode, currency, withPhone, shopSlug, dataProtection,clickedButton);
7878
session.begin();
7979

8080
}

src/Resources/app/storefront/src/mollie-payments/plugins/mollie-express-actions.plugin.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class MollieExpressActions extends Plugin {
3434
}
3535

3636

37-
3837
const buyButtonRepository = new BuyButtonRepository();
3938

4039
expressButtons.forEach((button) => {
@@ -100,15 +99,14 @@ export class MollieExpressActions extends Plugin {
10099
return;
101100
}
102101
}
103-
102+
target.classList.add('processed');
104103

105104
const expressAddToCart = new ExpressAddToCart();
106105

107106
expressAddToCart.addItemToCart(target);
108107

109-
target.classList.add('processed');
110108
const mollieEvent = new event.constructor(event.type, event);
111109
target.dispatchEvent(mollieEvent);
112-
target.classList.remove('processed');
110+
113111
}
114112
}

src/Resources/app/storefront/src/mollie-payments/services/ApplePaySessionFactory.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export default class ApplePaySessionFactory {
1919
* @param shopSlug
2020
* @param withPhone
2121
* @param dataProtection
22+
* @param clickedButton
2223
* @returns ApplePaySession
2324
*/
24-
create(isProductMode, country, currency, withPhone, shopSlug, dataProtection) {
25+
create(isProductMode, country, currency, withPhone, shopSlug, dataProtection,clickedButton) {
2526

2627
const me = this;
2728
var shippingFields = [
@@ -166,6 +167,7 @@ export default class ApplePaySessionFactory {
166167
// now finish our payment by filling a form
167168
// and submitting it along with our payment token
168169
me.finishPayment(shopSlug + '/mollie/apple-pay/start-payment', paymentToken, event.payment,dataProtectionValue);
170+
clickedButton.classList.remove('processed');
169171
};
170172

171173
session.oncancel = function () {
@@ -175,6 +177,7 @@ export default class ApplePaySessionFactory {
175177
if (isProductMode) {
176178
me.client.post(shopSlug + '/mollie/apple-pay/restore-cart');
177179
}
180+
clickedButton.classList.remove('processed');
178181
};
179182

180183
return session;

src/Resources/app/storefront/src/scss/base.scss

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
@import "./account/subscriptions";
66
@import "./component/credit-card-mandate";
77
@import "./component/paypal-express-button";
8+
@import "./component/express-button";
89
@import "./display";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.mollie-express-button.processed {
2+
3+
4+
.loader {
5+
display: block;
6+
position:absolute;
7+
}
8+
*:not(.loader){
9+
opacity:0.2;
10+
}
11+
12+
}
13+
14+
.mollie-express-button .loader {
15+
display: none;
16+
}

src/Resources/snippet/de_DE/mollie-payments.de-DE.json

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
"captionSubtotal": "Zwischensumme",
6464
"captionTaxes": "Steuern",
6565
"paymentError": "Die Zahlung mit Apple Pay ist fehlgeschlagen."
66+
},
67+
"paypalExpress": {
68+
"paymentError": "Die Zahlung mit Paypal Express ist fehlgeschlagen."
6669
}
6770
},
6871
"subscriptions": {

src/Resources/snippet/en_GB/mollie-payments.en-GB.json

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
"captionSubtotal": "Subtotal",
6464
"captionTaxes": "Taxes",
6565
"paymentError": "The payment with Apple Pay failed."
66+
},
67+
"paypalExpress": {
68+
"paymentError": "The payment with Paypal Express failed."
6669
}
6770
},
6871
"subscriptions": {

src/Resources/snippet/it_IT/mollie-payments.it-IT.json

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
"captionSubtotal": "Subtotale",
6464
"captionTaxes": "Tasse",
6565
"paymentError": "Il pagamento con Apple Pay non è andato a buon fine."
66+
},
67+
"paypalExpress": {
68+
"paymentError": "Il pagamento con Paypal Express non è andato a buon fine."
6669
}
6770
},
6871
"subscriptions": {

src/Resources/snippet/nl_NL/mollie-payments.nl-NL.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
"captionSubtotal": "Subtotaal",
6464
"captionTaxes": "BTW",
6565
"paymentError": "De betaling met Apple Pay is mislukt."
66-
}
66+
},
67+
"paypalExpress": {
68+
"paymentError": "De betaling met Paypal Express is mislukt."
69+
}
6770
},
6871
"subscriptions": {
6972
"account": {

src/Resources/views/mollie/component/paypal-express-button.twig

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<button name="paypal-express" class="mollie-paypal-button mollie-express-button paypal-button-{{ shape }} paypal-theme-{{ theme }}" data-form-action="{{ path('frontend.mollie.paypal-express.start') }}">
3636
<img src="{{ image }}" width="80px;"/>
3737
<p style="font-weight: 100;margin:0;margin-left:8px">Checkout</p>
38+
<div class="loader">
39+
40+
</div>
3841
</button>
3942
</div>
4043
{% endblock %}

tests/PHPUnit/Fakes/Repositories/FakePaymentMethodRepository.php

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
1212
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
1313
use Shopware\Core\Framework\Event\NestedEventCollection;
14+
use Shopware\Core\System\SalesChannel\SalesChannelContext;
1415

1516
class FakePaymentMethodRepository implements PaymentMethodRepositoryInterface
1617
{
@@ -84,4 +85,10 @@ public function getActiveApplePayID(Context $context): string
8485
{
8586
return 'phpunit-id';
8687
}
88+
89+
public function getActivePaypalExpressID(SalesChannelContext $context): string
90+
{
91+
return 'phpunit-id';
92+
}
93+
8794
}

0 commit comments

Comments
 (0)