From 486388019c392b1eb7b76dcb831c953490b0aa3e Mon Sep 17 00:00:00 2001 From: roykho Date: Sun, 25 Mar 2018 06:30:05 -0700 Subject: [PATCH] Remove legacy Stripe JS v2 form process --- assets/js/stripe.js | 94 ++---------------------- assets/js/stripe.min.js | 2 +- includes/class-wc-gateway-stripe.php | 12 +-- languages/woocommerce-gateway-stripe.pot | 40 +++++----- readme.txt | 1 + 5 files changed, 31 insertions(+), 118 deletions(-) diff --git a/assets/js/stripe.js b/assets/js/stripe.js index 4693607df..671db4a86 100644 --- a/assets/js/stripe.js +++ b/assets/js/stripe.js @@ -5,13 +5,12 @@ jQuery( function( $ ) { var stripe = Stripe( wc_stripe_params.key ); - if ( 'yes' === wc_stripe_params.use_elements ) { - var stripe_elements_options = wc_stripe_params.elements_options.length ? wc_stripe_params.elements_options : {}, - elements = stripe.elements( stripe_elements_options ), - stripe_card, - stripe_exp, - stripe_cvc; - } + var stripe_elements_options = wc_stripe_params.elements_options.length ? wc_stripe_params.elements_options : {}, + elements = stripe.elements( stripe_elements_options ), + stripe_card, + stripe_exp, + stripe_cvc; + /** * Object to handle Stripe elements payment form. @@ -186,9 +185,7 @@ jQuery( function( $ ) { this.reset ); - if ( 'yes' === wc_stripe_params.use_elements ) { - wc_stripe_form.createElements(); - } + wc_stripe_form.createElements(); if ( 'yes' === wc_stripe_params.is_stripe_checkout ) { $( document.body ).on( 'click', '.wc-stripe-checkout-button', function() { @@ -517,71 +514,6 @@ jQuery( function( $ ) { wc_stripe_form.form.submit(); }, - // Legacy - createToken: function() { - var card = $( '#stripe-card-number' ).val(), - cvc = $( '#stripe-card-cvc' ).val(), - expires = $( '#stripe-card-expiry' ).payment( 'cardExpiryVal' ), - first_name = $( '#billing_first_name' ).length ? $( '#billing_first_name' ).val() : wc_stripe_params.billing_first_name, - last_name = $( '#billing_last_name' ).length ? $( '#billing_last_name' ).val() : wc_stripe_params.billing_last_name, - data = { - number : card, - cvc : cvc, - exp_month: parseInt( expires.month, 10 ) || 0, - exp_year : parseInt( expires.year, 10 ) || 0 - }; - - if ( first_name && last_name ) { - data.name = first_name + ' ' + last_name; - } - - if ( $( '#billing_address_1' ).length > 0 ) { - data.address_line1 = $( '#billing_address_1' ).val(); - data.address_line2 = $( '#billing_address_2' ).val(); - data.address_state = $( '#billing_state' ).val(); - data.address_city = $( '#billing_city' ).val(); - data.address_zip = $( '#billing_postcode' ).val(); - data.address_country = $( '#billing_country' ).val(); - } else if ( wc_stripe_params.billing_address_1 ) { - data.address_line1 = wc_stripe_params.billing_address_1; - data.address_line2 = wc_stripe_params.billing_address_2; - data.address_state = wc_stripe_params.billing_state; - data.address_city = wc_stripe_params.billing_city; - data.address_zip = wc_stripe_params.billing_postcode; - data.address_country = wc_stripe_params.billing_country; - } - Stripe.setPublishableKey( wc_stripe_params.key ); - Stripe.createToken( data, wc_stripe_form.onStripeTokenResponse ); - }, - - // Legacy - onStripeTokenResponse: function( status, response ) { - if ( response.error ) { - $( document ).trigger( 'stripeError', response ); - } else { - // check if we allow prepaid cards - if ( 'no' === wc_stripe_params.allow_prepaid_card && 'prepaid' === response.card.funding ) { - response.error = { message: wc_stripe_params.no_prepaid_card_msg }; - - $( document ).trigger( 'stripeError', { response: response } ); - - return false; - } - - // token contains id, last4, and card type - var token = response.id; - - // insert the token into the form so it gets submitted to the server - wc_stripe_form.form.append( "" ); - - if ( $( 'form#add_payment_method' ).length ) { - $( wc_stripe_form.form ).off( 'submit', wc_stripe_form.form.onSubmit ); - } - - wc_stripe_form.form.submit(); - } - }, - onSubmit: function( e ) { if ( ! wc_stripe_form.isStripeChosen() ) { return; @@ -602,12 +534,6 @@ jQuery( function( $ ) { } } - // Process legacy card token. - if ( wc_stripe_form.isStripeCardChosen() && 'no' === wc_stripe_params.use_elements ) { - wc_stripe_form.createToken(); - return false; - } - if ( wc_stripe_form.isSepaChosen() ) { // Check if SEPA owner is filled before proceed. if ( '' === $( '#stripe-sepa-owner' ).val() ) { @@ -681,12 +607,6 @@ jQuery( function( $ ) { wc_stripe_form.block(); - // Process legacy card token. - if ( wc_stripe_form.isStripeCardChosen() && 'no' === wc_stripe_params.use_elements ) { - wc_stripe_form.createToken(); - return false; - } - wc_stripe_form.createSource(); return false; } diff --git a/assets/js/stripe.min.js b/assets/js/stripe.min.js index 090e6057c..c6448fc84 100644 --- a/assets/js/stripe.min.js +++ b/assets/js/stripe.min.js @@ -1 +1 @@ -jQuery(function(e){"use strict";var r=Stripe(wc_stripe_params.key);if("yes"===wc_stripe_params.use_elements)var t,o,i,n=wc_stripe_params.elements_options.length?wc_stripe_params.elements_options:{},s=r.elements(n);var a={getAjaxURL:function(e){return wc_stripe_params.ajaxurl.toString().replace("%%endpoint%%","wc_stripe_"+e)},unmountElements:function(){"yes"===wc_stripe_params.inline_cc_form?t.unmount("#stripe-card-element"):(t.unmount("#stripe-card-element"),o.unmount("#stripe-exp-element"),i.unmount("#stripe-cvc-element"))},mountElements:function(){e("#stripe-card-element").length&&("yes"===wc_stripe_params.inline_cc_form?t.mount("#stripe-card-element"):(t.mount("#stripe-card-element"),o.mount("#stripe-exp-element"),i.mount("#stripe-cvc-element")))},createElements:function(){var r={base:{iconColor:"#666EE8",color:"#31325F",fontSize:"15px","::placeholder":{color:"#CFD7E0"}}},n={focus:"focused",empty:"empty",invalid:"invalid"};r=wc_stripe_params.elements_styling?wc_stripe_params.elements_styling:r,n=wc_stripe_params.elements_classes?wc_stripe_params.elements_classes:n,"yes"===wc_stripe_params.inline_cc_form?(t=s.create("card",{style:r,hidePostalCode:!0})).addEventListener("change",function(r){a.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)}):(t=s.create("cardNumber",{style:r,classes:n}),o=s.create("cardExpiry",{style:r,classes:n}),i=s.create("cardCvc",{style:r,classes:n}),t.addEventListener("change",function(r){a.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)}),o.addEventListener("change",function(r){a.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)}),i.addEventListener("change",function(r){a.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)})),"yes"===wc_stripe_params.is_checkout?e(document.body).on("updated_checkout",function(){t&&a.unmountElements(),a.mountElements()}):(e("form#add_payment_method").length||e("form#order_review").length)&&a.mountElements()},init:function(){"yes"!==wc_stripe_params.is_change_payment_page&&"yes"!==wc_stripe_params.is_pay_for_order_page||e(document.body).trigger("wc-credit-card-form-init"),this.stripe_checkout_submit=!1,e("form.woocommerce-checkout").length&&(this.form=e("form.woocommerce-checkout")),e("form.woocommerce-checkout").on("checkout_place_order_stripe checkout_place_order_stripe_bancontact checkout_place_order_stripe_sofort checkout_place_order_stripe_giropay checkout_place_order_stripe_ideal checkout_place_order_stripe_alipay checkout_place_order_stripe_sepa checkout_place_order_stripe_bitcoin",this.onSubmit),e("form#order_review").length&&(this.form=e("form#order_review")),e("form#order_review, form#add_payment_method").on("submit",this.onSubmit),e("form#add_payment_method").length&&(this.form=e("form#add_payment_method")),e("form.woocommerce-checkout").on("change",this.reset),e(document).on("stripeError",this.onError).on("checkout_error",this.reset),"yes"===wc_stripe_params.use_elements&&a.createElements(),"yes"===wc_stripe_params.is_stripe_checkout&&e(document.body).on("click",".wc-stripe-checkout-button",function(){return a.openModal(),!1})},isStripeChosen:function(){return e("#payment_method_stripe, #payment_method_stripe_bancontact, #payment_method_stripe_sofort, #payment_method_stripe_giropay, #payment_method_stripe_ideal, #payment_method_stripe_alipay, #payment_method_stripe_sepa, #payment_method_stripe_bitcoin").is(":checked")||e("#payment_method_stripe").is(":checked")&&"new"===e('input[name="wc-stripe-payment-token"]:checked').val()||e("#payment_method_stripe_sepa").is(":checked")&&"new"===e('input[name="wc-stripe-payment-token"]:checked').val()},isStripeSaveCardChosen:function(){return e("#payment_method_stripe").is(":checked")&&e('input[name="wc-stripe-payment-token"]').is(":checked")&&"new"!==e('input[name="wc-stripe-payment-token"]:checked').val()||e("#payment_method_stripe_sepa").is(":checked")&&e('input[name="wc-stripe_sepa-payment-token"]').is(":checked")&&"new"!==e('input[name="wc-stripe_sepa-payment-token"]:checked').val()},isStripeCardChosen:function(){return e("#payment_method_stripe").is(":checked")},isBancontactChosen:function(){return e("#payment_method_stripe_bancontact").is(":checked")},isGiropayChosen:function(){return e("#payment_method_stripe_giropay").is(":checked")},isIdealChosen:function(){return e("#payment_method_stripe_ideal").is(":checked")},isSofortChosen:function(){return e("#payment_method_stripe_sofort").is(":checked")},isAlipayChosen:function(){return e("#payment_method_stripe_alipay").is(":checked")},isSepaChosen:function(){return e("#payment_method_stripe_sepa").is(":checked")},isBitcoinChosen:function(){return e("#payment_method_stripe_bitcoin").is(":checked")},isP24Chosen:function(){return e("#payment_method_stripe_p24").is(":checked")},hasSource:function(){return 0=o.owner.phone.length&&delete o.owner.phone,void 0!==o.owner.email&&0>=o.owner.email.length&&delete o.owner.email,void 0!==o.owner.name&&0>=o.owner.name.length&&delete o.owner.name,e("#billing_address_1").length>0?(o.owner.address.line1=e("#billing_address_1").val(),o.owner.address.line2=e("#billing_address_2").val(),o.owner.address.state=e("#billing_state").val(),o.owner.address.city=e("#billing_city").val(),o.owner.address.postal_code=e("#billing_postcode").val(),o.owner.address.country=e("#billing_country").val()):wc_stripe_params.billing_address_1&&(o.owner.address.line1=wc_stripe_params.billing_address_1,o.owner.address.line2=wc_stripe_params.billing_address_2,o.owner.address.state=wc_stripe_params.billing_state,o.owner.address.city=wc_stripe_params.billing_city,o.owner.address.postal_code=wc_stripe_params.billing_postcode,o.owner.address.country=wc_stripe_params.billing_country),o},createSource:function(){var o=a.getOwnerDetails(),i="card";if(a.isBancontactChosen()&&(i="bancontact"),a.isSepaChosen()&&(i="sepa_debit"),a.isIdealChosen()&&(i="ideal"),a.isSofortChosen()&&(i="sofort"),a.isBitcoinChosen()&&(i="bitcoin"),a.isGiropayChosen()&&(i="giropay"),a.isAlipayChosen()&&(i="alipay"),"card"===i)r.createSource(t,o).then(a.sourceResponse);else{switch(i){case"bancontact":case"giropay":case"ideal":case"sofort":case"alipay":o.amount=e("#stripe-"+i+"-payment-data").data("amount"),o.currency=e("#stripe-"+i+"-payment-data").data("currency"),o.redirect={return_url:wc_stripe_params.return_url},wc_stripe_params.statement_descriptor&&(o.statement_descriptor=wc_stripe_params.statement_descriptor)}switch(i){case"sepa_debit":var n=e("#stripe-payment-data"),s=e("#billing_email").length?e("#billing_email").val():n.data("email");o.currency=e("#stripe-"+i+"-payment-data").data("currency"),o.owner.name=e("#stripe-sepa-owner").val(),o.owner.email=s,o.sepa_debit={iban:e("#stripe-sepa-iban").val()},o.mandate={notification_method:wc_stripe_params.sepa_mandate_notification};break;case"ideal":o.ideal={bank:e("#stripe-ideal-bank").val()};break;case"bitcoin":case"alipay":o.currency=e("#stripe-"+i+"-payment-data").data("currency"),o.amount=e("#stripe-"+i+"-payment-data").data("amount");break;case"sofort":o.sofort={country:e("#billing_country").val()}}o.type=i,r.createSource(o).then(a.sourceResponse)}},sourceResponse:function(r){r.error?e(document.body).trigger("stripeError",r):"no"===wc_stripe_params.allow_prepaid_card&&"card"===r.source.type&&"prepaid"===r.source.card.funding?(r.error={message:wc_stripe_params.no_prepaid_card_msg},"yes"===wc_stripe_params.is_stripe_checkout?a.submitError('"):e(document.body).trigger("stripeError",r)):a.processStripeResponse(r.source)},processStripeResponse:function(r){a.reset(),a.form.append(""),e("form#add_payment_method").length&&e(a.form).off("submit",a.form.onSubmit),a.form.submit()},createToken:function(){var r=e("#stripe-card-number").val(),t=e("#stripe-card-cvc").val(),o=e("#stripe-card-expiry").payment("cardExpiryVal"),i=e("#billing_first_name").length?e("#billing_first_name").val():wc_stripe_params.billing_first_name,n=e("#billing_last_name").length?e("#billing_last_name").val():wc_stripe_params.billing_last_name,s={number:r,cvc:t,exp_month:parseInt(o.month,10)||0,exp_year:parseInt(o.year,10)||0};i&&n&&(s.name=i+" "+n),e("#billing_address_1").length>0?(s.address_line1=e("#billing_address_1").val(),s.address_line2=e("#billing_address_2").val(),s.address_state=e("#billing_state").val(),s.address_city=e("#billing_city").val(),s.address_zip=e("#billing_postcode").val(),s.address_country=e("#billing_country").val()):wc_stripe_params.billing_address_1&&(s.address_line1=wc_stripe_params.billing_address_1,s.address_line2=wc_stripe_params.billing_address_2,s.address_state=wc_stripe_params.billing_state,s.address_city=wc_stripe_params.billing_city,s.address_zip=wc_stripe_params.billing_postcode,s.address_country=wc_stripe_params.billing_country),Stripe.setPublishableKey(wc_stripe_params.key),Stripe.createToken(s,a.onStripeTokenResponse)},onStripeTokenResponse:function(r,t){if(t.error)e(document).trigger("stripeError",t);else{if("no"===wc_stripe_params.allow_prepaid_card&&"prepaid"===t.card.funding)return t.error={message:wc_stripe_params.no_prepaid_card_msg},e(document).trigger("stripeError",{response:t}),!1;var o=t.id;a.form.append(""),e("form#add_payment_method").length&&e(a.form).off("submit",a.form.onSubmit),a.form.submit()}},onSubmit:function(r){if(a.isStripeChosen()){if(!(a.isStripeSaveCardChosen()||a.hasSource()||a.hasToken())){if(r.preventDefault(),a.block(),"yes"===wc_stripe_params.is_stripe_checkout&&a.isStripeModalNeeded()&&a.isStripeCardChosen()&&"no"===wc_stripe_params.is_add_payment_page)return"no"===wc_stripe_params.is_pay_for_order_page||(a.openModal(),!1);if(a.isStripeCardChosen()&&"no"===wc_stripe_params.use_elements)return a.createToken(),!1;if(a.isSepaChosen()){if(""===e("#stripe-sepa-owner").val())return e(document.body).trigger("stripeError",{error:{message:wc_stripe_params.no_sepa_owner_msg}}),!1;if(""===e("#stripe-sepa-iban").val())return e(document.body).trigger("stripeError",{error:{message:wc_stripe_params.no_sepa_iban_msg}}),!1}if(a.isBancontactChosen()||a.isGiropayChosen()||a.isIdealChosen()||a.isAlipayChosen()||a.isSofortChosen()||a.isP24Chosen()){if(e("form#order_review").length&&(e("form#order_review").off("submit",this.onSubmit),a.form.submit()),e("form.woocommerce-checkout").length)return e("form.woocommerce-checkout").off("submit",this.onSubmit),!0;e("form#add_payment_method").length&&(e("form#add_payment_method").off("submit",this.onSubmit),a.form.submit())}return a.createSource(),!1}return e("form#add_payment_method").length?(r.preventDefault(),"yes"===wc_stripe_params.is_stripe_checkout&&a.isStripeModalNeeded()&&a.isStripeCardChosen()?(a.openModal(),!1):(a.block(),a.isStripeCardChosen()&&"no"===wc_stripe_params.use_elements?(a.createToken(),!1):(a.createSource(),!1))):void 0}},onCCFormChange:function(){a.reset()},reset:function(){e(".wc-stripe-error, .stripe-source, .stripe_token").remove(),"yes"===wc_stripe_params.is_stripe_checkout&&(a.stripe_submit=!1)},onError:function(r,t){var o=t.error.message,i=a.getSelectedPaymentElement().parents("li").eq(0).find(".stripe-source-errors");"invalid_request_error"!==t.error.type&&"api_connection_error"!==t.error.type&&"api_error"!==t.error.type&&"authentication_error"!==t.error.type&&"rate_limit_error"!==t.error.type||(o=wc_stripe_params.invalid_request_error),"card_error"===t.error.type&&wc_stripe_params.hasOwnProperty(t.error.code)&&(o=wc_stripe_params[t.error.code]),"validation_error"===t.error.type&&wc_stripe_params.hasOwnProperty(t.error.code)&&(o=wc_stripe_params[t.error.code]),a.reset(),e(".woocommerce-NoticeGroup-checkout").remove(),console.log(t.error.message),e(i).html('"),e(".wc-stripe-error").length&&e("html, body").animate({scrollTop:e(".wc-stripe-error").offset().top-200},200),a.unblock()},submitError:function(r){e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),a.form.prepend('
'+r+"
"),a.form.removeClass("processing").unblock(),a.form.find(".input-text, select, input:checkbox").blur();var t="";e("#add_payment_method").length&&(t=e("#add_payment_method")),e("#order_review").length&&(t=e("#order_review")),e("form.checkout").length&&(t=e("form.checkout")),t.length&&e("html, body").animate({scrollTop:t.offset().top-100},500),e(document.body).trigger("checkout_error"),a.unblock()}};a.init()}); \ No newline at end of file +jQuery(function(e){"use strict";var r,t,o,n=Stripe(wc_stripe_params.key),i=wc_stripe_params.elements_options.length?wc_stripe_params.elements_options:{},a=n.elements(i),s={getAjaxURL:function(e){return wc_stripe_params.ajaxurl.toString().replace("%%endpoint%%","wc_stripe_"+e)},unmountElements:function(){"yes"===wc_stripe_params.inline_cc_form?r.unmount("#stripe-card-element"):(r.unmount("#stripe-card-element"),t.unmount("#stripe-exp-element"),o.unmount("#stripe-cvc-element"))},mountElements:function(){e("#stripe-card-element").length&&("yes"===wc_stripe_params.inline_cc_form?r.mount("#stripe-card-element"):(r.mount("#stripe-card-element"),t.mount("#stripe-exp-element"),o.mount("#stripe-cvc-element")))},createElements:function(){var n={base:{iconColor:"#666EE8",color:"#31325F",fontSize:"15px","::placeholder":{color:"#CFD7E0"}}},i={focus:"focused",empty:"empty",invalid:"invalid"};n=wc_stripe_params.elements_styling?wc_stripe_params.elements_styling:n,i=wc_stripe_params.elements_classes?wc_stripe_params.elements_classes:i,"yes"===wc_stripe_params.inline_cc_form?(r=a.create("card",{style:n,hidePostalCode:!0})).addEventListener("change",function(r){s.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)}):(r=a.create("cardNumber",{style:n,classes:i}),t=a.create("cardExpiry",{style:n,classes:i}),o=a.create("cardCvc",{style:n,classes:i}),r.addEventListener("change",function(r){s.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)}),t.addEventListener("change",function(r){s.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)}),o.addEventListener("change",function(r){s.onCCFormChange(),r.error&&e(document.body).trigger("stripeError",r)})),"yes"===wc_stripe_params.is_checkout?e(document.body).on("updated_checkout",function(){r&&s.unmountElements(),s.mountElements()}):(e("form#add_payment_method").length||e("form#order_review").length)&&s.mountElements()},init:function(){"yes"!==wc_stripe_params.is_change_payment_page&&"yes"!==wc_stripe_params.is_pay_for_order_page||e(document.body).trigger("wc-credit-card-form-init"),this.stripe_checkout_submit=!1,e("form.woocommerce-checkout").length&&(this.form=e("form.woocommerce-checkout")),e("form.woocommerce-checkout").on("checkout_place_order_stripe checkout_place_order_stripe_bancontact checkout_place_order_stripe_sofort checkout_place_order_stripe_giropay checkout_place_order_stripe_ideal checkout_place_order_stripe_alipay checkout_place_order_stripe_sepa checkout_place_order_stripe_bitcoin",this.onSubmit),e("form#order_review").length&&(this.form=e("form#order_review")),e("form#order_review, form#add_payment_method").on("submit",this.onSubmit),e("form#add_payment_method").length&&(this.form=e("form#add_payment_method")),e("form.woocommerce-checkout").on("change",this.reset),e(document).on("stripeError",this.onError).on("checkout_error",this.reset),s.createElements(),"yes"===wc_stripe_params.is_stripe_checkout&&e(document.body).on("click",".wc-stripe-checkout-button",function(){return s.openModal(),!1})},isStripeChosen:function(){return e("#payment_method_stripe, #payment_method_stripe_bancontact, #payment_method_stripe_sofort, #payment_method_stripe_giropay, #payment_method_stripe_ideal, #payment_method_stripe_alipay, #payment_method_stripe_sepa, #payment_method_stripe_bitcoin").is(":checked")||e("#payment_method_stripe").is(":checked")&&"new"===e('input[name="wc-stripe-payment-token"]:checked').val()||e("#payment_method_stripe_sepa").is(":checked")&&"new"===e('input[name="wc-stripe-payment-token"]:checked').val()},isStripeSaveCardChosen:function(){return e("#payment_method_stripe").is(":checked")&&e('input[name="wc-stripe-payment-token"]').is(":checked")&&"new"!==e('input[name="wc-stripe-payment-token"]:checked').val()||e("#payment_method_stripe_sepa").is(":checked")&&e('input[name="wc-stripe_sepa-payment-token"]').is(":checked")&&"new"!==e('input[name="wc-stripe_sepa-payment-token"]:checked').val()},isStripeCardChosen:function(){return e("#payment_method_stripe").is(":checked")},isBancontactChosen:function(){return e("#payment_method_stripe_bancontact").is(":checked")},isGiropayChosen:function(){return e("#payment_method_stripe_giropay").is(":checked")},isIdealChosen:function(){return e("#payment_method_stripe_ideal").is(":checked")},isSofortChosen:function(){return e("#payment_method_stripe_sofort").is(":checked")},isAlipayChosen:function(){return e("#payment_method_stripe_alipay").is(":checked")},isSepaChosen:function(){return e("#payment_method_stripe_sepa").is(":checked")},isBitcoinChosen:function(){return e("#payment_method_stripe_bitcoin").is(":checked")},isP24Chosen:function(){return e("#payment_method_stripe_p24").is(":checked")},hasSource:function(){return 0=o.owner.phone.length&&delete o.owner.phone,void 0!==o.owner.email&&0>=o.owner.email.length&&delete o.owner.email,void 0!==o.owner.name&&0>=o.owner.name.length&&delete o.owner.name,e("#billing_address_1").length>0?(o.owner.address.line1=e("#billing_address_1").val(),o.owner.address.line2=e("#billing_address_2").val(),o.owner.address.state=e("#billing_state").val(),o.owner.address.city=e("#billing_city").val(),o.owner.address.postal_code=e("#billing_postcode").val(),o.owner.address.country=e("#billing_country").val()):wc_stripe_params.billing_address_1&&(o.owner.address.line1=wc_stripe_params.billing_address_1,o.owner.address.line2=wc_stripe_params.billing_address_2,o.owner.address.state=wc_stripe_params.billing_state,o.owner.address.city=wc_stripe_params.billing_city,o.owner.address.postal_code=wc_stripe_params.billing_postcode,o.owner.address.country=wc_stripe_params.billing_country),o},createSource:function(){var t=s.getOwnerDetails(),o="card";if(s.isBancontactChosen()&&(o="bancontact"),s.isSepaChosen()&&(o="sepa_debit"),s.isIdealChosen()&&(o="ideal"),s.isSofortChosen()&&(o="sofort"),s.isBitcoinChosen()&&(o="bitcoin"),s.isGiropayChosen()&&(o="giropay"),s.isAlipayChosen()&&(o="alipay"),"card"===o)n.createSource(r,t).then(s.sourceResponse);else{switch(o){case"bancontact":case"giropay":case"ideal":case"sofort":case"alipay":t.amount=e("#stripe-"+o+"-payment-data").data("amount"),t.currency=e("#stripe-"+o+"-payment-data").data("currency"),t.redirect={return_url:wc_stripe_params.return_url},wc_stripe_params.statement_descriptor&&(t.statement_descriptor=wc_stripe_params.statement_descriptor)}switch(o){case"sepa_debit":var i=e("#stripe-payment-data"),a=e("#billing_email").length?e("#billing_email").val():i.data("email");t.currency=e("#stripe-"+o+"-payment-data").data("currency"),t.owner.name=e("#stripe-sepa-owner").val(),t.owner.email=a,t.sepa_debit={iban:e("#stripe-sepa-iban").val()},t.mandate={notification_method:wc_stripe_params.sepa_mandate_notification};break;case"ideal":t.ideal={bank:e("#stripe-ideal-bank").val()};break;case"bitcoin":case"alipay":t.currency=e("#stripe-"+o+"-payment-data").data("currency"),t.amount=e("#stripe-"+o+"-payment-data").data("amount");break;case"sofort":t.sofort={country:e("#billing_country").val()}}t.type=o,n.createSource(t).then(s.sourceResponse)}},sourceResponse:function(r){r.error?e(document.body).trigger("stripeError",r):"no"===wc_stripe_params.allow_prepaid_card&&"card"===r.source.type&&"prepaid"===r.source.card.funding?(r.error={message:wc_stripe_params.no_prepaid_card_msg},"yes"===wc_stripe_params.is_stripe_checkout?s.submitError('
  • '+wc_stripe_params.no_prepaid_card_msg+"
"):e(document.body).trigger("stripeError",r)):s.processStripeResponse(r.source)},processStripeResponse:function(r){s.reset(),s.form.append(""),e("form#add_payment_method").length&&e(s.form).off("submit",s.form.onSubmit),s.form.submit()},onSubmit:function(r){if(s.isStripeChosen()){if(!(s.isStripeSaveCardChosen()||s.hasSource()||s.hasToken())){if(r.preventDefault(),s.block(),"yes"===wc_stripe_params.is_stripe_checkout&&s.isStripeModalNeeded()&&s.isStripeCardChosen()&&"no"===wc_stripe_params.is_add_payment_page)return"no"===wc_stripe_params.is_pay_for_order_page||(s.openModal(),!1);if(s.isSepaChosen()){if(""===e("#stripe-sepa-owner").val())return e(document.body).trigger("stripeError",{error:{message:wc_stripe_params.no_sepa_owner_msg}}),!1;if(""===e("#stripe-sepa-iban").val())return e(document.body).trigger("stripeError",{error:{message:wc_stripe_params.no_sepa_iban_msg}}),!1}if(s.isBancontactChosen()||s.isGiropayChosen()||s.isIdealChosen()||s.isAlipayChosen()||s.isSofortChosen()||s.isP24Chosen()){if(e("form#order_review").length&&(e("form#order_review").off("submit",this.onSubmit),s.form.submit()),e("form.woocommerce-checkout").length)return e("form.woocommerce-checkout").off("submit",this.onSubmit),!0;e("form#add_payment_method").length&&(e("form#add_payment_method").off("submit",this.onSubmit),s.form.submit())}return s.createSource(),!1}return e("form#add_payment_method").length?(r.preventDefault(),"yes"===wc_stripe_params.is_stripe_checkout&&s.isStripeModalNeeded()&&s.isStripeCardChosen()?(s.openModal(),!1):(s.block(),s.createSource(),!1)):void 0}},onCCFormChange:function(){s.reset()},reset:function(){e(".wc-stripe-error, .stripe-source, .stripe_token").remove(),"yes"===wc_stripe_params.is_stripe_checkout&&(s.stripe_submit=!1)},onError:function(r,t){var o=t.error.message,n=s.getSelectedPaymentElement().parents("li").eq(0).find(".stripe-source-errors");"invalid_request_error"!==t.error.type&&"api_connection_error"!==t.error.type&&"api_error"!==t.error.type&&"authentication_error"!==t.error.type&&"rate_limit_error"!==t.error.type||(o=wc_stripe_params.invalid_request_error),"card_error"===t.error.type&&wc_stripe_params.hasOwnProperty(t.error.code)&&(o=wc_stripe_params[t.error.code]),"validation_error"===t.error.type&&wc_stripe_params.hasOwnProperty(t.error.code)&&(o=wc_stripe_params[t.error.code]),s.reset(),e(".woocommerce-NoticeGroup-checkout").remove(),console.log(t.error.message),e(n).html('
  • '+o+"
"),e(".wc-stripe-error").length&&e("html, body").animate({scrollTop:e(".wc-stripe-error").offset().top-200},200),s.unblock()},submitError:function(r){e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),s.form.prepend('
'+r+"
"),s.form.removeClass("processing").unblock(),s.form.find(".input-text, select, input:checkbox").blur();var t="";e("#add_payment_method").length&&(t=e("#add_payment_method")),e("#order_review").length&&(t=e("#order_review")),e("form.checkout").length&&(t=e("form.checkout")),t.length&&e("html, body").animate({scrollTop:t.offset().top-100},500),e(document.body).trigger("checkout_error"),s.unblock()}};s.init()}); \ No newline at end of file diff --git a/includes/class-wc-gateway-stripe.php b/includes/class-wc-gateway-stripe.php index e9dc03f4b..4553eef36 100644 --- a/includes/class-wc-gateway-stripe.php +++ b/includes/class-wc-gateway-stripe.php @@ -339,13 +339,7 @@ public function payment_fields() { } if ( ! $this->stripe_checkout || is_wc_endpoint_url( 'add-payment-method' ) ) { - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { - $this->elements_form(); - } else { - WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' ); - $this->form(); - echo ''; - } + $this->elements_form(); } if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) && ! $this->stripe_checkout ) { @@ -460,9 +454,8 @@ public function payment_scripts() { wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); wp_enqueue_style( 'stripe_styles' ); wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); + wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); $stripe_params = array( 'key' => $this->publishable_key, @@ -497,7 +490,6 @@ public function payment_scripts() { $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); $stripe_params['statement_descriptor'] = $this->statement_descriptor; - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; diff --git a/languages/woocommerce-gateway-stripe.pot b/languages/woocommerce-gateway-stripe.pot index b7d0f07da..566d7bd76 100644 --- a/languages/woocommerce-gateway-stripe.pot +++ b/languages/woocommerce-gateway-stripe.pot @@ -2,10 +2,10 @@ # This file is distributed under the same license as the WooCommerce Stripe Gateway package. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Stripe Gateway 4.0.7\n" +"Project-Id-Version: WooCommerce Stripe Gateway 4.1.0-beta-1\n" "Report-Msgid-Bugs-To: " "https://github.com/woocommerce/woocommerce-gateway-stripe/issues\n" -"POT-Creation-Date: 2018-03-24 17:07:51+00:00\n" +"POT-Creation-Date: 2018-03-25 13:29:02+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -59,7 +59,7 @@ msgid "Stripe charge complete (Charge ID: %s)" msgstr "" #: includes/abstracts/abstract-wc-stripe-payment-gateway.php:447 -#: includes/class-wc-gateway-stripe.php:675 +#: includes/class-wc-gateway-stripe.php:667 #: includes/compat/class-wc-stripe-subs-compat.php:96 #: includes/payment-methods/class-wc-gateway-stripe-bitcoin.php:328 msgid "Payment processing failed. Please retry." @@ -734,58 +734,58 @@ msgid "" "more card numbers." msgstr "" -#: includes/class-wc-gateway-stripe.php:373 +#: includes/class-wc-gateway-stripe.php:367 msgid "Credit or debit card" msgstr "" -#: includes/class-wc-gateway-stripe.php:381 +#: includes/class-wc-gateway-stripe.php:375 msgid "Card Number" msgstr "" -#: includes/class-wc-gateway-stripe.php:389 +#: includes/class-wc-gateway-stripe.php:383 msgid "Expiry Date" msgstr "" -#: includes/class-wc-gateway-stripe.php:397 +#: includes/class-wc-gateway-stripe.php:391 msgid "Card Code (CVC)" msgstr "" -#: includes/class-wc-gateway-stripe.php:469 +#: includes/class-wc-gateway-stripe.php:462 msgid "Please accept the terms and conditions first" msgstr "" -#: includes/class-wc-gateway-stripe.php:470 +#: includes/class-wc-gateway-stripe.php:463 msgid "Please fill in required checkout fields first" msgstr "" -#: includes/class-wc-gateway-stripe.php:488 -#: includes/class-wc-gateway-stripe.php:670 +#: includes/class-wc-gateway-stripe.php:481 +#: includes/class-wc-gateway-stripe.php:662 #: includes/compat/class-wc-stripe-subs-compat.php:91 msgid "" "Sorry, we're not accepting prepaid cards at this time. Your credit card has " "not been charge. Please try with alternative payment method." msgstr "" -#: includes/class-wc-gateway-stripe.php:489 +#: includes/class-wc-gateway-stripe.php:482 msgid "Please enter your IBAN account name." msgstr "" -#: includes/class-wc-gateway-stripe.php:490 +#: includes/class-wc-gateway-stripe.php:483 msgid "Please enter your IBAN account number." msgstr "" -#: includes/class-wc-gateway-stripe.php:570 +#: includes/class-wc-gateway-stripe.php:562 msgid "Place Order" msgstr "" -#: includes/class-wc-gateway-stripe.php:751 +#: includes/class-wc-gateway-stripe.php:743 #: includes/class-wc-stripe-order-handler.php:140 #: includes/class-wc-stripe-webhook-handler.php:186 #: includes/payment-methods/class-wc-gateway-stripe-sepa.php:351 msgid "This card is no longer available and has been removed." msgstr "" -#: includes/class-wc-gateway-stripe.php:770 +#: includes/class-wc-gateway-stripe.php:762 #: includes/class-wc-stripe-order-handler.php:158 #: includes/class-wc-stripe-webhook-handler.php:205 #: includes/compat/class-wc-stripe-sepa-subs-compat.php:194 @@ -796,22 +796,22 @@ msgid "" "later." msgstr "" -#: includes/class-wc-gateway-stripe.php:851 +#: includes/class-wc-gateway-stripe.php:843 #. translators: error message msgid "This represents the fee Stripe collects for the transaction." msgstr "" -#: includes/class-wc-gateway-stripe.php:852 +#: includes/class-wc-gateway-stripe.php:844 msgid "Stripe Fee:" msgstr "" -#: includes/class-wc-gateway-stripe.php:888 +#: includes/class-wc-gateway-stripe.php:880 msgid "" "This represents the net total that will be credited to your Stripe bank " "account. This may be in the currency that is set in your Stripe account." msgstr "" -#: includes/class-wc-gateway-stripe.php:889 +#: includes/class-wc-gateway-stripe.php:881 msgid "Stripe Payout:" msgstr "" diff --git a/readme.txt b/readme.txt index c335798c0..90e3f27f0 100644 --- a/readme.txt +++ b/readme.txt @@ -137,6 +137,7 @@ We will completely remove the older form by version 5.0. * Add - Compatibility with Payment Request/Apple Pay and Product Addons in cart page. * Add - $post object on hook `wc_stripe_hide_payment_request_on_product_page`. * Update - Stripe API version to 2018-02-28. +* Remove - Hard deprecated Stripe JS v2 credit card form process. = 4.0.7 - 2018-02-23 = * Fix - Potential conflict issue when adding payment method from another payment gateway.