-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vitalij Mik
committed
Oct 21, 2024
1 parent
6673e0e
commit 38e1cf6
Showing
26 changed files
with
320 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/Resources/app/storefront/src/mollie-payments/plugins/mollie-express-actions.plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import Plugin from '../Plugin'; | ||
import PrivacyNoteElement from '../repository/PrivacyNoteElement'; | ||
import BuyButtonRepository from '../repository/BuyButtonRepository'; | ||
import ExpressButtonsRepository from '../repository/ExpressButtonsRepository'; | ||
import ExpressAddToCart from '../services/ExpressAddToCart'; | ||
|
||
export const MOLLIE_EXPRESS_CHECKOUT_EVENT = 'MollieStartExpressCheckout'; | ||
|
||
export class MollieExpressActions extends Plugin { | ||
|
||
|
||
init() { | ||
|
||
const pluginOffCanvasInstances = window.PluginManager.getPluginList().OffCanvasCart.get('instances'); | ||
if (pluginOffCanvasInstances.length > 0) { | ||
pluginOffCanvasInstances.forEach((pluginOffCanvas) => { | ||
pluginOffCanvas.$emitter.subscribe('offCanvasOpened', this.bindEvents.bind(this)); | ||
}); | ||
} | ||
|
||
this.bindEvents(); | ||
|
||
} | ||
|
||
bindEvents() { | ||
const expressButtonsRepository = new ExpressButtonsRepository(); | ||
const expressButtons = expressButtonsRepository.findAll(); | ||
|
||
if (expressButtons.length === 0) { | ||
return; | ||
} | ||
|
||
const buyButtonRepository = new BuyButtonRepository(); | ||
|
||
expressButtons.forEach((button) => { | ||
|
||
|
||
button.classList.remove('d-none'); | ||
button.addEventListener('click', this.onButtonClick) | ||
|
||
const buyButton = buyButtonRepository.find(button); | ||
if (!(buyButton instanceof HTMLButtonElement)) { | ||
return; | ||
} | ||
|
||
if (buyButton.hasAttribute('disabled')) { | ||
button.classList.add('d-none'); | ||
button.removeEventListener('click', this.onButtonClick) | ||
} | ||
|
||
const buyButtonForm = buyButton.closest('form'); | ||
if (!(buyButtonForm instanceof HTMLFormElement)) { | ||
return; | ||
} | ||
|
||
buyButtonForm.addEventListener('change', () => { | ||
|
||
button.classList.remove('d-none'); | ||
button.addEventListener('click', this.onButtonClick) | ||
|
||
if (buyButton.hasAttribute('disabled')) { | ||
|
||
button.classList.add('d-none'); | ||
button.removeEventListener('click', this.onButtonClick) | ||
} | ||
}) | ||
|
||
}); | ||
} | ||
|
||
async onButtonClick(event) { | ||
let target = event.target; | ||
if (!(target instanceof HTMLButtonElement)) { | ||
target = target.closest('button'); | ||
} | ||
|
||
const privacyNote = new PrivacyNoteElement(); | ||
|
||
const privacyNoteElement = privacyNote.find(target); | ||
|
||
if (privacyNoteElement instanceof HTMLDivElement) { | ||
privacyNoteElement.classList.add('was-validated'); | ||
const isValid = privacyNote.validate(privacyNoteElement); | ||
if (isValid === false) { | ||
return; | ||
} | ||
} | ||
const mollieEvent = new Event(MOLLIE_EXPRESS_CHECKOUT_EVENT); | ||
|
||
const expressAddToCart = new ExpressAddToCart(); | ||
await expressAddToCart.addItemToCart(target).then(() => { | ||
target.dispatchEvent(mollieEvent); | ||
}); | ||
} | ||
} |
Oops, something went wrong.