-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from buckaroo-it/BP-3490-Add-a-Bancontact-opt…
…ion-to-let-consumer-fill-in-card-information-in-the-Shopware-checkout-instead-of-an-redirect Bp 3490 add a bancontact option to let consumer fill in card information in the shopware checkout instead of an redirect
- Loading branch information
Showing
12 changed files
with
401 additions
and
169 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
128 changes: 128 additions & 0 deletions
128
src/Resources/app/storefront/src/bancontact/buckaroo-payment.bancontact.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,128 @@ | ||
import Plugin from 'src/plugin-system/plugin.class'; | ||
|
||
export default class BuckarooPaymentBancontact extends Plugin { | ||
init() | ||
{ | ||
|
||
this._listenToSubmit(); | ||
this._createScript(() => { | ||
const bancontactmrcashInputs = [ 'bancontactmrcash_cardholdername', 'bancontactmrcash_cardnumber', 'bancontactmrcash_expirationmonth', 'bancontactmrcash_expirationyear']; | ||
for (const fieldId of bancontactmrcashInputs) { | ||
const field = document.getElementById(fieldId); | ||
if (field) { | ||
field.addEventListener('change', this._handleInputChanged.bind(this)); | ||
} | ||
} | ||
this._getEncryptedData(); | ||
}); | ||
} | ||
|
||
_createScript(callback) | ||
{ | ||
const url = 'https://static.buckaroo.nl/script/ClientSideEncryption001.js'; | ||
const script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = url; | ||
script.addEventListener('load', callback.bind(this), false); | ||
document.head.appendChild(script); | ||
} | ||
|
||
_getEncryptedData() | ||
{ | ||
const getEncryptedData = function (cardNumber, year, month, cardholder) { | ||
window.BuckarooClientSideEncryption.V001.encryptCardData( | ||
cardNumber, | ||
year, | ||
month, | ||
'', | ||
cardholder, | ||
function (encryptedCardData) { | ||
const encryptedCardDataInput = document.getElementById('encryptedCardData'); | ||
if (encryptedCardDataInput) { | ||
encryptedCardDataInput.value = encryptedCardData; | ||
} | ||
} | ||
); | ||
}; | ||
const bancontactmrcash_cardnumber = document.getElementById('bancontactmrcash_cardnumber'); | ||
const bancontactmrcash_expirationyear = document.getElementById('bancontactmrcash_expirationyear'); | ||
const bancontactmrcash_expirationmonth = document.getElementById('bancontactmrcash_expirationmonth'); | ||
const bancontactmrcash_cardholdername = document.getElementById('bancontactmrcash_cardholdername'); | ||
if (bancontactmrcash_cardnumber && bancontactmrcash_expirationyear && bancontactmrcash_expirationmonth && bancontactmrcash_cardholdername) { | ||
getEncryptedData(bancontactmrcash_cardnumber.value, bancontactmrcash_expirationyear.value, bancontactmrcash_expirationmonth.value, bancontactmrcash_cardholdername.value); | ||
} | ||
} | ||
|
||
_handleInputChanged(event) | ||
{ | ||
this._CheckValidate(); | ||
this._getEncryptedData(); | ||
} | ||
|
||
_handleCheckField(field) | ||
{ | ||
document.getElementById(field.id + 'Error').style.display = 'none'; | ||
switch (field.id) { | ||
case 'bancontactmrcash_cardnumber': | ||
if (!window.BuckarooClientSideEncryption.V001.validateCardNumber(field.value.replace(/\s+/g, ''))) { | ||
document.getElementById(field.id + 'Error').style.display = 'block'; | ||
return false; | ||
} | ||
break; | ||
case 'bancontactmrcash_cardholdername': | ||
if (!window.BuckarooClientSideEncryption.V001.validateCardholderName(field.value)) { | ||
document.getElementById(field.id + 'Error').style.display = 'block'; | ||
return false; | ||
} | ||
break; | ||
case 'bancontactmrcash_expirationmonth': | ||
if (!window.BuckarooClientSideEncryption.V001.validateMonth(field.value)) { | ||
document.getElementById(field.id + 'Error').style.display = 'block'; | ||
return false; | ||
} | ||
break; | ||
case 'bancontactmrcash_expirationyear': | ||
if (!window.BuckarooClientSideEncryption.V001.validateYear(field.value)) { | ||
document.getElementById(field.id + 'Error').style.display = 'block'; | ||
return false; | ||
} | ||
break; | ||
default: | ||
} | ||
return true; | ||
} | ||
|
||
_CheckValidate() | ||
{ | ||
let not_valid = false; | ||
const buckarooInputs = ['bancontactmrcash_cardholdername', 'bancontactmrcash_cardnumber', 'bancontactmrcash_expirationmonth', 'bancontactmrcash_expirationyear']; | ||
for (const fieldId of buckarooInputs) { | ||
const field = document.getElementById(fieldId); | ||
if (field) { | ||
if (!this._handleCheckField(field)) { | ||
not_valid = true; | ||
} | ||
} | ||
} | ||
return this._disableConfirmFormSubmit(not_valid); | ||
} | ||
|
||
_disableConfirmFormSubmit(disable) | ||
{ | ||
const field = document.getElementById('confirmFormSubmit'); | ||
if (field) { | ||
document.getElementById('confirmFormSubmit').disabled = disable; | ||
} | ||
return disable; | ||
} | ||
_validateOnSubmit(e) | ||
{ | ||
e.preventDefault(); | ||
let valid = !this._CheckValidate(); | ||
document.$emitter.publish('buckaroo_payment_validate', {valid, type:'bancontactmrcash'}); | ||
} | ||
_listenToSubmit() | ||
{ | ||
document.$emitter.subscribe('buckaroo_payment_submit', this._validateOnSubmit.bind(this)) | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 23 additions & 83 deletions
106
src/Resources/public/administration/static/sepa-credittransfer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.