Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
@@ -0,0 +1,346 @@
|
||||
/* global wpforms_builder, wpforms_builder_stripe */
|
||||
|
||||
/**
|
||||
* Stripe builder function.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
const WPFormsStripeModernBuilder = window.WPFormsStripeModernBuilder || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Elements holder.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
let el = {};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialized once the DOM is fully loaded.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
ready() {
|
||||
if ( app.isLegacySettings() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache DOM elements.
|
||||
el = {
|
||||
$alert: $( '#wpforms-stripe-credit-card-alert' ),
|
||||
$panelContent: $( '#wpforms-panel-content-section-payment-stripe' ),
|
||||
$feeNotice: $( '.wpforms-stripe-notice-info' ),
|
||||
};
|
||||
|
||||
app.bindUIActions();
|
||||
|
||||
if ( ! wpforms_builder_stripe.is_pro ) {
|
||||
const toggleInput = '.wpforms-panel-content-section-payment-toggle input',
|
||||
planNameInput = '.wpforms-panel-content-section-payment-plan-name input';
|
||||
|
||||
$( toggleInput ).each( app.toggleContent );
|
||||
$( planNameInput ).each( app.checkPlanName );
|
||||
|
||||
$( '#wpforms-panel-payments' )
|
||||
.on( 'click', toggleInput, app.toggleContent )
|
||||
.on( 'click', '.wpforms-panel-content-section-payment-plan-head-buttons-toggle', app.togglePlan )
|
||||
.on( 'click', '.wpforms-panel-content-section-payment-plan-head-buttons-delete', app.deletePlan )
|
||||
.on( 'input', planNameInput, app.renamePlan )
|
||||
.on( 'focusout', planNameInput, app.checkPlanName );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Process various events as a response to UI interactions.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
bindUIActions() {
|
||||
const $builder = $( '#wpforms-builder' );
|
||||
|
||||
$builder.on( 'wpformsFieldDelete', app.disableNotifications )
|
||||
.on( 'wpformsSaved', app.requiredFieldsCheck )
|
||||
.on( 'wpformsFieldAdd', app.fieldAdded )
|
||||
.on( 'wpformsFieldDelete', app.fieldDeleted )
|
||||
.on( 'wpformsPaymentsPlanCreated', app.toggleMultiplePlansWarning )
|
||||
.on( 'wpformsPaymentsPlanDeleted', app.toggleMultiplePlansWarning );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users about required fields.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
requiredFieldsCheck() {
|
||||
if ( ! $( '#wpforms-panel-field-stripe-enable_recurring' ).is( ':checked' ) || el.$panelContent.hasClass( 'wpforms-hidden' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$panelContent.find( '.wpforms-panel-content-section-payment-plan' ).each( function() {
|
||||
const $plan = $( this ),
|
||||
planId = $plan.data( 'plan-id' );
|
||||
|
||||
if ( ! $plan.find( `#wpforms-panel-field-stripe-recurring-${ planId }-email` ).val() ) {
|
||||
app.recurringEmailAlert();
|
||||
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Show alert for required recurring email field.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
recurringEmailAlert() {
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_recurring_email,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable notifications.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
disableNotifications( e, id, type ) {
|
||||
if ( ! app.isStripeField( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $notificationWrap = $( '.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]' );
|
||||
|
||||
$notificationWrap.find( 'input[id*="-stripe"]' ).prop( 'checked', false );
|
||||
$notificationWrap.addClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determinate is legacy settings is loaded.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @return {boolean} True is legacy settings loaded.
|
||||
*/
|
||||
isLegacySettings() {
|
||||
return $( '#wpforms-panel-field-stripe-enable' ).length;
|
||||
},
|
||||
|
||||
/**
|
||||
* We have to do several actions when the "Stripe" field is added.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
fieldAdded( e, id, type ) {
|
||||
if ( ! app.isStripeField( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.settingsToggle( true );
|
||||
el.$feeNotice.toggleClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* We have to do several actions when the "Stripe" field is deleted.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
fieldDeleted( e, id, type ) {
|
||||
if ( ! app.isStripeField( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.settingsToggle( false );
|
||||
el.$feeNotice.toggleClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determinate if field type is Stripe credit card.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {string} type Field type.
|
||||
*
|
||||
* @return {boolean} True if Stripe field.
|
||||
*/
|
||||
isStripeField( type ) {
|
||||
return wpforms_builder_stripe.field_slugs.includes( type );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles visibility of multiple plans warning.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
toggleMultiplePlansWarning() {
|
||||
el.$panelContent.find( '.wpforms-stripe-multiple-plans-warning' ).toggleClass( 'wpforms-hidden', el.$panelContent.find( '.wpforms-panel-content-section-payment-plan' ).length === 1 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles visibility of the Stripe addon settings.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {boolean} display Show or hide settings.
|
||||
*/
|
||||
settingsToggle( display ) {
|
||||
if (
|
||||
! el.$alert.length &&
|
||||
! el.$panelContent.length
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$alert.toggleClass( 'wpforms-hidden', display );
|
||||
el.$panelContent.toggleClass( 'wpforms-hidden', ! display );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle payments content.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
toggleContent() {
|
||||
const $input = $( this );
|
||||
|
||||
if (
|
||||
$( '#wpforms-panel-field-stripe-enable_recurring' ).is( ':checked' ) &&
|
||||
$( '#wpforms-panel-field-stripe-enable_one_time' ).is( ':checked' )
|
||||
) {
|
||||
$input.prop( 'checked', false );
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: $input.attr( 'id' ) === 'wpforms-panel-field-stripe-enable_recurring' ? wpforms_builder_stripe.disabled_recurring : wpforms_builder_stripe.disabled_one_time,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
|
||||
$input.prop( 'checked', false );
|
||||
}
|
||||
|
||||
const $wrapper = $input.closest( '.wpforms-panel-content-section-payment' ),
|
||||
isChecked = $input.prop( 'checked' ) && ! $( '#wpforms-panel-field-settings-disable_entries' ).prop( 'checked' );
|
||||
|
||||
$wrapper.find( '.wpforms-panel-content-section-payment-toggled-body' ).toggle( isChecked );
|
||||
$wrapper.toggleClass( 'wpforms-panel-content-section-payment-open', isChecked );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle a plan content.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
togglePlan() {
|
||||
const $plan = $( this ).closest( '.wpforms-panel-content-section-payment-plan' ),
|
||||
$icon = $plan.find( '.wpforms-panel-content-section-payment-plan-head-buttons-toggle' );
|
||||
|
||||
$icon.toggleClass( 'fa-chevron-circle-up fa-chevron-circle-down' );
|
||||
$plan.find( '.wpforms-panel-content-section-payment-plan-body' ).toggle( $icon.hasClass( 'fa-chevron-circle-down' ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a plan.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
deletePlan() {
|
||||
// Trigger a warning modal when trying to delete single plan without pro addon.
|
||||
$( '.wpforms-panel-content-section-payment-button-add-plan' ).click();
|
||||
},
|
||||
|
||||
/**
|
||||
* Check a plan name on empty value.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
checkPlanName() {
|
||||
const $input = $( this ),
|
||||
$plan = $input.closest( '.wpforms-panel-content-section-payment-plan' ),
|
||||
$planName = $plan.find( '.wpforms-panel-content-section-payment-plan-head-title' );
|
||||
|
||||
if ( $input.val() ) {
|
||||
$planName.html( $input.val() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultValue = wpforms_builder_stripe.plan_placeholder;
|
||||
|
||||
$planName.html( defaultValue );
|
||||
$input.val( defaultValue );
|
||||
},
|
||||
|
||||
/**
|
||||
* Rename a plan.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
renamePlan() {
|
||||
const $input = $( this ),
|
||||
$plan = $input.closest( '.wpforms-panel-content-section-payment-plan' ),
|
||||
$planName = $plan.find( '.wpforms-panel-content-section-payment-plan-head-title' );
|
||||
|
||||
if ( ! $input.val() ) {
|
||||
$planName.html( '' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$planName.html( $input.val() );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripeModernBuilder.init();
|
@@ -0,0 +1 @@
|
||||
const WPFormsStripeModernBuilder=window.WPFormsStripeModernBuilder||function(l){let o={};const i={init(){l(i.ready)},ready(){var e,n;i.isLegacySettings()||(o={$alert:l("#wpforms-stripe-credit-card-alert"),$panelContent:l("#wpforms-panel-content-section-payment-stripe"),$feeNotice:l(".wpforms-stripe-notice-info")},i.bindUIActions(),wpforms_builder_stripe.is_pro)||(n=".wpforms-panel-content-section-payment-plan-name input",l(e=".wpforms-panel-content-section-payment-toggle input").each(i.toggleContent),l(n).each(i.checkPlanName),l("#wpforms-panel-payments").on("click",e,i.toggleContent).on("click",".wpforms-panel-content-section-payment-plan-head-buttons-toggle",i.togglePlan).on("click",".wpforms-panel-content-section-payment-plan-head-buttons-delete",i.deletePlan).on("input",n,i.renamePlan).on("focusout",n,i.checkPlanName))},bindUIActions(){l("#wpforms-builder").on("wpformsFieldDelete",i.disableNotifications).on("wpformsSaved",i.requiredFieldsCheck).on("wpformsFieldAdd",i.fieldAdded).on("wpformsFieldDelete",i.fieldDeleted).on("wpformsPaymentsPlanCreated",i.toggleMultiplePlansWarning).on("wpformsPaymentsPlanDeleted",i.toggleMultiplePlansWarning)},requiredFieldsCheck(){l("#wpforms-panel-field-stripe-enable_recurring").is(":checked")&&!o.$panelContent.hasClass("wpforms-hidden")&&o.$panelContent.find(".wpforms-panel-content-section-payment-plan").each(function(){var e=l(this),n=e.data("plan-id");if(!e.find(`#wpforms-panel-field-stripe-recurring-${n}-email`).val())return i.recurringEmailAlert(),!1})},recurringEmailAlert(){l.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_recurring_email,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},disableNotifications(e,n,t){i.isStripeField(t)&&((t=l('.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]')).find('input[id*="-stripe"]').prop("checked",!1),t.addClass("wpforms-hidden"))},isLegacySettings(){return l("#wpforms-panel-field-stripe-enable").length},fieldAdded(e,n,t){i.isStripeField(t)&&(i.settingsToggle(!0),o.$feeNotice.toggleClass("wpforms-hidden"))},fieldDeleted(e,n,t){i.isStripeField(t)&&(i.settingsToggle(!1),o.$feeNotice.toggleClass("wpforms-hidden"))},isStripeField(e){return wpforms_builder_stripe.field_slugs.includes(e)},toggleMultiplePlansWarning(){o.$panelContent.find(".wpforms-stripe-multiple-plans-warning").toggleClass("wpforms-hidden",1===o.$panelContent.find(".wpforms-panel-content-section-payment-plan").length)},settingsToggle(e){(o.$alert.length||o.$panelContent.length)&&(o.$alert.toggleClass("wpforms-hidden",e),o.$panelContent.toggleClass("wpforms-hidden",!e))},toggleContent(){var e=l(this),n=(l("#wpforms-panel-field-stripe-enable_recurring").is(":checked")&&l("#wpforms-panel-field-stripe-enable_one_time").is(":checked")&&(e.prop("checked",!1),l.alert({title:wpforms_builder.heads_up,content:"wpforms-panel-field-stripe-enable_recurring"===e.attr("id")?wpforms_builder_stripe.disabled_recurring:wpforms_builder_stripe.disabled_one_time,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}}),e.prop("checked",!1)),e.closest(".wpforms-panel-content-section-payment")),e=e.prop("checked")&&!l("#wpforms-panel-field-settings-disable_entries").prop("checked");n.find(".wpforms-panel-content-section-payment-toggled-body").toggle(e),n.toggleClass("wpforms-panel-content-section-payment-open",e)},togglePlan(){var e=l(this).closest(".wpforms-panel-content-section-payment-plan"),n=e.find(".wpforms-panel-content-section-payment-plan-head-buttons-toggle");n.toggleClass("fa-chevron-circle-up fa-chevron-circle-down"),e.find(".wpforms-panel-content-section-payment-plan-body").toggle(n.hasClass("fa-chevron-circle-down"))},deletePlan(){l(".wpforms-panel-content-section-payment-button-add-plan").click()},checkPlanName(){var e,n=l(this),t=n.closest(".wpforms-panel-content-section-payment-plan").find(".wpforms-panel-content-section-payment-plan-head-title");n.val()?t.html(n.val()):(e=wpforms_builder_stripe.plan_placeholder,t.html(e),n.val(e))},renamePlan(){var e=l(this),n=e.closest(".wpforms-panel-content-section-payment-plan").find(".wpforms-panel-content-section-payment-plan-head-title");e.val()?n.html(e.val()):n.html("")}};return i}((document,window,jQuery));WPFormsStripeModernBuilder.init();
|
@@ -0,0 +1,220 @@
|
||||
/* global wpforms_builder, wpforms_builder_stripe_card_field */
|
||||
|
||||
/**
|
||||
* WPForms Stripe Card Field function.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsStripeCardField = window.WPFormsStripeCardField || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.bindUIActions();
|
||||
},
|
||||
|
||||
/**
|
||||
* Process various events as a response to UI interactions.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
bindUIActions: function() {
|
||||
|
||||
$( document ).on( 'wpformsSaved', app.ajaxRequiredCheck );
|
||||
$( document ).on( 'wpformsSaved', app.paymentsEnabledCheck );
|
||||
|
||||
$( document ).on( 'click', '#wpforms-add-fields-' + wpforms_builder_stripe_card_field.field_slug, app.stripeKeysCheck );
|
||||
$( document ).on( 'change', '.wpforms-field-option-stripe-credit-card .wpforms-field-option-row-sublabel_position select', app.sublabelPositionChange );
|
||||
$( document ).on( 'change', '.wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select', app.linkEmailChange );
|
||||
|
||||
$( document ).on( 'wpformsFieldAdd', app.disableAddCardButton );
|
||||
$( document ).on( 'wpformsFieldDelete', app.enableAddCardButton );
|
||||
$( document ).on( 'wpformsFieldDelete', app.maybeResetLinkEmailField );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users if AJAX submission is required.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
ajaxRequiredCheck: function() {
|
||||
|
||||
if ( ! $( '.wpforms-field.wpforms-field-' + wpforms_builder_stripe_card_field.field_slug ).length ||
|
||||
$( '#wpforms-panel-field-settings-ajax_submit' ).is( ':checked' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_ajax_required,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users if Stripe payments are not enabled.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
paymentsEnabledCheck: function() {
|
||||
|
||||
if ( ! $( `.wpforms-field.wpforms-field-${ wpforms_builder_stripe_card_field.field_slug }:visible` ).length ||
|
||||
$( '#wpforms-panel-field-stripe-enable' ).is( ':checked' ) ||
|
||||
$( '#wpforms-panel-field-stripe-enable_one_time' ).is( ':checked' ) ||
|
||||
$( '#wpforms-panel-field-stripe-enable_recurring' ).is( ':checked' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.payments_enabled_required,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On adding Stripe Credit Card field notify users if Stripe keys are missing.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
stripeKeysCheck: function() {
|
||||
|
||||
if ( ! $( this ).hasClass( 'stripe-keys-required' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_keys_required,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable "Add Card" button in the fields list.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
disableAddCardButton: function( e, id, type ) {
|
||||
|
||||
if ( wpforms_builder_stripe_card_field.field_slug === type ) {
|
||||
$( '#wpforms-add-fields-' + wpforms_builder_stripe_card_field.field_slug )
|
||||
.prop( 'disabled', true );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable "Add Card" button in the fields list.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
enableAddCardButton: function( e, id, type ) {
|
||||
|
||||
if ( wpforms_builder_stripe_card_field.field_slug === type ) {
|
||||
$( '#wpforms-add-fields-' + wpforms_builder_stripe_card_field.field_slug )
|
||||
.prop( 'disabled', false );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Switch sublabels preview mode.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
sublabelPositionChange: function() {
|
||||
|
||||
const fieldId = $( this ).parent().data( 'field-id' ),
|
||||
$fieldPreview = $( `#wpforms-field-${fieldId}` ).find( '.wpforms-stripe-payment-element' );
|
||||
|
||||
$fieldPreview.toggleClass( 'above' );
|
||||
$fieldPreview.toggleClass( 'floating' );
|
||||
$fieldPreview.find( 'select' ).val( $fieldPreview.hasClass( 'above' ) ? 'empty' : 'country' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Switch Link Email Field mapping.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
linkEmailChange: function() {
|
||||
|
||||
const fieldId = $( this ).parent().data( 'field-id' );
|
||||
|
||||
$( `#wpforms-field-${fieldId}` ).find( '.wpforms-stripe-link-email' ).toggleClass( 'wpforms-hidden', $( this ).val() !== '' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Maybe reset link email field if mapped email was removed.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
maybeResetLinkEmailField: function( e, id, type ) {
|
||||
|
||||
if ( type !== 'email' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$( '.wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select' ).trigger( 'change' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripeCardField.init();
|
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsStripeCardField=window.WPFormsStripeCardField||function(e,s){const i={init:function(){i.bindUIActions()},bindUIActions:function(){s(e).on("wpformsSaved",i.ajaxRequiredCheck),s(e).on("wpformsSaved",i.paymentsEnabledCheck),s(e).on("click","#wpforms-add-fields-"+wpforms_builder_stripe_card_field.field_slug,i.stripeKeysCheck),s(e).on("change",".wpforms-field-option-stripe-credit-card .wpforms-field-option-row-sublabel_position select",i.sublabelPositionChange),s(e).on("change",".wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select",i.linkEmailChange),s(e).on("wpformsFieldAdd",i.disableAddCardButton),s(e).on("wpformsFieldDelete",i.enableAddCardButton),s(e).on("wpformsFieldDelete",i.maybeResetLinkEmailField)},ajaxRequiredCheck:function(){s(".wpforms-field.wpforms-field-"+wpforms_builder_stripe_card_field.field_slug).length&&!s("#wpforms-panel-field-settings-ajax_submit").is(":checked")&&s.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_ajax_required,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},paymentsEnabledCheck:function(){!s(`.wpforms-field.wpforms-field-${wpforms_builder_stripe_card_field.field_slug}:visible`).length||s("#wpforms-panel-field-stripe-enable").is(":checked")||s("#wpforms-panel-field-stripe-enable_one_time").is(":checked")||s("#wpforms-panel-field-stripe-enable_recurring").is(":checked")||s.alert({title:wpforms_builder.heads_up,content:wpforms_builder.payments_enabled_required,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},stripeKeysCheck:function(){s(this).hasClass("stripe-keys-required")&&s.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_keys_required,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},disableAddCardButton:function(e,i,r){wpforms_builder_stripe_card_field.field_slug===r&&s("#wpforms-add-fields-"+wpforms_builder_stripe_card_field.field_slug).prop("disabled",!0)},enableAddCardButton:function(e,i,r){wpforms_builder_stripe_card_field.field_slug===r&&s("#wpforms-add-fields-"+wpforms_builder_stripe_card_field.field_slug).prop("disabled",!1)},sublabelPositionChange:function(){var e=s(this).parent().data("field-id"),e=s("#wpforms-field-"+e).find(".wpforms-stripe-payment-element");e.toggleClass("above"),e.toggleClass("floating"),e.find("select").val(e.hasClass("above")?"empty":"country")},linkEmailChange:function(){var e=s(this).parent().data("field-id");s("#wpforms-field-"+e).find(".wpforms-stripe-link-email").toggleClass("wpforms-hidden",""!==s(this).val())},maybeResetLinkEmailField:function(e,i,r){"email"===r&&s(".wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select").trigger("change")}};return i}(document,(window,jQuery));WPFormsStripeCardField.init();
|
@@ -0,0 +1,200 @@
|
||||
/* global wpforms_builder, wpforms_builder_stripe */
|
||||
|
||||
/**
|
||||
* Stripe builder function.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
|
||||
const WPFormsStripe = window.WPFormsStripe || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialized once the DOM is fully loaded.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
ready() {
|
||||
if ( ! app.isLegacySettings() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.settingsDisplay();
|
||||
app.settingsConditions();
|
||||
|
||||
app.bindUIActions();
|
||||
},
|
||||
|
||||
/**
|
||||
* Process various events as a response to UI interactions.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
bindUIActions() {
|
||||
$( document )
|
||||
.on( 'wpformsFieldDelete', app.disableNotifications )
|
||||
.on( 'wpformsSaved', app.requiredFieldsCheck )
|
||||
.on( 'wpformsFieldUpdate', app.settingsDisplay )
|
||||
.on( 'wpformsFieldUpdate', app.settingsConditions );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles visibility of the Stripe settings.
|
||||
*
|
||||
* If a credit card field has been added then reveal the settings,
|
||||
* otherwise hide them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
settingsDisplay() {
|
||||
const $alert = $( '#wpforms-stripe-credit-card-alert' );
|
||||
const $content = $( '#stripe-provider' );
|
||||
|
||||
// Check if any Credit Card fields were added to the form.
|
||||
const ccFieldsAdded = wpforms_builder_stripe.field_slugs.filter( function( fieldSlug ) {
|
||||
const $el = $( '.wpforms-field-option-' + fieldSlug );
|
||||
|
||||
return $el.length ? $el : null;
|
||||
} );
|
||||
|
||||
if ( ccFieldsAdded.length ) {
|
||||
$alert.hide();
|
||||
$content.find( '#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2' ).show();
|
||||
} else {
|
||||
$alert.show();
|
||||
$content.find( '#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2' ).hide();
|
||||
$content.find( '#wpforms-panel-field-stripe-enable' ).prop( 'checked', false );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles the visibility of the related settings.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
settingsConditions() {
|
||||
$( '#wpforms-panel-field-stripe-enable' ).conditions( {
|
||||
conditions: {
|
||||
element: '#wpforms-panel-field-stripe-enable',
|
||||
type: 'checked',
|
||||
operator: 'is',
|
||||
},
|
||||
actions: {
|
||||
if: {
|
||||
element: '.wpforms-panel-content-section-stripe-body',
|
||||
action: 'show',
|
||||
},
|
||||
else: {
|
||||
element: '.wpforms-panel-content-section-stripe-body',
|
||||
action: 'hide',
|
||||
},
|
||||
},
|
||||
effect: 'appear',
|
||||
} );
|
||||
|
||||
$( '#wpforms-panel-field-stripe-recurring-enable' ).conditions( {
|
||||
conditions: {
|
||||
element: '#wpforms-panel-field-stripe-recurring-enable',
|
||||
type: 'checked',
|
||||
operator: 'is',
|
||||
},
|
||||
actions: {
|
||||
if: {
|
||||
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',
|
||||
action: 'show',
|
||||
},
|
||||
else: {
|
||||
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',
|
||||
action: 'hide',
|
||||
},
|
||||
},
|
||||
effect: 'appear',
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users about required fields.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
requiredFieldsCheck() {
|
||||
if (
|
||||
! $( '#wpforms-panel-field-stripe-enable' ).is( ':checked' ) ||
|
||||
! $( '#wpforms-panel-field-stripe-recurring-enable' ).is( ':checked' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $( '#wpforms-panel-field-stripe-recurring-email' ).val() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_recurring_email,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable notifications.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
disableNotifications( e, id, type ) {
|
||||
if ( ! wpforms_builder_stripe.field_slugs.includes( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $notificationWrap = $( '.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]' );
|
||||
|
||||
$notificationWrap.find( 'input[id*="-stripe"]' ).prop( 'checked', false );
|
||||
$notificationWrap.addClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determinate is legacy settings is loaded.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @return {boolean} True is legacy settings loaded.
|
||||
*/
|
||||
isLegacySettings() {
|
||||
return $( '#wpforms-panel-field-stripe-enable' ).length;
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripe.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-builder-stripe.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-builder-stripe.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
const WPFormsStripe=window.WPFormsStripe||function(e,n){const i={init(){n(i.ready)},ready(){i.isLegacySettings()&&(i.settingsDisplay(),i.settingsConditions(),i.bindUIActions())},bindUIActions(){n(e).on("wpformsFieldDelete",i.disableNotifications).on("wpformsSaved",i.requiredFieldsCheck).on("wpformsFieldUpdate",i.settingsDisplay).on("wpformsFieldUpdate",i.settingsConditions)},settingsDisplay(){var e=n("#wpforms-stripe-credit-card-alert"),i=n("#stripe-provider");wpforms_builder_stripe.field_slugs.filter(function(e){e=n(".wpforms-field-option-"+e);return e.length?e:null}).length?(e.hide(),i.find("#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2").show()):(e.show(),i.find("#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2").hide(),i.find("#wpforms-panel-field-stripe-enable").prop("checked",!1))},settingsConditions(){n("#wpforms-panel-field-stripe-enable").conditions({conditions:{element:"#wpforms-panel-field-stripe-enable",type:"checked",operator:"is"},actions:{if:{element:".wpforms-panel-content-section-stripe-body",action:"show"},else:{element:".wpforms-panel-content-section-stripe-body",action:"hide"}},effect:"appear"}),n("#wpforms-panel-field-stripe-recurring-enable").conditions({conditions:{element:"#wpforms-panel-field-stripe-recurring-enable",type:"checked",operator:"is"},actions:{if:{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",action:"show"},else:{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",action:"hide"}},effect:"appear"})},requiredFieldsCheck(){n("#wpforms-panel-field-stripe-enable").is(":checked")&&n("#wpforms-panel-field-stripe-recurring-enable").is(":checked")&&(n("#wpforms-panel-field-stripe-recurring-email").val()||n.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_recurring_email,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}}))},disableNotifications(e,i,r){wpforms_builder_stripe.field_slugs.includes(r)&&((r=n('.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]')).find('input[id*="-stripe"]').prop("checked",!1),r.addClass("wpforms-hidden"))},isLegacySettings(){return n("#wpforms-panel-field-stripe-enable").length}};return i}(document,(window,jQuery));WPFormsStripe.init();
|
@@ -0,0 +1,170 @@
|
||||
/* global wpforms_admin_settings_stripe, wpforms_admin */
|
||||
|
||||
/**
|
||||
* Stripe integration settings script.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
|
||||
const WPFormsSettingsStripe = window.WPFormsSettingsStripe || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Elements holder.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const el = {};
|
||||
|
||||
/**
|
||||
* Runtime variables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const vars = {
|
||||
alertTitle: wpforms_admin.heads_up,
|
||||
alertContent: wpforms_admin_settings_stripe.mode_update,
|
||||
ok: wpforms_admin.ok,
|
||||
hideClassName: 'wpforms-hide',
|
||||
};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
ready() {
|
||||
app.setup();
|
||||
app.bindEvents();
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup. Prepare some variables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
setup() {
|
||||
// Cache DOM elements.
|
||||
el.$wrapper = $( '.wpforms-admin-content-payments' );
|
||||
el.$liveConnectionBlock = $( '.wpforms-stripe-connection-status-live' );
|
||||
el.$testConnectionBlock = $( '.wpforms-stripe-connection-status-test' );
|
||||
el.$testModeCheckbox = $( '#wpforms-setting-stripe-test-mode' );
|
||||
el.copyButton = $( '#wpforms-setting-row-stripe-webhooks-endpoint-set .wpforms-copy-to-clipboard' );
|
||||
el.webhookEndpointUrl = $( 'input#wpforms-stripe-webhook-endpoint-url' );
|
||||
el.webhookMethod = $( 'input[name="stripe-webhooks-communication"]' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind events.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
bindEvents() {
|
||||
el.$wrapper
|
||||
.on( 'change', '#wpforms-setting-stripe-test-mode', app.triggerModeSwitchAlert );
|
||||
el.copyButton
|
||||
.on( 'click', app.copyWebhooksEndpoint );
|
||||
el.webhookMethod
|
||||
.on( 'change', app.onMethodChange );
|
||||
},
|
||||
|
||||
/**
|
||||
* Conditionally show Stripe mode switch warning.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
triggerModeSwitchAlert() {
|
||||
if ( el.$testModeCheckbox.is( ':checked' ) ) {
|
||||
el.$liveConnectionBlock.addClass( vars.hideClassName );
|
||||
el.$testConnectionBlock.removeClass( vars.hideClassName );
|
||||
} else {
|
||||
el.$testConnectionBlock.addClass( vars.hideClassName );
|
||||
el.$liveConnectionBlock.removeClass( vars.hideClassName );
|
||||
}
|
||||
|
||||
if ( $( '#wpforms-setting-row-stripe-connection-status .wpforms-connected' ).is( ':visible' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: vars.alertTitle,
|
||||
content: vars.alertContent,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: vars.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy webhooks endpoint URL to clipboard.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} event Event object.
|
||||
*/
|
||||
copyWebhooksEndpoint( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
// Use Clipboard API for modern browsers and HTTPS connections, in other cases use old-fashioned way.
|
||||
if ( navigator.clipboard ) {
|
||||
navigator.clipboard.writeText( el.webhookEndpointUrl.val() ).then(
|
||||
function() {
|
||||
el.copyButton.find( 'span' ).removeClass( 'dashicons-admin-page' ).addClass( 'dashicons-yes-alt' );
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
el.webhookEndpointUrl.attr( 'disabled', false ).focus().select();
|
||||
|
||||
document.execCommand( 'copy' );
|
||||
|
||||
el.copyButton.find( 'span' ).removeClass( 'dashicons-admin-page' ).addClass( 'dashicons-yes-alt' );
|
||||
|
||||
el.webhookEndpointUrl.attr( 'disabled', true );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the endpoint URL.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
onMethodChange() {
|
||||
const checked = el.webhookMethod.filter( ':checked' ).val(),
|
||||
newUrl = wpforms_admin_settings_stripe.webhook_urls[ checked ];
|
||||
|
||||
el.webhookEndpointUrl.val( newUrl );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsSettingsStripe.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-settings-stripe.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-settings-stripe.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
const WPFormsSettingsStripe=window.WPFormsSettingsStripe||function(t,e){const o={},n={alertTitle:wpforms_admin.heads_up,alertContent:wpforms_admin_settings_stripe.mode_update,ok:wpforms_admin.ok,hideClassName:"wpforms-hide"},s={init(){e(s.ready)},ready(){s.setup(),s.bindEvents()},setup(){o.$wrapper=e(".wpforms-admin-content-payments"),o.$liveConnectionBlock=e(".wpforms-stripe-connection-status-live"),o.$testConnectionBlock=e(".wpforms-stripe-connection-status-test"),o.$testModeCheckbox=e("#wpforms-setting-stripe-test-mode"),o.copyButton=e("#wpforms-setting-row-stripe-webhooks-endpoint-set .wpforms-copy-to-clipboard"),o.webhookEndpointUrl=e("input#wpforms-stripe-webhook-endpoint-url"),o.webhookMethod=e('input[name="stripe-webhooks-communication"]')},bindEvents(){o.$wrapper.on("change","#wpforms-setting-stripe-test-mode",s.triggerModeSwitchAlert),o.copyButton.on("click",s.copyWebhooksEndpoint),o.webhookMethod.on("change",s.onMethodChange)},triggerModeSwitchAlert(){(o.$testModeCheckbox.is(":checked")?(o.$liveConnectionBlock.addClass(n.hideClassName),o.$testConnectionBlock):(o.$testConnectionBlock.addClass(n.hideClassName),o.$liveConnectionBlock)).removeClass(n.hideClassName),e("#wpforms-setting-row-stripe-connection-status .wpforms-connected").is(":visible")||e.alert({title:n.alertTitle,content:n.alertContent,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:n.ok,btnClass:"btn-confirm",keys:["enter"]}}})},copyWebhooksEndpoint(e){e.preventDefault(),navigator.clipboard?navigator.clipboard.writeText(o.webhookEndpointUrl.val()).then(function(){o.copyButton.find("span").removeClass("dashicons-admin-page").addClass("dashicons-yes-alt")}):(o.webhookEndpointUrl.attr("disabled",!1).focus().select(),t.execCommand("copy"),o.copyButton.find("span").removeClass("dashicons-admin-page").addClass("dashicons-yes-alt"),o.webhookEndpointUrl.attr("disabled",!0))},onMethodChange(){var e=o.webhookMethod.filter(":checked").val(),e=wpforms_admin_settings_stripe.webhook_urls[e];o.webhookEndpointUrl.val(e)}};return s}(document,(window,jQuery));WPFormsSettingsStripe.init();
|
@@ -0,0 +1,454 @@
|
||||
/* global Stripe, wpforms, wpforms_settings, wpforms_stripe, WPForms */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WPForms Stripe Elements function.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
var WPFormsStripeElements = window.WPFormsStripeElements || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
stripe: null,
|
||||
|
||||
/**
|
||||
* Number of page locked to switch.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {int}
|
||||
*/
|
||||
lockedPageToSwitch: 0,
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.stripe = Stripe( // eslint-disable-line new-cap
|
||||
wpforms_stripe.publishable_key,
|
||||
{ 'locale': wpforms_stripe.data.element_locale }
|
||||
);
|
||||
|
||||
$( document ).on( 'wpformsReady', function() {
|
||||
$( '.wpforms-stripe form' )
|
||||
.filter( ( _, form ) => typeof $( form ).data( 'formid' ) === 'number' ) // filter out forms which are locked (formid changed to 'locked-...').
|
||||
.each( app.setupStripeForm );
|
||||
} );
|
||||
|
||||
$( document ).on( 'wpformsBeforePageChange', app.pageChange );
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup and configure a Stripe form.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
setupStripeForm: function() {
|
||||
|
||||
let $form = $( this );
|
||||
|
||||
app.updateFormSubmitHandler( $form );
|
||||
|
||||
$form.on( 'wpformsAjaxSubmitActionRequired', app.handleCardActionCallback );
|
||||
|
||||
app.updateCardElementStylesModern( $form );
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup, mount and configure Stripe Card Element.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {object} formValidator jQuery Validator object.
|
||||
*
|
||||
* @returns {card|void} Stripe Card element.
|
||||
*/
|
||||
setupCardElement: function( $form, formValidator ) {
|
||||
|
||||
const $hiddenInput = $form.find( '.wpforms-stripe-credit-card-hidden-input' );
|
||||
|
||||
if ( ! $hiddenInput || $hiddenInput.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cardElement = $hiddenInput.data( 'stripe-element' );
|
||||
|
||||
if ( cardElement ) {
|
||||
return cardElement;
|
||||
}
|
||||
|
||||
let style = wpforms_stripe.data.element_style;
|
||||
|
||||
if ( $.isEmptyObject( style ) ) {
|
||||
style = app.getElementStyleDefault( $hiddenInput );
|
||||
}
|
||||
|
||||
let cardSettings = {
|
||||
classes : wpforms_stripe.data.element_classes,
|
||||
hidePostalCode: true,
|
||||
style : style,
|
||||
};
|
||||
|
||||
cardElement = app.stripe.elements().create( 'card', cardSettings );
|
||||
|
||||
cardElement.mount( $form.find( '.wpforms-field-stripe-credit-card-cardnumber' ).get( 0 ) );
|
||||
|
||||
cardElement.on( 'change', function( e ) {
|
||||
|
||||
if ( ! e.error ) {
|
||||
formValidator.hideThese( formValidator.errorsFor( $hiddenInput.get( 0 ) ) );
|
||||
return;
|
||||
}
|
||||
|
||||
let message = e.error.message;
|
||||
|
||||
if ( 'incomplete_number' === e.error.code || 'invalid_number' === e.error.code ) {
|
||||
message = wpforms_settings.val_creditcard;
|
||||
}
|
||||
|
||||
app.displayStripeError( $form, message );
|
||||
} );
|
||||
|
||||
$hiddenInput.data( 'stripe-element', cardElement );
|
||||
|
||||
return cardElement;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get default styles for card settings.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $hiddenInput Input element.
|
||||
*
|
||||
* @returns {object|void} Base styles.
|
||||
*/
|
||||
getElementStyleDefault: function( $hiddenInput ) {
|
||||
|
||||
if ( ! $hiddenInput || $hiddenInput.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const textColor = $hiddenInput.css( 'color' );
|
||||
const fontSize = $hiddenInput.css( 'font-size' );
|
||||
|
||||
let style = {
|
||||
base: {
|
||||
fontSize : fontSize,
|
||||
color : textColor,
|
||||
'::placeholder' : {
|
||||
fontSize : fontSize,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let fontFamily = $hiddenInput.css( 'font-family' );
|
||||
|
||||
const regExp = /[“”<>!@$%^&*=~`|{}[\]]/;
|
||||
|
||||
if ( regExp.test( fontFamily ) || fontFamily.indexOf( 'MS Shell Dlg' ) !== -1 ) {
|
||||
fontFamily = $( 'p' ).css( 'font-family' );
|
||||
}
|
||||
|
||||
if ( ! regExp.test( fontFamily ) ) {
|
||||
style.base.fontFamily = fontFamily;
|
||||
style.base['::placeholder'].fontFamily = fontFamily;
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update submitHandler for the forms containing Stripe.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
*/
|
||||
updateFormSubmitHandler: function( $form ) {
|
||||
|
||||
let formValidator = $form.validate(),
|
||||
formSubmitHandler = formValidator.settings.submitHandler,
|
||||
cardElement = app.setupCardElement( $form, formValidator ),
|
||||
$stripeDiv = $form.find( '.wpforms-field-stripe-credit-card-cardnumber' );
|
||||
|
||||
// Replace the default submit handler.
|
||||
formValidator.settings.submitHandler = function() {
|
||||
|
||||
let valid = $form.validate().form(),
|
||||
ccEmpty = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.empty ),
|
||||
ccRequired = $stripeDiv.data( 'required' ),
|
||||
condHidden = $stripeDiv.closest( '.wpforms-field-stripe-credit-card' ).hasClass( 'wpforms-conditional-hide' ),
|
||||
processCard = false;
|
||||
|
||||
if ( ! condHidden ) {
|
||||
processCard = ccRequired || ( ! ccEmpty && ! ccRequired );
|
||||
}
|
||||
|
||||
if ( valid && processCard ) {
|
||||
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', true );
|
||||
app.createPaymentMethod( $form, cardElement, ccRequired, formSubmitHandler );
|
||||
|
||||
} else if ( valid ) {
|
||||
|
||||
// Form is valid, however no credit card to process.
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', false );
|
||||
return formSubmitHandler( $form );
|
||||
|
||||
} else {
|
||||
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', false );
|
||||
$form.validate().cancelSubmit = true;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a PaymentMethod out of card details provided.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {card} cardElement Stripe Card element.
|
||||
* @param {boolean} ccRequired Card field is required.
|
||||
* @param {Function} formSubmitHandler jQuery Validation SubmitHandler function.
|
||||
*/
|
||||
createPaymentMethod: function( $form, cardElement, ccRequired, formSubmitHandler ) {
|
||||
|
||||
app.stripe.createPaymentMethod( 'card', cardElement, {
|
||||
billing_details: {
|
||||
name: $form.find( '.wpforms-field-stripe-credit-card-cardname' ).val(),
|
||||
},
|
||||
} ).then( function( result ) {
|
||||
|
||||
if ( result.error && ccRequired ) {
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', false );
|
||||
app.displayStripeError( $form, result.error.message );
|
||||
$form.validate().cancelSubmit = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! result.error ) {
|
||||
$form.find( '.wpforms-stripe-payment-method-id' ).remove();
|
||||
if ( result.paymentMethod ) {
|
||||
$form.append( '<input type="hidden" class="wpforms-stripe-payment-method-id" name="wpforms[payment_method_id]" value="' + result.paymentMethod.id + '">' );
|
||||
}
|
||||
}
|
||||
|
||||
formSubmitHandler( $form );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle 'action_required' server response.
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {object} json Data returned form a server.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
handleCardActionCallback: function( e, json ) {
|
||||
|
||||
const $form = $( this );
|
||||
|
||||
if ( json.success && json.data.action_required ) {
|
||||
app.stripe.handleCardPayment(
|
||||
json.data.payment_intent_client_secret
|
||||
).then( function( result ) {
|
||||
app.handleCardPaymentCallback( $form, result );
|
||||
} );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for Stripe 'handleCardPayment' method.
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {object} result Data returned by 'handleCardPayment'.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
handleCardPaymentCallback: function( $form, result ) {
|
||||
|
||||
if ( result.error ) {
|
||||
|
||||
app.formAjaxUnblock( $form );
|
||||
$form.find( '.wpforms-field-stripe-credit-card-cardnumber' ).addClass( wpforms_stripe.data.element_classes.invalid );
|
||||
app.displayStripeError( $form, result.error.message );
|
||||
|
||||
} else if ( result.paymentIntent && 'succeeded' === result.paymentIntent.status ) {
|
||||
|
||||
$form.find( '.wpforms-stripe-payment-method-id' ).remove();
|
||||
$form.find( '.wpforms-stripe-payment-intent-id' ).remove();
|
||||
$form.append( '<input type="hidden" class="wpforms-stripe-payment-intent-id" name="wpforms[payment_intent_id]" value="' + result.paymentIntent.id + '">' );
|
||||
wpforms.formSubmitAjax( $form );
|
||||
|
||||
} else {
|
||||
|
||||
app.formAjaxUnblock( $form );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Display a field error using jQuery Validate library.
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {object} message Error message.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
displayStripeError: function( $form, message ) {
|
||||
|
||||
const fieldName = $form.find( '.wpforms-stripe-credit-card-hidden-input' ).attr( 'name' ),
|
||||
$stripeDiv = $form.find( '.wpforms-field-stripe-credit-card-cardnumber' );
|
||||
let errors = {};
|
||||
|
||||
errors[fieldName] = message;
|
||||
|
||||
wpforms.displayFormAjaxFieldErrors( $form, errors );
|
||||
|
||||
// Switch page for the multipage form.
|
||||
if ( ! $stripeDiv.is( ':visible' ) && $form.find( '.wpforms-page-indicator-steps' ).length > 0 ) {
|
||||
// Empty $json object needed to change the page to the first one.
|
||||
wpforms.setCurrentPage( $form, {} );
|
||||
}
|
||||
|
||||
wpforms.scrollToError( $stripeDiv );
|
||||
},
|
||||
|
||||
/**
|
||||
* Unblock the AJAX form.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
*/
|
||||
formAjaxUnblock: function( $form ) {
|
||||
|
||||
let $container = $form.closest( '.wpforms-container' ),
|
||||
$spinner = $form.find( '.wpforms-submit-spinner' ),
|
||||
$submit = $form.find( '.wpforms-submit' ),
|
||||
submitText = $submit.data( 'submit-text' );
|
||||
|
||||
if ( submitText ) {
|
||||
$submit.text( submitText );
|
||||
}
|
||||
|
||||
$submit.prop( 'disabled', false );
|
||||
$container.css( 'opacity', '' );
|
||||
$spinner.hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for a page changing.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {Event} event Event.
|
||||
* @param {int} currentPage Current page.
|
||||
* @param {jQuery} $form Current form.
|
||||
* @param {string} action The navigation action.
|
||||
*/
|
||||
pageChange: function( event, currentPage, $form, action ) {
|
||||
|
||||
const $stripeDiv = $form.find( '.wpforms-field-stripe-credit-card-cardnumber' ),
|
||||
ccComplete = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.complete ),
|
||||
ccEmpty = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.empty ),
|
||||
ccInvalid = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.invalid );
|
||||
|
||||
// Stop navigation through page break pages.
|
||||
if (
|
||||
! $stripeDiv.is( ':visible' ) ||
|
||||
( ! $stripeDiv.data( 'required' ) && ccEmpty ) ||
|
||||
( app.lockedPageToSwitch && app.lockedPageToSwitch !== currentPage ) ||
|
||||
action === 'prev'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ccComplete ) {
|
||||
$stripeDiv.find( '.wpforms-error' ).remove();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
app.lockedPageToSwitch = currentPage;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( ccInvalid ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.displayStripeError( $form, wpforms_stripe.i18n.empty_details );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update Card Element styles in Modern Markup mode.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form object.
|
||||
*/
|
||||
updateCardElementStylesModern: function( $form ) {
|
||||
|
||||
// Should work only in Modern Markup mode.
|
||||
if ( ! window.WPForms || ! WPForms.FrontendModern || ! $.isEmptyObject( wpforms_stripe.data.element_style ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $form || $form.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cssVars = WPForms.FrontendModern.getCssVars( $form );
|
||||
|
||||
$form.find( '.wpforms-stripe-credit-card-hidden-input' ).each( function() {
|
||||
|
||||
const $hiddenInput = $( this );
|
||||
const cardElement = $hiddenInput.data( 'stripe-element' );
|
||||
|
||||
if ( ! cardElement ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const styles = {
|
||||
base : {
|
||||
color: cssVars['field-text-color'],
|
||||
fontSize: cssVars['field-size-font-size'],
|
||||
'::placeholder': {
|
||||
color: WPForms.FrontendModern.getColorWithOpacity( cssVars['field-text-color'], '0.5' ),
|
||||
fontSize: cssVars['field-size-font-size'],
|
||||
},
|
||||
},
|
||||
invalid: {
|
||||
color: cssVars['field-text-color'],
|
||||
},
|
||||
};
|
||||
|
||||
cardElement.update( { style: styles } );
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripeElements.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/wpforms-stripe-elements.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/wpforms-stripe-elements.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user