PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / stripe / js / connect_settings.js

connect_settings.js in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, at stripe/js/connect_settings.js

120 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function() {
2 function setupStripeConnectListener() {
3 onclickPreventDefault( '.frm_disconnect_stripe', handleStripeDisconnectClick );
4 onclickPreventDefault( '.frm_reauth_stripe', handleStripeReauthClick );
5 onclickPreventDefault( '.frm_connect_with_oauth', handleConnectWithOauth );
6 renderStripeConnectSettingsButton();
7 }
8
9 function renderStripeConnectSettingsButton() {
10 const container = document.getElementById( 'frm_strp_settings_container' );
11 if ( container ) {
12 postAjax(
13 {
14 action: 'frm_strp_connect_get_settings_button'
15 },
16 function( data ) {
17 container.innerHTML = data.html;
18 }
19 );
20 }
21 }
22
23 function onclickPreventDefault( selector, callback ) {
24 jQuery( document ).on( 'click', selector, function( event ) {
25 event.preventDefault();
26 callback( this );
27 } );
28 }
29
30 function handleStripeDisconnectClick( trigger ) {
31 const testMode = isTriggerInTestMode( trigger );
32 const spinner = frmDom.span( { className: 'frm-wait frm_visible_spinner' } );
33
34 spinner.style.margin = 0; // The default 20px margin causes the spinner to look bad.
35 trigger.replaceWith( spinner );
36
37 strpSettingsAjaxRequest(
38 'frm_stripe_connect_disconnect',
39 function() {
40 renderStripeConnectSettingsButton();
41 },
42 testMode
43 );
44 }
45
46 function handleStripeReauthClick( trigger ) {
47 strpSettingsAjaxRequest(
48 'frm_stripe_connect_reauth',
49 function( data ) {
50 if ( data.connect_url !== undefined ) {
51 window.location = data.connect_url;
52 } else {
53 renderStripeConnectSettingsButton();
54 }
55 },
56 isTriggerInTestMode( trigger )
57 );
58 }
59
60 function handleConnectWithOauth( trigger ) {
61 trigger.classList.add( 'frm_loading_button' );
62 strpSettingsAjaxRequest(
63 'frm_stripe_connect_oauth',
64 function( data ) {
65 if ( data.redirect_url !== undefined ) {
66 window.location = data.redirect_url;
67 } else {
68 renderStripeConnectSettingsButton();
69 }
70 },
71 isTriggerInTestMode( trigger )
72 );
73 }
74
75 function strpSettingsAjaxRequest( action, success, testMode ) {
76 const data = {
77 action,
78 testMode,
79 nonce: frmGlobal.nonce
80 };
81 postAjax( data, success );
82 }
83
84 function postAjax( data, success ) {
85 const xmlHttp = new XMLHttpRequest();
86 const params = typeof data === 'string' ? data : Object.keys( data ).map(
87 function( k ) {
88 return `${ encodeURIComponent( k ) }=${ encodeURIComponent( data[ k ] ) }`;
89 }
90 ).join( '&' );
91
92 xmlHttp.open( 'post', ajaxurl, true );
93 xmlHttp.onreadystatechange = function() {
94 let response;
95 if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) {
96 response = xmlHttp.responseText;
97 if ( response !== '' ) {
98 response = JSON.parse( response );
99 if ( response.success ) {
100 if ( response.data === undefined ) {
101 response.data = {};
102 }
103 success( response.data );
104 }
105 }
106 }
107 };
108 xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );
109 xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
110 xmlHttp.send( params );
111 return xmlHttp;
112 }
113
114 function isTriggerInTestMode( trigger ) {
115 return parseInt( jQuery( trigger ).closest( '[data-test-mode]' ).attr( 'data-test-mode' ) );
116 }
117
118 jQuery( document ).ready( setupStripeConnectListener );
119 }() );
120