Skip to content

Commit

Permalink
Remove legacy Stripe JS v2 form process
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho committed Mar 25, 2018
1 parent 14bbb27 commit 4863880
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 118 deletions.
94 changes: 7 additions & 87 deletions assets/js/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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( "<input type='hidden' class='stripe_token' name='stripe_token' value='" + token + "'/>" );

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;
Expand All @@ -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() ) {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/stripe.min.js

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions includes/class-wc-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="stripe-source-errors" role="alert"></div>';
}
$this->elements_form();

This comment has been minimized.

Copy link
@kilbot

kilbot Apr 16, 2018

@roykho Why was wc_stripe_use_elements_checkout_form removed? This was a handy hook to provide backwards compatibility. It is also a breaking change.

This comment has been minimized.

Copy link
@roykho

roykho Apr 17, 2018

Author Member

@kilbot Stripe deprecated this method, so we follow suit.

}

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 ) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down
40 changes: 20 additions & 20 deletions languages/woocommerce-gateway-stripe.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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 ""

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4863880

Please sign in to comment.