Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wpforms-.../assets/js/integrat.../stripe
File: wpforms-stripe-payment-element.js
/* global Stripe, wpforms, wpforms_stripe, WPForms, WPFormsUtils */
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* @param window.wpformsStripePaymentElementAppearance
[3] Fix | Delete
* @param wpforms_stripe.data.element_appearance
[4] Fix | Delete
* @param wpforms_stripe.data.element_locale
[5] Fix | Delete
* @param wpforms_stripe.i18n.element_load_error
[6] Fix | Delete
* @param wpforms_stripe.i18n.empty_details
[7] Fix | Delete
* @param wpforms_stripe.publishable_key
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
// noinspection ES6ConvertVarToLetConst
[11] Fix | Delete
/**
[12] Fix | Delete
* WPForms Stripe Payment Element function.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 1.8.2
[15] Fix | Delete
*/
[16] Fix | Delete
[17] Fix | Delete
// eslint-disable-next-line no-var
[18] Fix | Delete
var WPFormsStripePaymentElement = window.WPFormsStripePaymentElement || ( function( document, window, $ ) {
[19] Fix | Delete
/**
[20] Fix | Delete
* Original Submit Handler.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 1.8.2
[23] Fix | Delete
*
[24] Fix | Delete
* @type {Function}
[25] Fix | Delete
*/
[26] Fix | Delete
let originalSubmitHandler;
[27] Fix | Delete
[28] Fix | Delete
// noinspection JSUnusedLocalSymbols
[29] Fix | Delete
/**
[30] Fix | Delete
* Public functions and properties.
[31] Fix | Delete
*
[32] Fix | Delete
* @since 1.8.2
[33] Fix | Delete
*
[34] Fix | Delete
* @type {Object}
[35] Fix | Delete
*/
[36] Fix | Delete
const app = {
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Stripe object.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 1.8.2
[42] Fix | Delete
*
[43] Fix | Delete
* @type {Object}
[44] Fix | Delete
* @property {Function} confirmPayment Payment confirmation.
[45] Fix | Delete
*/
[46] Fix | Delete
stripe: null,
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Object to store form data.
[50] Fix | Delete
*
[51] Fix | Delete
* @since 1.8.2
[52] Fix | Delete
*
[53] Fix | Delete
* @type {Object}
[54] Fix | Delete
*/
[55] Fix | Delete
forms: {},
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Start the engine.
[59] Fix | Delete
*
[60] Fix | Delete
* @since 1.8.2
[61] Fix | Delete
*/
[62] Fix | Delete
init() {
[63] Fix | Delete
app.stripe = Stripe( // eslint-disable-line new-cap
[64] Fix | Delete
wpforms_stripe.publishable_key,
[65] Fix | Delete
{
[66] Fix | Delete
locale: wpforms_stripe.data.element_locale,
[67] Fix | Delete
betas: [ 'elements_enable_deferred_intent_beta_1' ],
[68] Fix | Delete
}
[69] Fix | Delete
);
[70] Fix | Delete
[71] Fix | Delete
$( document ).on( 'wpformsReady', function() {
[72] Fix | Delete
app.initializeFormsDefaultObject();
[73] Fix | Delete
[74] Fix | Delete
$( '.wpforms-stripe form' )
[75] Fix | Delete
.each( app.setupStripeForm )
[76] Fix | Delete
.on( 'wpformsConvFormsFieldActivationAfter', app.convFormsFieldActivationAfter ); // Initialize in Conversational Form on field activation.
[77] Fix | Delete
} );
[78] Fix | Delete
[79] Fix | Delete
$( document )
[80] Fix | Delete
.on( 'wpformsBeforePageChange', app.pageChange )
[81] Fix | Delete
.on( 'wpformsAmountTotalCalculated', app.updateElementsTotalAmount )
[82] Fix | Delete
.on( 'wpformsProcessConditionalsField', function( e, formID, fieldID, pass, action ) {
[83] Fix | Delete
app.processConditionalsField( formID, fieldID, pass, action );
[84] Fix | Delete
} );
[85] Fix | Delete
},
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Initialize forms default object.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 1.8.2
[91] Fix | Delete
*/
[92] Fix | Delete
initializeFormsDefaultObject() {
[93] Fix | Delete
$( '.wpforms-stripe form' ).each( function() {
[94] Fix | Delete
const formId = $( this ).data( 'formid' );
[95] Fix | Delete
[96] Fix | Delete
app.forms[ formId ] = {
[97] Fix | Delete
elements : null,
[98] Fix | Delete
paymentElement: null,
[99] Fix | Delete
elementsModified: false,
[100] Fix | Delete
linkElement: null,
[101] Fix | Delete
linkEmail: '',
[102] Fix | Delete
linkDestroyed: false,
[103] Fix | Delete
paymentType: '',
[104] Fix | Delete
lockedPageToSwitch: 0,
[105] Fix | Delete
paymentMethodId: '',
[106] Fix | Delete
total: '',
[107] Fix | Delete
};
[108] Fix | Delete
} );
[109] Fix | Delete
},
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Setup and configure a Stripe form.
[113] Fix | Delete
*
[114] Fix | Delete
* @since 1.8.2
[115] Fix | Delete
*/
[116] Fix | Delete
setupStripeForm() {
[117] Fix | Delete
const $form = $( this ),
[118] Fix | Delete
$stripeDiv = $form.find( '.wpforms-field-stripe-credit-card' );
[119] Fix | Delete
[120] Fix | Delete
if ( ! $stripeDiv.find( '.wpforms-field-row' ).length ) {
[121] Fix | Delete
return;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
const validator = $form.data( 'validator' );
[125] Fix | Delete
[126] Fix | Delete
if ( ! validator ) {
[127] Fix | Delete
return;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
// Store the original submitHandler.
[131] Fix | Delete
originalSubmitHandler = validator.settings.submitHandler;
[132] Fix | Delete
[133] Fix | Delete
// Replace the default submit handler.
[134] Fix | Delete
validator.settings.submitHandler = app.submitHandler;
[135] Fix | Delete
[136] Fix | Delete
$form.on( 'wpformsAjaxSubmitActionRequired', app.confirmPaymentActionCallback );
[137] Fix | Delete
[138] Fix | Delete
if ( $stripeDiv.hasClass( 'wpforms-conditional-field' ) ) {
[139] Fix | Delete
return;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
app.setupPaymentElement( $form );
[143] Fix | Delete
},
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Handle confirm payment server response.
[147] Fix | Delete
*
[148] Fix | Delete
* @param {Object} e Event object.
[149] Fix | Delete
* @param {Object} json Json returned from a server.
[150] Fix | Delete
* @param {boolean} json.data.action_required Whether action is required.
[151] Fix | Delete
* @param {string} json.data.payment_intent_client_secret Payment intent client secret.
[152] Fix | Delete
* @param {boolean} json.success Success.
[153] Fix | Delete
*
[154] Fix | Delete
* @since 1.8.2
[155] Fix | Delete
*/
[156] Fix | Delete
async confirmPaymentActionCallback( e, json ) {
[157] Fix | Delete
if ( ! json.success || ! json.data.action_required ) {
[158] Fix | Delete
return;
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
const $form = $( this );
[162] Fix | Delete
[163] Fix | Delete
const redirectUrl = new URL( window.location.href ),
[164] Fix | Delete
formId = $form.data( 'formid' );
[165] Fix | Delete
[166] Fix | Delete
await app.stripe.confirmPayment(
[167] Fix | Delete
{
[168] Fix | Delete
clientSecret: json.data.payment_intent_client_secret, // eslint-disable-line camelcase
[169] Fix | Delete
confirmParams: {
[170] Fix | Delete
return_url: redirectUrl.toString(), // eslint-disable-line camelcase
[171] Fix | Delete
payment_method: app.forms[ formId ].paymentMethodId, // eslint-disable-line camelcase
[172] Fix | Delete
},
[173] Fix | Delete
redirect: 'if_required',
[174] Fix | Delete
}
[175] Fix | Delete
).then( function( result ) {
[176] Fix | Delete
app.handleConfirmPayment( $form, result );
[177] Fix | Delete
} );
[178] Fix | Delete
},
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Callback for Stripe 'confirmPayment' method.
[182] Fix | Delete
*
[183] Fix | Delete
* @param {jQuery} $form Form element.
[184] Fix | Delete
* @param {Object} result Data returned by 'handleCardPayment'.
[185] Fix | Delete
* @param {Object} result.error Error.
[186] Fix | Delete
* @param {Object} result.paymentIntent Payment intent.
[187] Fix | Delete
*
[188] Fix | Delete
* @since 1.8.2
[189] Fix | Delete
*/
[190] Fix | Delete
handleConfirmPayment( $form, result ) {
[191] Fix | Delete
if ( result.error ) {
[192] Fix | Delete
app.displayStripeError( $form, result.error.message );
[193] Fix | Delete
[194] Fix | Delete
return;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
const formId = $form.data( 'formid' );
[198] Fix | Delete
[199] Fix | Delete
if ( result.paymentIntent && result.paymentIntent.status === 'succeeded' ) {
[200] Fix | Delete
$form.find( '.wpforms-stripe-payment-method-id' ).remove();
[201] Fix | Delete
$form.find( '.wpforms-stripe-payment-intent-id' ).remove();
[202] Fix | Delete
$form.append( '<input type="hidden" class="wpforms-stripe-payment-intent-id" name="wpforms[payment_intent_id]" value="' + result.paymentIntent.id + '">' );
[203] Fix | Delete
$form.append( '<input type="hidden" class="wpforms-stripe-payment-link-email" name="wpforms[payment_link_email]" value="' + app.forms[ formId ].linkEmail + '">' );
[204] Fix | Delete
wpforms.formSubmitAjax( $form );
[205] Fix | Delete
[206] Fix | Delete
return;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
app.formAjaxUnblock( $form );
[210] Fix | Delete
},
[211] Fix | Delete
[212] Fix | Delete
/**
[213] Fix | Delete
* Setup, mount and configure Stripe Payment Element.
[214] Fix | Delete
*
[215] Fix | Delete
* @since 1.8.2
[216] Fix | Delete
*
[217] Fix | Delete
* @param {jQuery} $form Form element.
[218] Fix | Delete
*/
[219] Fix | Delete
setupPaymentElement( $form ) {
[220] Fix | Delete
const formId = $form.data( 'formid' );
[221] Fix | Delete
[222] Fix | Delete
if ( $.isEmptyObject( app.forms ) ) {
[223] Fix | Delete
app.initializeFormsDefaultObject();
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
if ( app.forms[ formId ].paymentElement ) {
[227] Fix | Delete
return;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
app.forms[ formId ].elements = app.stripe.elements(
[231] Fix | Delete
{
[232] Fix | Delete
currency: wpforms.getCurrency().code.toLowerCase(),
[233] Fix | Delete
mode: 'payment',
[234] Fix | Delete
// eslint-disable-next-line
[235] Fix | Delete
// See min amount for different currencies https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts.
[236] Fix | Delete
amount: 77777,
[237] Fix | Delete
loader: 'always',
[238] Fix | Delete
locale: wpforms_stripe.data.element_locale,
[239] Fix | Delete
appearance: app.getElementAppearanceOptions( $form ),
[240] Fix | Delete
} );
[241] Fix | Delete
[242] Fix | Delete
app.initializePaymentElement( $form );
[243] Fix | Delete
[244] Fix | Delete
app.linkEmailMappedFieldTriggers( $form );
[245] Fix | Delete
[246] Fix | Delete
// Update the total amount in case of fixed price.
[247] Fix | Delete
wpforms.amountTotalCalc( $form );
[248] Fix | Delete
[249] Fix | Delete
// Update styles in Modern Markup mode.
[250] Fix | Delete
app.updatePaymentElementStylesModern( $form );
[251] Fix | Delete
},
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Handle Process Conditionals for Stripe field.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 1.8.2
[257] Fix | Delete
*
[258] Fix | Delete
* @param {string} formID Form ID.
[259] Fix | Delete
* @param {string} fieldID Field ID.
[260] Fix | Delete
* @param {boolean} pass Pass logic.
[261] Fix | Delete
* @param {string} action Action to execute.
[262] Fix | Delete
*/
[263] Fix | Delete
processConditionalsField( formID, fieldID, pass, action ) { // eslint-disable-line complexity
[264] Fix | Delete
const $form = $( '#wpforms-form-' + formID ),
[265] Fix | Delete
$stripeDiv = $form.find( '.wpforms-field-stripe-credit-card' ),
[266] Fix | Delete
isHidden = ( pass && action === 'hide' ) || ( ! pass && action !== 'hide' );
[267] Fix | Delete
[268] Fix | Delete
if (
[269] Fix | Delete
! $stripeDiv.length ||
[270] Fix | Delete
$stripeDiv.data( 'field-id' ).toString() !== fieldID ||
[271] Fix | Delete
app.forms[ formID ].paymentElement ||
[272] Fix | Delete
isHidden
[273] Fix | Delete
) {
[274] Fix | Delete
return;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
app.setupPaymentElement( $form );
[278] Fix | Delete
},
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Get Element appearance options.
[282] Fix | Delete
*
[283] Fix | Delete
* @since 1.8.2
[284] Fix | Delete
*
[285] Fix | Delete
* @param {jQuery} $form Form element.
[286] Fix | Delete
*
[287] Fix | Delete
* @return {Object} Appearance options.
[288] Fix | Delete
*/
[289] Fix | Delete
getElementAppearanceOptions( $form ) { // eslint-disable-line complexity, max-lines-per-function
[290] Fix | Delete
const customAppearanceOptions = app.getCustomAppearanceOptions();
[291] Fix | Delete
[292] Fix | Delete
if ( ! $.isEmptyObject( customAppearanceOptions ) ) {
[293] Fix | Delete
return customAppearanceOptions;
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
const $hiddenInput = $form.find( '.wpforms-stripe-credit-card-hidden-input' ),
[297] Fix | Delete
$fieldRow = $form.find( '.wpforms-field-stripe-credit-card .wpforms-field-row' );
[298] Fix | Delete
[299] Fix | Delete
const labelHide = ! $fieldRow.hasClass( 'wpforms-sublabel-hide' );
[300] Fix | Delete
[301] Fix | Delete
const inputStyle = {
[302] Fix | Delete
borderColor: app.getCssPropertyValue( $hiddenInput, '--field-border' ) || app.getCssPropertyValue( $hiddenInput, 'border-color' ),
[303] Fix | Delete
borderRadius: app.getCssPropertyValue( $hiddenInput, 'border-radius' ),
[304] Fix | Delete
fontSize: app.getCssPropertyValue( $hiddenInput, 'font-size' ),
[305] Fix | Delete
colorPrimary: app.getCssPropertyValue( $hiddenInput, '--primary-color' ) || app.getCssPropertyValue( $hiddenInput, 'color' ),
[306] Fix | Delete
colorText: app.getCssPropertyValue( $hiddenInput, '--secondary-color' ) || app.getCssPropertyValue( $hiddenInput, 'color' ),
[307] Fix | Delete
colorTextPlaceholder: app.getCssPropertyValue( $hiddenInput, '--secondary-color-50' ) || WPFormsUtils.cssColorsUtils.getColorWithOpacity( app.getCssPropertyValue( $hiddenInput, 'color' ), '0.5' ),
[308] Fix | Delete
colorBackground: app.getCssPropertyValue( $hiddenInput, '--background-color' ) || app.getCssPropertyValue( $hiddenInput, 'background-color' ),
[309] Fix | Delete
fontFamily: app.getCssPropertyValue( $hiddenInput, 'font-family' ),
[310] Fix | Delete
focusColor: app.getCssPropertyValue( $hiddenInput, '--accent-color' ) || app.getCssPropertyValue( $hiddenInput, 'color' ),
[311] Fix | Delete
errorColor: '#990000',
[312] Fix | Delete
};
[313] Fix | Delete
[314] Fix | Delete
if ( window.WPForms && WPForms.FrontendModern ) {
[315] Fix | Delete
inputStyle.colorPrimary = WPForms.FrontendModern.getSolidColor( inputStyle.colorPrimary );
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
return {
[319] Fix | Delete
theme: 'none',
[320] Fix | Delete
labels: $fieldRow.data( 'sublabel-position' ),
[321] Fix | Delete
sublabelHide: labelHide,
[322] Fix | Delete
variables: {
[323] Fix | Delete
colorPrimary: inputStyle.colorPrimary,
[324] Fix | Delete
colorBackground: inputStyle.colorBackground,
[325] Fix | Delete
colorText: inputStyle.colorText,
[326] Fix | Delete
colorDanger: inputStyle.errorColor,
[327] Fix | Delete
fontFamily: inputStyle.fontFamily,
[328] Fix | Delete
spacingUnit: '4px',
[329] Fix | Delete
spacingGridRow: '8px',
[330] Fix | Delete
fontSizeSm: '13px',
[331] Fix | Delete
fontWeightNormal: '400',
[332] Fix | Delete
borderRadius: inputStyle.borderRadius,
[333] Fix | Delete
colorTextPlaceholder: inputStyle.colorTextPlaceholder,
[334] Fix | Delete
colorIcon: inputStyle.colorText,
[335] Fix | Delete
},
[336] Fix | Delete
rules: {
[337] Fix | Delete
'.Input--invalid': {
[338] Fix | Delete
color: inputStyle.colorText,
[339] Fix | Delete
borderColor: '#cc0000',
[340] Fix | Delete
},
[341] Fix | Delete
'.Input': {
[342] Fix | Delete
border: 'none',
[343] Fix | Delete
borderRadius: inputStyle.borderRadius,
[344] Fix | Delete
boxShadow: '0 0 0 1px ' + inputStyle.borderColor,
[345] Fix | Delete
fontSize: inputStyle.fontSize,
[346] Fix | Delete
padding: '12px 14px',
[347] Fix | Delete
lineHeight: parseInt( inputStyle.fontSize, 10 ) + 5 + 'px', // match the font and line height to prevent overflow
[348] Fix | Delete
transition: 'none',
[349] Fix | Delete
color: inputStyle.colorText,
[350] Fix | Delete
backgroundColor: inputStyle.colorBackground,
[351] Fix | Delete
},
[352] Fix | Delete
'.Input:focus, .Input:hover': {
[353] Fix | Delete
border: 'none',
[354] Fix | Delete
boxShadow: '0 0 0 2px ' + inputStyle.focusColor,
[355] Fix | Delete
outline: 'none',
[356] Fix | Delete
},
[357] Fix | Delete
'.Label': {
[358] Fix | Delete
fontFamily: inputStyle.fontFamily,
[359] Fix | Delete
lineHeight: labelHide ? '1.3' : '0',
[360] Fix | Delete
opacity: Number( labelHide ),
[361] Fix | Delete
color: inputStyle.colorPrimary,
[362] Fix | Delete
},
[363] Fix | Delete
'.CheckboxInput, .CodeInput, .PickerItem': {
[364] Fix | Delete
border: '1px solid ' + inputStyle.borderColor,
[365] Fix | Delete
},
[366] Fix | Delete
'.Tab, .Block': {
[367] Fix | Delete
border: '1px solid ' + inputStyle.borderColor,
[368] Fix | Delete
borderRadius: inputStyle.borderRadius,
[369] Fix | Delete
color: inputStyle.colorText,
[370] Fix | Delete
},
[371] Fix | Delete
'.TabLabel, .TabIcon': {
[372] Fix | Delete
color: inputStyle.colorText,
[373] Fix | Delete
},
[374] Fix | Delete
'.Tab--selected': {
[375] Fix | Delete
borderColor: '#999999',
[376] Fix | Delete
color: inputStyle.colorText,
[377] Fix | Delete
},
[378] Fix | Delete
'.Action': {
[379] Fix | Delete
marginLeft: '6px',
[380] Fix | Delete
},
[381] Fix | Delete
'.Action, .MenuAction': {
[382] Fix | Delete
border: 'none',
[383] Fix | Delete
backgroundColor: 'transparent',
[384] Fix | Delete
},
[385] Fix | Delete
'.Action:hover, .MenuAction:hover': {
[386] Fix | Delete
border: 'none',
[387] Fix | Delete
backgroundColor: 'transparent',
[388] Fix | Delete
},
[389] Fix | Delete
'.Error, .RedirectText': {
[390] Fix | Delete
color: inputStyle.errorColor,
[391] Fix | Delete
},
[392] Fix | Delete
'.TabIcon--selected': {
[393] Fix | Delete
fill: inputStyle.colorText,
[394] Fix | Delete
},
[395] Fix | Delete
},
[396] Fix | Delete
};
[397] Fix | Delete
},
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Get custom appearance options.
[401] Fix | Delete
*
[402] Fix | Delete
* @since 1.8.5
[403] Fix | Delete
*
[404] Fix | Delete
* @return {Object} Element appearance options.
[405] Fix | Delete
*/
[406] Fix | Delete
getCustomAppearanceOptions() {
[407] Fix | Delete
if ( typeof window.wpformsStripePaymentElementAppearance === 'object' ) {
[408] Fix | Delete
return window.wpformsStripePaymentElementAppearance;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
if ( ! $.isEmptyObject( wpforms_stripe.data.element_appearance ) ) {
[412] Fix | Delete
return wpforms_stripe.data.element_appearance;
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
return {};
[416] Fix | Delete
},
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Get CSS property value.
[420] Fix | Delete
* In case of exception, return empty string.
[421] Fix | Delete
*
[422] Fix | Delete
* @since 1.8.4
[423] Fix | Delete
*
[424] Fix | Delete
* @param {jQuery} $element Element.
[425] Fix | Delete
* @param {string} property Property.
[426] Fix | Delete
*
[427] Fix | Delete
* @return {string} Property value.
[428] Fix | Delete
*/
[429] Fix | Delete
getCssPropertyValue( $element, property ) {
[430] Fix | Delete
try {
[431] Fix | Delete
return $element.css( property );
[432] Fix | Delete
} catch ( e ) {
[433] Fix | Delete
return '';
[434] Fix | Delete
}
[435] Fix | Delete
},
[436] Fix | Delete
[437] Fix | Delete
/**
[438] Fix | Delete
* Initialize Payment Element.
[439] Fix | Delete
*
[440] Fix | Delete
* @since 1.8.2
[441] Fix | Delete
*
[442] Fix | Delete
* @param {jQuery} $form Form element.
[443] Fix | Delete
* @param {string} email Email address.
[444] Fix | Delete
*/
[445] Fix | Delete
initializePaymentElement( $form, email = '' ) {
[446] Fix | Delete
const $fieldRow = $form.find( '.wpforms-field-stripe-credit-card .wpforms-field-row' );
[447] Fix | Delete
[448] Fix | Delete
const formId = $form.data( 'formid' );
[449] Fix | Delete
[450] Fix | Delete
if ( app.forms[ formId ].paymentElement ) {
[451] Fix | Delete
app.forms[ formId ].paymentElement.destroy();
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
app.forms[ formId ].paymentElement = app.forms[ formId ].elements.create( 'payment', { defaultValues : { billingDetails: { email } } } );
[455] Fix | Delete
[456] Fix | Delete
app.mountPaymentElement( $form );
[457] Fix | Delete
[458] Fix | Delete
// eslint-disable-next-line complexity
[459] Fix | Delete
app.forms[ formId ].paymentElement.on( 'change', function( event ) {
[460] Fix | Delete
app.forms[ formId ].paymentType = event.value.type;
[461] Fix | Delete
[462] Fix | Delete
// Destroy a link element as it's not required for Google and Apple Pay.
[463] Fix | Delete
if ( ! $fieldRow.data( 'link-email' ) ) {
[464] Fix | Delete
if ( event.value.type === 'google_pay' || event.value.type === 'apple_pay' ) {
[465] Fix | Delete
app.forms[ formId ].linkElement.destroy();
[466] Fix | Delete
[467] Fix | Delete
app.forms[ formId ].linkDestroyed = true;
[468] Fix | Delete
} else if ( app.forms[ formId ].linkDestroyed ) {
[469] Fix | Delete
app.initializeLinkAuthenticationElement( $form );
[470] Fix | Delete
[471] Fix | Delete
app.forms[ formId ].linkDestroyed = false;
[472] Fix | Delete
}
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
$fieldRow.data( 'type', event.value.type );
[476] Fix | Delete
[477] Fix | Delete
if ( event.empty ) {
[478] Fix | Delete
$fieldRow.data( 'completed', false );
[479] Fix | Delete
[480] Fix | Delete
$fieldRow.find( 'label.wpforms-error' ).toggle( event.value.type === 'card' );
[481] Fix | Delete
[482] Fix | Delete
return;
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
app.forms[ formId ].elementsModified = true;
[486] Fix | Delete
[487] Fix | Delete
if ( event.complete ) {
[488] Fix | Delete
$fieldRow.data( 'completed', true );
[489] Fix | Delete
[490] Fix | Delete
app.hideStripeFieldError( $form );
[491] Fix | Delete
[492] Fix | Delete
return;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
$fieldRow.data( 'completed', false );
[496] Fix | Delete
} );
[497] Fix | Delete
[498] Fix | Delete
app.forms[ formId ].paymentElement.on( 'loaderror', function( event ) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function