Skip to content

Enable Deposits Support #4273

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

Draft
wants to merge 42 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5605108
Introduce forced tokenization trait.
peterwilsoncc Feb 7, 2025
a1c06e7
Use forced tokenization trait.
peterwilsoncc Feb 7, 2025
0a476dd
UPE GW: Init forced tokenization.
peterwilsoncc Feb 7, 2025
d9a1797
Pre-flight tokens.
peterwilsoncc Feb 10, 2025
30a9323
Charging and saving order tokens.
peterwilsoncc Feb 10, 2025
3735d7c
Set tokens to reusable if the order requires a token.
peterwilsoncc Feb 10, 2025
9ec83d6
Process orders and save token if requuired.
peterwilsoncc Feb 10, 2025
ca44190
Set future usage to "off_session" for the orders which requires token…
iamdharmesh Feb 26, 2025
0cbd05c
Update charge_order_token function to collect payment successfully.
iamdharmesh Feb 26, 2025
8cab155
Detach the payment method once complete.
peterwilsoncc Mar 3, 2025
8a0e8ef
Docblocks and tidyup
peterwilsoncc Mar 5, 2025
9c9fe6a
Use payment method getter.
peterwilsoncc Mar 5, 2025
c102452
Document `get_order_payment_token()`.
peterwilsoncc Mar 6, 2025
0d32d55
Only enable feature for UPE checkout.
peterwilsoncc Mar 14, 2025
d8ce53c
Remove legacy handling.
peterwilsoncc Mar 17, 2025
1076469
Add existing filter wc_stripe_display_save_payment_method_checkbox to…
peterwilsoncc Mar 17, 2025
8e46652
Add documentation cross references to wc_stripe_display_save_payment_…
peterwilsoncc Mar 17, 2025
e7791de
Save user payment method when forced.
peterwilsoncc Mar 17, 2025
7677db4
Initialize forced tokenization in additional locations.
peterwilsoncc Mar 26, 2025
f239a70
Require the gateway support tokenization in order to support forcing it.
peterwilsoncc Mar 26, 2025
dab50f1
Ensure intent is available for reuse.
peterwilsoncc Mar 31, 2025
3eadb72
Set tokens to reusable if the order requires a token.
peterwilsoncc Feb 10, 2025
3254f24
Rename Forced Tokenization Feature to Deposits.
peterwilsoncc Apr 15, 2025
fed1fcc
Update check for deposits being enabled.
peterwilsoncc Apr 15, 2025
374e5f8
Check for cart/order deposits against existing classes.
peterwilsoncc Apr 15, 2025
6ef81ed
Rename has_forced_tokenization check to has_deposit.
peterwilsoncc Apr 15, 2025
66dc3dd
Remove user payment method saving.
peterwilsoncc Apr 28, 2025
06637c6
Remove check for user payment method tokenization.
peterwilsoncc Apr 28, 2025
d385c3c
Account for renamed methods.
peterwilsoncc Apr 28, 2025
bfbba47
Account for renamed method in subs trait.
peterwilsoncc Apr 28, 2025
91612fc
Get top most order within the trait.
peterwilsoncc Apr 28, 2025
00dfbe8
CS Fixes
peterwilsoncc Apr 28, 2025
9ec113a
Modify various hooks to use deposits rather than generic tokenization.
peterwilsoncc Apr 29, 2025
b8d34b6
Test a deposit order uses payment intent.
peterwilsoncc Apr 29, 2025
e6d442b
Check for feature support to determine whether to set up off_session …
peterwilsoncc Apr 29, 2025
29ab885
Mock payment intent.
peterwilsoncc Apr 30, 2025
20b2a39
Less broken tests.
peterwilsoncc Apr 30, 2025
d33b94d
Remove duplicate block of code.
peterwilsoncc May 1, 2025
bab21bb
Clarify deposits comment.
peterwilsoncc May 1, 2025
10255ec
Update comments refering to forced tokenization.
peterwilsoncc May 1, 2025
d344dba
Rename property to refer to deposits.
peterwilsoncc May 1, 2025
9bf1e32
Merge branch 'develop' into enh/deposits-feature-support
peterwilsoncc May 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions includes/abstracts/abstract-wc-stripe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {

use WC_Stripe_Subscriptions_Trait;
use WC_Stripe_Pre_Orders_Trait;
use WC_Stripe_Deposits_Trait;

/**
* The delay between retries.
Expand Down Expand Up @@ -512,7 +513,7 @@ public function generate_payment_request( $order, $prepared_payment_method ) {
'signature' => $this->get_order_signature( $order ),
];

if ( $this->has_subscription( $order->get_id() ) ) {
if ( $this->has_subscription( $order->get_id() ) || $this->order_contains_deposit( $order ) ) {
$metadata += [
'payment_type' => 'recurring',
];
Expand Down Expand Up @@ -1585,7 +1586,7 @@ public function update_existing_intent( $intent, $order, $prepared_source ) {

$request['payment_method_types'] = [ WC_Stripe_Payment_Methods::CARD ];

if ( $this->has_subscription( $order->get_id() ) ) {
if ( $this->has_subscription( $order->get_id() ) || $this->order_contains_deposit( $order ) ) {
// If this is a failed subscription order payment, the intent should be
// prepared for future usage.
$request['setup_future_usage'] = 'off_session';
Expand Down
4 changes: 4 additions & 0 deletions includes/class-wc-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public function __construct() {
// Check if pre-orders are enabled and add support for them.
$this->maybe_init_pre_orders();

// Check if forced tokenization is enabled and add support for it.
$this->maybe_init_deposits();

// Get setting values.
$this->title = $this->get_validated_option( 'title' );
$this->description = $this->get_validated_option( 'description' );
Expand Down Expand Up @@ -260,6 +263,7 @@ public function payment_fields() {

$this->elements_form();

/** Documented in includes/payment-methods/class-wc-stripe-upe-payment-gateway.php */
if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok.

$this->save_payment_method_checkbox();
Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-stripe-blocks-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ private function get_show_save_option() {
// 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 .
/** Documented in includes/payment-methods/class-wc-stripe-upe-payment-gateway.php */
return apply_filters( 'wc_stripe_display_save_payment_method_checkbox', filter_var( $saved_cards, FILTER_VALIDATE_BOOLEAN ) );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-stripe-intent-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ private function build_base_payment_intent_request_params( $payment_information

// If the customer is saving the payment method to the store or has a subscription, we should set the setup_future_usage to off_session.
// Only exception is when using a confirmation token. For confirmations tokens, the setup_future_usage is set within the payment method.
if ( ! $is_using_confirmation_token && ( $payment_information['save_payment_method_to_store'] || ! empty( $payment_information['has_subscription'] ) ) ) {
if ( ! $is_using_confirmation_token && ( $payment_information['save_payment_method_to_store'] || ! empty( $payment_information['has_subscription'] ) || $payment_information['has_deposit'] ) ) {
$request['setup_future_usage'] = 'off_session';
}

Expand Down
Loading
Loading