-
Notifications
You must be signed in to change notification settings - Fork 216
Handling saving of methods when SPE is enabled #4126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 27 commits
30b59b7
c323ffd
1e0e717
78ea9ab
ea2378d
c4a0541
ee6a6cc
97f688e
c1e4c4e
da8c8b4
2e3b7e1
5b2c93b
4b7c782
1f22ae0
6e4668f
f87b4a4
059d02e
83164a7
ea5d2b4
cc7f828
8f99920
a746281
2c4c641
5a52073
1121533
ccaac50
2a94ea1
2fcbe12
fa10e53
442c0f4
583838a
74da162
977b38c
a8f4c97
c3a62ea
a695e94
b32cdaf
449afdf
e8b8d08
2670f59
80618ca
7a8afd2
e4e6202
4b09ce3
d0db66b
7f9d3dd
13f4cb3
d410310
fed2e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NON_REUSABLE_METHODS } from 'wcstripe/stripe-utils/constants'; | ||
|
||
export const handleDisplayOfSavingCheckbox = ( method ) => { | ||
const saveCardInfoContainer = document.querySelector( | ||
'.wc-block-components-payment-methods__save-card-info' | ||
); | ||
if ( saveCardInfoContainer ) { | ||
saveCardInfoContainer.style.display = NON_REUSABLE_METHODS.includes( | ||
method | ||
) | ||
? 'none' | ||
: 'block'; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,17 +133,6 @@ const PaymentElements = ( { | |
}; | ||
|
||
if ( getBlocksConfiguration()?.isSPEEnabled ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the unnecessary styles since radio buttons will go away soon. |
||
options.appearance.rules = { | ||
...options.appearance?.rules, | ||
...{ | ||
'.RadioIcon': { | ||
width: '2.1em', | ||
}, | ||
'.RadioIconOuter': { | ||
strokeWidth: '2px', | ||
}, | ||
}, | ||
}; | ||
options = { | ||
...options, | ||
...{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,9 @@ import { | |
removeCashAppLimitNotice, | ||
} from 'wcstripe/stripe-utils/cash-app-limit-notice-handler'; | ||
import { isLinkEnabled } from 'wcstripe/stripe-utils'; | ||
import { | ||
PAYMENT_METHOD_CARD, | ||
PAYMENT_METHOD_CASHAPP, | ||
} from 'wcstripe/stripe-utils/constants'; | ||
import { applySinglePaymentElementStyles } from 'wcstripe/blocks/upe/apply-single-payment-element-styles'; | ||
import { PAYMENT_METHOD_CASHAPP } from 'wcstripe/stripe-utils/constants'; | ||
import { applySinglePaymentElementStyles } from 'wcstripe/blocks/upe/spe/apply-single-payment-element-styles'; | ||
import { handleDisplayOfSavingCheckbox } from 'wcstripe/blocks/upe/spe/handle-display-of-saving-checkbox'; | ||
|
||
const noop = () => null; | ||
|
||
|
@@ -309,10 +307,7 @@ const PaymentProcessor = ( { | |
removeCashAppLimitNotice(); | ||
} | ||
// Apply single payment element styles if the selected payment method is card and SPE is enabled. | ||
if ( | ||
selectedPaymentMethodType === PAYMENT_METHOD_CARD && | ||
getBlocksConfiguration()?.isSPEEnabled | ||
) { | ||
if ( getBlocksConfiguration()?.isSPEEnabled ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The selected payment method type here is always card, so it is redundant. |
||
applySinglePaymentElementStyles(); | ||
} | ||
}, [ selectedPaymentMethodType ] ); | ||
|
@@ -337,6 +332,9 @@ const PaymentProcessor = ( { | |
const onSelectedPaymentMethodChange = ( { value, complete } ) => { | ||
setSelectedPaymentMethodType( value.type ); | ||
setIsPaymentElementComplete( complete ); | ||
if ( getBlocksConfiguration()?.isSPEEnabled ) { | ||
handleDisplayOfSavingCheckbox( value.type ); | ||
} | ||
}; | ||
|
||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NON_REUSABLE_METHODS } from 'wcstripe/stripe-utils/constants'; | ||
|
||
export const handleDisplayOfSavingCheckbox = ( method ) => { | ||
const saveCardInfoContainer = document.querySelector( | ||
'.woocommerce-SavedPaymentMethods-saveNew' | ||
); | ||
if ( saveCardInfoContainer ) { | ||
saveCardInfoContainer.style.display = NON_REUSABLE_METHODS.includes( | ||
method | ||
) | ||
? 'none' | ||
: 'block'; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,7 @@ public function __construct() { | |
$this->enabled = $this->get_option( 'enabled' ); | ||
$this->sepa_tokens_for_other_methods = 'yes' === $this->get_option( 'sepa_tokens_for_other_methods' ); | ||
$this->spe_enabled = WC_Stripe_Feature_Flags::is_spe_available() && 'yes' === $this->get_option( 'single_payment_element' ); | ||
$this->saved_cards = ! $this->spe_enabled && 'yes' === $this->get_option( 'saved_cards' ); // @todo Temporarily disabling saving of methods when SPE is enabled | ||
$this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); | ||
$this->testmode = WC_Stripe_Mode::is_test(); | ||
$this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; | ||
$this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; | ||
|
@@ -653,10 +653,7 @@ public function payment_fields() { | |
<p><?php echo wp_kses_post( $this->get_description() ); ?></p> | ||
<?php endif; ?> | ||
|
||
<?php | ||
// @todo Temporarily disabling test instructions when SPE is enabled. | ||
if ( $this->testmode && ! $this->spe_enabled ) : | ||
?> | ||
<?php if ( $this->testmode ) : ?> | ||
<p class="testmode-info"> | ||
<?php | ||
printf( | ||
|
@@ -899,6 +896,15 @@ private function process_payment_with_payment_method( int $order_id ) { | |
$upe_payment_method = $this->payment_methods[ $selected_payment_type ] ?? null; | ||
$response_args = []; | ||
|
||
if ( $this->spe_enabled && isset( $payment_method_details->type ) ) { | ||
foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) { | ||
$payment_method = new $payment_method_class(); | ||
if ( $payment_method->get_id() === $payment_method_details->type ) { | ||
$upe_payment_method = $payment_method; | ||
} | ||
} | ||
Mayisha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Make sure that we attach the payment method and the customer ID to the order meta data. | ||
$this->set_payment_method_id_for_order( $order, $payment_method_id ); | ||
$this->set_customer_id_for_order( $order, $payment_information['customer'] ); | ||
|
@@ -2009,18 +2015,27 @@ public function create_token_from_setup_intent( $setup_intent_id, $user ) { | |
|
||
$payment_method_id = $setup_intent->payment_method; | ||
|
||
if ( isset( $this->payment_methods[ $payment_method_type ] ) ) { | ||
wjrosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$payment_method = null; | ||
if ( $this->spe_enabled ) { | ||
$payment_method_type = $payment_method_details['type'] ?? $payment_method_details->type ?? null; | ||
if ( ! empty( $payment_method_type ) ) { | ||
foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) { | ||
$payment_method_instance = new $payment_method_class(); | ||
if ( $payment_method_instance->get_id() === $payment_method_type ) { | ||
$payment_method = $payment_method_instance; | ||
wjrosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} else { | ||
$payment_method = $this->payment_methods[ $payment_method_type ]; | ||
} | ||
|
||
if ( $payment_method->get_id() !== $payment_method->get_retrievable_type() ) { | ||
$payment_method_id = $payment_method_details[ $payment_method_type ]->generated_sepa_debit; | ||
} | ||
if ( $payment_method->get_id() !== $payment_method->get_retrievable_type() ) { | ||
$payment_method_id = $payment_method_details[ $payment_method_type ]->generated_sepa_debit; | ||
} | ||
|
||
$payment_method_object = $this->stripe_request( 'payment_methods/' . $payment_method_id ); | ||
|
||
$payment_method = $this->payment_methods[ $payment_method_type ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was redundant. |
||
|
||
$customer = new WC_Stripe_Customer( wp_get_current_user()->ID ); | ||
$customer->clear_cache(); | ||
|
||
|
@@ -2847,10 +2862,6 @@ private function get_payment_method_types_for_intent_creation( | |
* @return bool - True if the payment method is reusable and the saved cards feature is enabled for the gateway and there is no subscription item in the cart, false otherwise. | ||
*/ | ||
private function should_upe_payment_method_show_save_option( $payment_method ) { | ||
if ( $this->spe_enabled ) { // @todo Temporary disabling saving payment methods for SPE. | ||
return false; | ||
} | ||
|
||
if ( $payment_method->is_reusable() ) { | ||
// If a subscription in the cart, it will be saved by default so no need to show the option. | ||
return $this->is_saved_cards_enabled() && ! $this->is_subscription_item_in_cart() && ! $this->is_pre_order_charged_upon_release_in_cart(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge both files on the next PR so this one doesn't get too big. I will also add tests for this there.