admin-builder-modern-stripe.js
1 year ago
admin-builder-modern-stripe.min.js
1 year ago
admin-builder-stripe-card-field.js
1 year ago
admin-builder-stripe-card-field.min.js
1 year ago
admin-builder-stripe.js
1 year ago
admin-builder-stripe.min.js
1 year ago
admin-settings-stripe.js
1 year ago
admin-settings-stripe.min.js
1 year ago
wpforms-stripe-elements.js
1 year ago
wpforms-stripe-elements.min.js
1 year ago
wpforms-stripe-payment-element.js
1 year ago
wpforms-stripe-payment-element.min.js
1 year ago
admin-builder-stripe.js
201 lines
| 1 | /* global wpforms_builder, wpforms_builder_stripe */ |
| 2 | |
| 3 | /** |
| 4 | * Stripe builder function. |
| 5 | * |
| 6 | * @since 1.8.2 |
| 7 | */ |
| 8 | |
| 9 | const WPFormsStripe = window.WPFormsStripe || ( function( document, window, $ ) { |
| 10 | /** |
| 11 | * Public functions and properties. |
| 12 | * |
| 13 | * @since 1.8.2 |
| 14 | * |
| 15 | * @type {Object} |
| 16 | */ |
| 17 | const app = { |
| 18 | |
| 19 | /** |
| 20 | * Start the engine. |
| 21 | * |
| 22 | * @since 1.8.2 |
| 23 | */ |
| 24 | init() { |
| 25 | $( app.ready ); |
| 26 | }, |
| 27 | |
| 28 | /** |
| 29 | * Initialized once the DOM is fully loaded. |
| 30 | * |
| 31 | * @since 1.8.2 |
| 32 | */ |
| 33 | ready() { |
| 34 | if ( ! app.isLegacySettings() ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | app.settingsDisplay(); |
| 39 | app.settingsConditions(); |
| 40 | |
| 41 | app.bindUIActions(); |
| 42 | }, |
| 43 | |
| 44 | /** |
| 45 | * Process various events as a response to UI interactions. |
| 46 | * |
| 47 | * @since 1.8.2 |
| 48 | */ |
| 49 | bindUIActions() { |
| 50 | $( document ) |
| 51 | .on( 'wpformsFieldDelete', app.disableNotifications ) |
| 52 | .on( 'wpformsSaved', app.requiredFieldsCheck ) |
| 53 | .on( 'wpformsFieldUpdate', app.settingsDisplay ) |
| 54 | .on( 'wpformsFieldUpdate', app.settingsConditions ); |
| 55 | }, |
| 56 | |
| 57 | /** |
| 58 | * Toggles visibility of the Stripe settings. |
| 59 | * |
| 60 | * If a credit card field has been added then reveal the settings, |
| 61 | * otherwise hide them. |
| 62 | * |
| 63 | * @since 1.8.2 |
| 64 | */ |
| 65 | settingsDisplay() { |
| 66 | const $alert = $( '#wpforms-stripe-credit-card-alert' ); |
| 67 | const $content = $( '#stripe-provider' ); |
| 68 | |
| 69 | // Check if any Credit Card fields were added to the form. |
| 70 | const ccFieldsAdded = wpforms_builder_stripe.field_slugs.filter( function( fieldSlug ) { |
| 71 | const $el = $( '.wpforms-field-option-' + fieldSlug ); |
| 72 | |
| 73 | return $el.length ? $el : null; |
| 74 | } ); |
| 75 | |
| 76 | if ( ccFieldsAdded.length ) { |
| 77 | $alert.hide(); |
| 78 | $content.find( '#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2' ).show(); |
| 79 | } else { |
| 80 | $alert.show(); |
| 81 | $content.find( '#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2' ).hide(); |
| 82 | $content.find( '#wpforms-panel-field-stripe-enable' ).prop( 'checked', false ); |
| 83 | } |
| 84 | }, |
| 85 | |
| 86 | /** |
| 87 | * Toggles the visibility of the related settings. |
| 88 | * |
| 89 | * @since 1.8.2 |
| 90 | */ |
| 91 | settingsConditions() { |
| 92 | $( '#wpforms-panel-field-stripe-enable' ).conditions( { |
| 93 | conditions: { |
| 94 | element: '#wpforms-panel-field-stripe-enable', |
| 95 | type: 'checked', |
| 96 | operator: 'is', |
| 97 | }, |
| 98 | actions: { |
| 99 | if: { |
| 100 | element: '.wpforms-panel-content-section-stripe-body', |
| 101 | action: 'show', |
| 102 | }, |
| 103 | else: { |
| 104 | element: '.wpforms-panel-content-section-stripe-body', |
| 105 | action: 'hide', |
| 106 | }, |
| 107 | }, |
| 108 | effect: 'appear', |
| 109 | } ); |
| 110 | |
| 111 | $( '#wpforms-panel-field-stripe-recurring-enable' ).conditions( { |
| 112 | conditions: { |
| 113 | element: '#wpforms-panel-field-stripe-recurring-enable', |
| 114 | type: 'checked', |
| 115 | operator: 'is', |
| 116 | }, |
| 117 | actions: { |
| 118 | if: { |
| 119 | element: '#wpforms-panel-field-stripe-recurring-period-wrap,#wpforms-panel-field-stripe-recurring-conditional_logic-wrap,#wpforms-conditional-groups-payments-stripe-recurring,#wpforms-panel-field-stripe-recurring-email-wrap,#wpforms-panel-field-stripe-recurring-name-wrap', |
| 120 | action: 'show', |
| 121 | }, |
| 122 | else: { |
| 123 | element: '#wpforms-panel-field-stripe-recurring-period-wrap,#wpforms-panel-field-stripe-recurring-conditional_logic-wrap,#wpforms-conditional-groups-payments-stripe-recurring,#wpforms-panel-field-stripe-recurring-email-wrap,#wpforms-panel-field-stripe-recurring-name-wrap', |
| 124 | action: 'hide', |
| 125 | }, |
| 126 | }, |
| 127 | effect: 'appear', |
| 128 | } ); |
| 129 | }, |
| 130 | |
| 131 | /** |
| 132 | * On form save notify users about required fields. |
| 133 | * |
| 134 | * @since 1.8.2 |
| 135 | */ |
| 136 | requiredFieldsCheck() { |
| 137 | if ( |
| 138 | ! $( '#wpforms-panel-field-stripe-enable' ).is( ':checked' ) || |
| 139 | ! $( '#wpforms-panel-field-stripe-recurring-enable' ).is( ':checked' ) |
| 140 | ) { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | if ( $( '#wpforms-panel-field-stripe-recurring-email' ).val() ) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | $.alert( { |
| 149 | title: wpforms_builder.heads_up, |
| 150 | content: wpforms_builder.stripe_recurring_email, |
| 151 | icon: 'fa fa-exclamation-circle', |
| 152 | type: 'orange', |
| 153 | buttons: { |
| 154 | confirm: { |
| 155 | text: wpforms_builder.ok, |
| 156 | btnClass: 'btn-confirm', |
| 157 | keys: [ 'enter' ], |
| 158 | }, |
| 159 | }, |
| 160 | } ); |
| 161 | }, |
| 162 | |
| 163 | /** |
| 164 | * Disable notifications. |
| 165 | * |
| 166 | * @since 1.8.2 |
| 167 | * |
| 168 | * @param {Object} e Event object. |
| 169 | * @param {number} id Field ID. |
| 170 | * @param {string} type Field type. |
| 171 | */ |
| 172 | disableNotifications( e, id, type ) { |
| 173 | if ( ! wpforms_builder_stripe.field_slugs.includes( type ) ) { |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | const $notificationWrap = $( '.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]' ); |
| 178 | |
| 179 | $notificationWrap.find( 'input[id*="-stripe"]' ).prop( 'checked', false ); |
| 180 | $notificationWrap.addClass( 'wpforms-hidden' ); |
| 181 | }, |
| 182 | |
| 183 | /** |
| 184 | * Determine is legacy settings is loaded. |
| 185 | * |
| 186 | * @since 1.8.4 |
| 187 | * |
| 188 | * @return {boolean} True is legacy settings loaded. |
| 189 | */ |
| 190 | isLegacySettings() { |
| 191 | return $( '#wpforms-panel-field-stripe-enable' ).length; |
| 192 | }, |
| 193 | }; |
| 194 | |
| 195 | // Provide access to public functions/properties. |
| 196 | return app; |
| 197 | }( document, window, jQuery ) ); |
| 198 | |
| 199 | // Initialize. |
| 200 | WPFormsStripe.init(); |
| 201 |