%PDF-
%PDF-
Mini Shell
Mini Shell
/**
* Stripe payment form handler.
*/
jQuery(($) => {
'use strict';
/**
* Payment form handler.
*
* Interacts with Stripe Elements to process a checkout payment form.
*/
window.MWCPaymentsStripePaymentFormHandler = class MWCPaymentsStripePaymentFormHandler {
/**
* Instantiates the payment form handler.
*
* Loads the payment handler and intercepts form submissions to process the payment using Stripe Elements.
*
* @param {Object} args form handler arguments
*/
constructor(args) {
this.appInfo = args.appInfo;
this.appearance = args.appearance;
this.publishableKey = args.publishableKey;
this.billingDetails = args.billingDetails;
this.isLoggingEnabled = args.isLoggingEnabled;
this.redirectUrl = args.redirectUrl;
this.genericError = args.genericError;
this.isDetailedDecline = args.isDetailedDecline;
this.reusablePaymentMethodTypes = args.reusablePaymentMethodTypes;
// bail if no Stripe wrappers exist on the page
if (! $('#mwc-payments-stripe-form').length) {
return;
}
this.initialize();
if ( $( 'form.checkout' ).length ) {
this.form = $( 'form.checkout' );
this.handleCheckout();
} else if ( $( 'form#order_review' ).length ) {
this.form = $( 'form#order_review' );
this.handlePayPage();
} else if ( $( 'form#add_payment_method' ).length ) {
this.form = $( 'form#add_payment_method' );
this.handleMyAccount();
} else {
this.debugLog('No payment form available');
}
}
/**
* Initializes the Stripe SDK and Elements
*/
initialize() {
this.stripe = Stripe(this.publishableKey);
this.stripe.registerAppInfo(this.appInfo);
this.refreshForm()
}
/**
* Initializes Stripe Elements
*/
initElements() {
this.clientSecret = $('#mwc-payments-stripe-client-secret').val();
this.elements = this.stripe.elements({
clientSecret: this.clientSecret,
appearance: this.appearance,
})
}
/**
* Initializes the payment element
*/
initPaymentElement() {
this.paymentElement = this.elements.create('payment', {
fields: {
billingDetails: {
name: this.getFormFieldState(this.billingDetails.name, '#billing_first_name', '#billing_last_name' ),
email: this.getFormFieldState(this.billingDetails.email, '#billing_email'),
phone: this.getFormFieldState(this.billingDetails.phone, '#billing_phone'),
address: {
line1: this.getFormFieldState(this.billingDetails.address.line1, '#billing_address_1'),
line2: this.getFormFieldState(this.billingDetails.address.line1, '#billing_address_2'),
city: this.getFormFieldState(this.billingDetails.address.city, '#billing_city'),
state: this.getFormFieldState(this.billingDetails.address.state, '#billing_state'),
country: this.getFormFieldState(this.billingDetails.address.country, '#billing_country'),
postalCode: this.getFormFieldState(this.billingDetails.address.postal_code, '#billing_postcode'),
},
}
}
})
}
/**
* Handles the saved payment methods
*/
handleSavedPaymentMethods() {
let $newMethodForm = $('.mwc-payments-stripe-new-payment-method-form');
$('input.mwc-payments-stripe-payment-method').change( () => {
if ( $( "input.mwc-payments-stripe-payment-method:checked" ).val() ) {
$newMethodForm.slideUp( 200 );
} else {
$newMethodForm.slideDown( 200 );
}
} ).change();
$('input#createaccount').change((event) => {
this.toggleSaveMethod($(event.target).is(':checked'));
});
if (! $('input#createaccount').is(':checked')) {
$('input#createaccount').change();
}
// when the save method checkbox is checked, ensure the payment element displays the terms
$('input.mwc-payments-tokenize-payment-method').change((event) => {
let termsValue = $(event.target).is(':checked') ? 'always' : 'auto';
this.paymentElement.update({
terms: {
auBecsDebit: termsValue,
bancontact: termsValue,
card: termsValue,
ideal: termsValue,
sepaDebit: termsValue,
sofort: termsValue,
usBankAccount: termsValue,
}
});
});
}
/**
* Toggles the "Save method" checkbox availability.
*
* @param {Boolean} isAvailable
*/
toggleSaveMethod(isAvailable) {
let $checkbox = $('input.mwc-payments-tokenize-payment-method');
let $parentRow = $checkbox.closest( 'p.form-row' );
if (isAvailable) {
$parentRow.slideDown();
$parentRow.next().show();
} else {
$parentRow.hide();
$parentRow.next().hide();
$checkbox.prop('checked', false);
}
}
/**
* Gets the state of a Stripe Element form field depending on the potential for its value availability.
*
* - If the value is already available, we know we never need to collect it on the Stripe form.
* - If the value is not yet available but at least one of its form fields are present in the DOM, we know it will be collected by the Woo form and will be available when payment is submitted.
*
* @param {string} availableValue
* @param {string} sourceDomElements
*
* @returns {string}
*/
getFormFieldState(availableValue, ...sourceDomElements) {
return availableValue || sourceDomElements.some(function (sourceDomElement) {
return $(sourceDomElement).length > 0;
}) ? 'never' : 'auto'
}
/**
* Refreshes the payment form.
*/
refreshForm() {
this.initElements()
if (this.paymentElement) {
this.paymentElement.destroy()
}
this.initPaymentElement()
// ensure the saved method checkbox is toggled depending on the chosen payment method type
this.paymentElement.on('change', (event) => {
this.toggleSaveMethod(this.reusablePaymentMethodTypes.includes(event.value.type));
});
this.paymentElement.mount('#mwc-payments-stripe-form')
}
/**
* Handles the checkout page.
*/
handleCheckout() {
$( document.body ).on( 'updated_checkout', () => {
this.refreshForm()
this.handleSavedPaymentMethods()
} );
$( this.form ).on( 'checkout_place_order_stripe', () => {
// submit the form and process server-side if a saved method is selected
if ( $( "input.mwc-payments-stripe-payment-method:checked" ).val() ) {
return true
}
$( this.form ).on('checkout_place_order_success.mwc-stripe', (event, data) => {
let returnUrl = data.redirect
if (data.billingDetails) {
this.billingDetails = data.billingDetails;
}
// prevent WC from redirecting before we can confirm the payment
data.redirect = '#!'
if (returnUrl !== '#!') {
this.handleConfirm(returnUrl);
}
})
});
}
/**
* Handles the order pay page
*/
handlePayPage() {
this.refreshForm();
this.handleSavedPaymentMethods()
this.form.submit( (event) => {
if ( $( '#order_review input[name=payment_method]:checked' ).val() === 'stripe' ) {
// submit the form and process server-side if a saved method is selected
if ( $( "input.mwc-payments-stripe-payment-method:checked" ).val() ) {
return true
}
event.preventDefault()
if ($('#mwc-payments-stripe-tokenize-payment-method').is(':checked')) {
let url = new URL(this.redirectUrl);
url.searchParams.set("shouldTokenize", "true");
this.redirectUrl = url.href;
}
this.handleConfirm(this.redirectUrl);
}
} );
}
handleMyAccount() {
this.form.submit( (event) => {
if ( $( '#add_payment_method input[name=payment_method]:checked' ).val() === 'stripe' ) {
event.preventDefault();
this.handleConfirm(this.redirectUrl);
}
} );
}
/**
* Handles confirming a payment or setup intent.
*
* @param {String} returnUrl
*/
handleConfirm(returnUrl = null) {
// if the client secret is for a setup intent
if (this.clientSecret.toString().startsWith('seti_')) {
this.handleConfirmSetup(returnUrl);
return;
}
this.handleConfirmPayment(returnUrl);
}
/**
* Handles confirming a setup intent.
*
* @param {String} returnUrl
*/
handleConfirmSetup(returnUrl = null) {
this.stripe.confirmSetup({
elements: this.elements,
confirmParams: {
payment_method_data: {
billing_details: this.billingDetails,
},
return_url: returnUrl,
},
}).then(result => {
if (result.error) {
this.handleError(result.error)
}
});
}
/**
* Handles confirming a payment intent.
*
* @param {String} returnUrl
*/
handleConfirmPayment(returnUrl = null) {
this.stripe.confirmPayment({
elements: this.elements,
confirmParams: {
payment_method_data: {
billing_details: this.billingDetails,
},
return_url: returnUrl,
}
}).then(result => {
$(this.form).off('checkout_place_order_success.mwc-stripe');
if (result.error) {
this.handleError(result.error)
}
});
}
/**
* Handles the error event data.
*
* Logs errors to console.
*
* @param {Object} event after a form error
*/
handleError(event) {
$( '.woocommerce-error, .woocommerce-message' ).remove();
if ((event.type === 'validation_error') || (event.type === 'card_error' && this.isDetailedDecline)) {
this.form.prepend( '<ul class="woocommerce-error"><li>' + event.message + '</li></ul>' );
} else {
this.form.prepend( '<ul class="woocommerce-error"><li>' + this.genericError + '</li></ul>' );
}
this.form.removeClass( 'processing' ).unblock();
this.form.find( '.input-text, select' ).blur();
$( 'html, body' ).animate( { scrollTop: this.form.offset().top - 100 }, 1000 );
this.debugLog(event);
}
/**
* Logs an item to console if logging is enabled.
*/
debugLog() {
if (this.isLoggingEnabled) {
console.log.apply(null, arguments);
}
}
}
// dispatch loaded event
$(document.body).trigger('mwc_payments_stripe_payment_form_handler_loaded');
});
Zerion Mini Shell 1.0
Custom Staffing Solutions | Beyond A Resume
Skip to content
Distinguish Your Business From The Rest With The People That Make Up Your Team
We go Beyond a Resume to find high value, committed people
ready, willing, and able to add true value toward your organization's mission.
The right people make or break your business
We focus on resolving two types of challenges surrounding staffing and recruiting at Beyond a Resume: The first challenge comes when a business continues to grow, but does not have the full-time, internal, talent acquisition resources to hire the right people or talent necessary to keep up with their rate of progression as a company.
The second is a business that has a dedicated internal Human Resources Team, but requires outsourced assistance when the volume of people and talent needed exceeds short term internal capacity, OR the position(s) they seek to fill demand a specific skill set that is difficult to find, requiring added bandwidth.
In nearly any line of business, growth is a challenge in and of itself. Yet, the real problems arise in managing growth to ensure your progress remains profitable, sustainable, and repeatable. The biggest factor in this equation is usually found in your people. When you have the right people, success is unlimited. On the other hand, when you don’t have the right people in place or are having trouble finding enough of the right people, failure or stagnation is imminent.
The frustration that comes with the process of “hiring” can bring you to new levels of stress as the time cost involved eats away at your production elsewhere. If you have experienced this in the past, or are currently struggling with this issue, you’re certainly not alone. You may simply need the right partner to take the worst parts of this process off your plate so you can concentrate on your responsibilities, while we work diligently to reduce the noise and deliver only the ideal candidates worth your time and attention.
People can make or break your business and we go Beyond a Resume to find high value, committed people ready, willing, and able to add true value.
Primary Industry Experience
Healthcare and Home Healthcare
Talent Acquisition Solutions
Statement of Work Projects
Scroll To Top