* expose a allowSavedCards option to JS on stripe settings data

* hide 'save my card' checkbox if merchant disables saved cards

* use stripe allowSavedCards option to control "Save my card" checkbox

* (linter) remove unnecessary useEffect dependency:

- stripePromise const is defined outside component, so hook doesn't
depend on it

* clarify comment about saved cards and supports( tokenization )

* correct comment about save card merchant option - doesn't affect paying with previously saved payment methods

* use true boolean value for stripe allow saved cards setting:

previously was using woo option `yes no` style, other JS settings all use true bool

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>

* fix client side check now `allowSavedCards` is true boolean

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
This commit is contained in:
Rua Haszard 2020-05-15 11:35:17 +12:00 committed by GitHub
parent e5c500c70d
commit 89f843b2b7
2 changed files with 17 additions and 3 deletions

View File

@ -7,7 +7,7 @@ import { useEffect, useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { loadStripe } from '../stripe-utils';
import { getStripeServerData, loadStripe } from '../stripe-utils';
import { StripeCreditCard, getStripeCreditCardIcons } from './payment-method';
import { PAYMENT_METHOD_NAME } from './constants';
@ -22,7 +22,7 @@ const StripeComponent = ( props ) => {
setErrorMessage( error.message );
}
} );
}, [] );
}, [ setErrorMessage ] );
useEffect( () => {
if ( errorMessage ) {
@ -57,7 +57,7 @@ const stripeCcPaymentMethod = {
'woo-gutenberg-products-block'
),
supports: {
savePaymentInfo: true,
savePaymentInfo: getStripeServerData().allowSavedCards,
},
};

View File

@ -104,9 +104,23 @@ final class Stripe extends AbstractPaymentMethodType {
],
'inline_cc_form' => $this->get_inline_cc_form(),
'icons' => $this->get_icons(),
'allowSavedCards' => $this->get_allow_saved_cards(),
];
}
/**
* Determine if store allows cards to be saved during checkout.
*
* @return bool True if merchant allows shopper to save card (payment method) during checkout).
*/
private function get_allow_saved_cards() {
// This assumes that Stripe supports `tokenization` - currently this is true, based on
// https://github.com/woocommerce/woocommerce-gateway-stripe/blob/master/includes/class-wc-gateway-stripe.php#L95 .
// See https://github.com/woocommerce/woocommerce-gateway-stripe/blob/ad19168b63df86176cbe35c3e95203a245687640/includes/class-wc-gateway-stripe.php#L271 and
// https://github.com/woocommerce/woocommerce/wiki/Payment-Token-API .
return apply_filters( 'wc_stripe_display_save_payment_method_checkbox', filter_var( $this->settings['saved_cards'], FILTER_VALIDATE_BOOLEAN ) );
}
/**
* Returns the label to use accompanying the total in the stripe statement.
*