Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Dec 1, 2023
1 parent 79861d5 commit 506d8ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
56 changes: 38 additions & 18 deletions js/src/mollie.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
/* global Mollie */
( function () {
function init( data ) {
const mollie = Mollie( data.profileId, data.options );
const element = document.getElementById( data.elementId );

const tokenElement = document.getElementById( data.elementId );

if ( ! tokenElement ) {
if ( ! element ) {
throw new Error( 'No data token element.' );
}

if ( ! tokenElement.form ) {
if ( ! element.form ) {
throw new Error( 'Data token element not in form.' );
}

const form = tokenElement.form;
const form = element.form;

async function createToken( e ) {
e.preventDefault();
if ( ! form.mollie ) {
form.mollie = Mollie( data.profileId, data.options );

const { token } = await mollie.createToken();
async function createToken( e ) {
const tokenElement = document.getElementById( data.elementId );

if ( token ) {
tokenElement.value = token;
}
if ( ! tokenElement ) {
return;
}

e.preventDefault();

const { token, error } = await form.mollie.createToken();

if ( error ) {
console.log( error );
}

form.removeEventListener( 'submit', createToken );
if ( token ) {
tokenElement.value = token;
}

form.requestSubmit( e.submitter );
form.requestSubmit( e.submitter );

form.addEventListener( 'submit', createToken );
form.addEventListener( 'submit', createToken, {
once: true,
} );
}

form.addEventListener( 'submit', createToken, {
once: true,
} );
}

form.addEventListener( 'submit', createToken );
if ( form.mollieCardComponent ) {
form.mollieCardComponent.unmount();
}

const cardComponent = mollie.createComponent( 'card' );
if ( ! form.mollieCardComponent ) {
form.mollieCardComponent = form.mollie.createComponent( 'card' );
}

cardComponent.mount( data.mount );
form.mollieCardComponent.mount( data.mount );
}

window.pronamicPayMollieFields = window.pronamicPayMollieFields || [];
Expand Down
2 changes: 1 addition & 1 deletion src/CardField.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setup(): void {
\hash_file( 'crc32b', __DIR__ . '/' . $file ),
);

$file = '../js/dist/mollie.min.js';
$file = '../js/src/mollie.js';

\wp_register_script(
'pronamic-pay-mollie',
Expand Down

0 comments on commit 506d8ed

Please sign in to comment.