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: some changes #888

Merged
merged 1 commit into from
Nov 8, 2024
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
2 changes: 1 addition & 1 deletion src/Components/PaypalExpress/PayPalExpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function isPaypalExpressEnabled(SalesChannelContext $context): bool
*/
public function getActivePaypalExpressID(SalesChannelContext $context): string
{
return $this->repoPaymentMethods->getActivePaypalExpressID($context->getContext());
return $this->repoPaymentMethods->getActivePaypalExpressID($context);
}


Expand Down
5 changes: 3 additions & 2 deletions src/Components/PaypalExpress/Route/FinishCheckoutRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function finishCheckout(SalesChannelContext $context): FinishCheckoutResp
);
}

# create new account or find existing and login
$this->paypalExpress->prepareCustomer($shippingAddress, $context, $acceptedDataProtection, $billingAddress);

# we have to update the cart extension before a new user is created and logged in, otherwise the extension is not saved
$cartExtension = new ArrayStruct([
CustomFieldsInterface::PAYPAL_EXPRESS_AUTHENTICATE_ID => $payPalExpressSession->authenticationId
Expand All @@ -130,8 +133,6 @@ public function finishCheckout(SalesChannelContext $context): FinishCheckoutResp
$this->cartService->persistCart($cart, $context);


# create new account or find existing and login
$this->paypalExpress->prepareCustomer($shippingAddress, $context, $acceptedDataProtection, $billingAddress);
return new FinishCheckoutResponse($payPalExpressSession->id, $payPalExpressSession->authenticationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class PaypalExpressControllerBase extends StorefrontController
{
use RedirectTrait;

private const SNIPPET_ERROR = 'molliePayments.payments.paypalExpress.paymentError';
/**
* @var RouterInterface
*/
Expand Down Expand Up @@ -67,6 +67,7 @@ public function startCheckout(Request $request, SalesChannelContext $context): R
$redirectUrl = $responseRedirectUrl;
}
} catch (\Throwable $e) {
$this->addFlash('danger', $this->trans(self::SNIPPET_ERROR));
$this->logger->error(
'Failed to start Paypal Express checkout',
['message' => $e->getMessage()]
Expand All @@ -82,6 +83,7 @@ public function cancelCheckout(SalesChannelContext $context): Response
try {
$this->cancelCheckoutRoute->cancelCheckout($context);
} catch (\Throwable $e) {
$this->addFlash('danger', $this->trans(self::SNIPPET_ERROR));
$this->logger->error(
'Failed to cancel Paypal Express checkout',
['message' => $e->getMessage()]
Expand All @@ -102,6 +104,7 @@ public function finishCheckout(SalesChannelContext $context): Response
$returnUrl = $this->getCheckoutConfirmPage($this->router);
} catch (\Throwable $e) {
$returnUrl = $this->getCheckoutCartPage($this->router);
$this->addFlash('danger', $this->trans(self::SNIPPET_ERROR));
$this->logger->error(
'Failed to finish Paypal Express Checkout',
['message' => $e->getMessage()]
Expand Down
9 changes: 6 additions & 3 deletions src/Repository/PaymentMethod/PaymentMethodRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class PaymentMethodRepository implements PaymentMethodRepositoryInterface
{
Expand Down Expand Up @@ -80,18 +81,20 @@ public function getActiveApplePayID(Context $context): string
}

/**
* @param Context $context
* @param SalesChannelContext $context
* @throws \Exception
* @return string
*/
public function getActivePaypalExpressID(Context $context): string
public function getActivePaypalExpressID(SalesChannelContext $context): string
{
$criteria = new Criteria();
$criteria->addAssociation('salesChannels');
$criteria->addFilter(new EqualsFilter('handlerIdentifier', PayPalExpressPayment::class));
$criteria->addFilter(new EqualsFilter('active', true));
$criteria->addFilter(new EqualsFilter('salesChannels.id', $context->getSalesChannelId()));

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

if (count($paymentMethods) <= 0) {
throw new \Exception('Payment Method PayPal Express not found in system');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

interface PaymentMethodRepositoryInterface
{
Expand Down Expand Up @@ -37,4 +38,10 @@ public function search(Criteria $criteria, Context $context): EntitySearchResult
* @return string
*/
public function getActiveApplePayID(Context $context): string;

/**
* @param SalesChannelContext $context
* @return string
*/
public function getActivePaypalExpressID(SalesChannelContext $context): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class MollieApplePayDirect extends Plugin {
}

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

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class MollieExpressActions extends Plugin {
}



const buyButtonRepository = new BuyButtonRepository();

expressButtons.forEach((button) => {
Expand Down Expand Up @@ -100,15 +99,14 @@ export class MollieExpressActions extends Plugin {
return;
}
}

target.classList.add('processed');

const expressAddToCart = new ExpressAddToCart();

expressAddToCart.addItemToCart(target);

target.classList.add('processed');
const mollieEvent = new event.constructor(event.type, event);
target.dispatchEvent(mollieEvent);
target.classList.remove('processed');

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

const me = this;
var shippingFields = [
Expand Down Expand Up @@ -166,6 +167,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,dataProtectionValue);
clickedButton.classList.remove('processed');
};

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

return session;
Expand Down
1 change: 1 addition & 0 deletions src/Resources/app/storefront/src/scss/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
@import "./account/subscriptions";
@import "./component/credit-card-mandate";
@import "./component/paypal-express-button";
@import "./component/express-button";
@import "./display";
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.mollie-express-button.processed {


.loader {
display: block;
position:absolute;
}
*:not(.loader){
opacity:0.2;
}

}

.mollie-express-button .loader {
display: none;
}
3 changes: 3 additions & 0 deletions src/Resources/snippet/de_DE/mollie-payments.de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"captionSubtotal": "Zwischensumme",
"captionTaxes": "Steuern",
"paymentError": "Die Zahlung mit Apple Pay ist fehlgeschlagen."
},
"paypalExpress": {
"paymentError": "Die Zahlung mit Paypal Express ist fehlgeschlagen."
}
},
"subscriptions": {
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/snippet/en_GB/mollie-payments.en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"captionSubtotal": "Subtotal",
"captionTaxes": "Taxes",
"paymentError": "The payment with Apple Pay failed."
},
"paypalExpress": {
"paymentError": "The payment with Paypal Express failed."
}
},
"subscriptions": {
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/snippet/it_IT/mollie-payments.it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"captionSubtotal": "Subtotale",
"captionTaxes": "Tasse",
"paymentError": "Il pagamento con Apple Pay non è andato a buon fine."
},
"paypalExpress": {
"paymentError": "Il pagamento con Paypal Express non è andato a buon fine."
}
},
"subscriptions": {
Expand Down
5 changes: 4 additions & 1 deletion src/Resources/snippet/nl_NL/mollie-payments.nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
"captionSubtotal": "Subtotaal",
"captionTaxes": "BTW",
"paymentError": "De betaling met Apple Pay is mislukt."
}
},
"paypalExpress": {
"paymentError": "De betaling met Paypal Express is mislukt."
}
},
"subscriptions": {
"account": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<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') }}">
<img src="{{ image }}" width="80px;"/>
<p style="font-weight: 100;margin:0;margin-left:8px">Checkout</p>
<div class="loader">

</div>
</button>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
use Shopware\Core\Framework\Event\NestedEventCollection;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class FakePaymentMethodRepository implements PaymentMethodRepositoryInterface
{
Expand Down Expand Up @@ -84,4 +85,10 @@ public function getActiveApplePayID(Context $context): string
{
return 'phpunit-id';
}

public function getActivePaypalExpressID(SalesChannelContext $context): string
{
return 'phpunit-id';
}

}
Loading