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

Conversation

peterwilsoncc
Copy link

@peterwilsoncc peterwilsoncc commented Apr 29, 2025

Supersedes #3855
Related WOODEP-1
Related https://github.com/woocommerce/woocommerce-deposits/issues/715 (specific task)
Related https://github.com/woocommerce/woocommerce-deposits/issues/375 (project)

Changes proposed in this Pull Request:

Introduces support of the deposits feature for processing scheduled and subsequent orders in WooCommerce Deposits. This is to allow merchants using the Deposits extension to be paid automatically on the payment plan schedule and as the merchant completes orders with a fixed or percentage deposit.

Introduces WC_Stripe_Deposits_Trait for supporting the feature.

Initilization of the feature requires:

  • the presence of the wc_deposits_init() function (available as the Deposits extension is included)
  • the gateway supports tokenization

Similar to Pre-Orders, the token/intent is stored against the order rather than as a user payment method. The intent is detached once the order is fully paid to prevent live intents from being stored in the database longer than they are required. The intent details are retained after the final payment to allow for refunds.

This does not include any UI changes so testing on mobile is not required.

Note

PHPUnit tests have been started but a currently broken.

I'm going to need some assistance about how to test with Deposits. I was going to base them on the pre-orders tests but I can't see what I need to mock differently for Desposits.

Testing instructions

  1. Enable Deposits using the branch https://github.com/woocommerce/woocommerce-deposits/pull/720
  2. Create a Deposits payment plan product:
    • Name the Product: Deposits 2 day payment plan -- I'll use this name below
    • Account for the minimum allowed charge for each payment
    • Two day payment plan
    • Payment plan is required
    • 50% at checkout, 50% 1 day later
  3. Create a Deposits fixed amount product
    • Name the product: $2 Deposits product ($1 deposit) -- I'll use this name below
    • You may need to modify the amounts to account for minimum payment amounts
    • Deposit is required
    • Total cost: $2
    • Deposit amount: $1
  4. Create a Deposits percentage amount product
    • Name the product: $2 Deposits product (50% deposit) -- I'll use this name below
    • You may need to modify the amounts to account for minimum payment amounts
    • Deposit is required
    • Total cost: $2
    • Deposit amount: 50%
  5. Purchase the product Deposits 2 day payment plan
  6. Ensure the 50% upfront charge is processed by Stripe successfully
  7. In the database, modify the scheduled payment date to bring it forward (I usually set it to a few seconds after the intial purchase). The order can be found in the wp_wc_orders table, the charge date to modify is the date_created_gmt column
  8. Run the WP CLI command wp eval "do_action( 'woocommerce_invoice_scheduled_orders' );" to emulate the cron job firing.
  9. Wait two or three minutes for the Action Scheduler tasks to complete, the second order will show as processing or completed once this is done. If the second order status shows as pending payment, this step has failed.
  10. View the stripe logs in the dashboard.stripe.com
  11. Ensure that GET requests are selected in the Methods filter
  12. Ensure that the payment intent detach endpoint has been hit
  13. Purchase the $2 Deposits product ($1 deposit) product
  14. Ensure the $1 upfront charge is processed by Stripe successfully
  15. View the order in the WP Dashboard
  16. Click the "Charge remaining amount" button below the line item
  17. You will be redirected to the new order, ensure this:
  • is showing as paid
  • is showing as charging the customer $1
  1. View the stripe logs in dashboard.stripe.com
  2. Ensure that GET requests are selected in the Methods filter
  3. Ensure the payment intent detach endpoint has been hit
  4. Purchase the $2 Deposits product (50% deposit) product
  5. Ensure the $1 upfront charge is processed by Stripe successfully
  6. View the order in the WP Dashboard
  7. Click the "Charge remaining amount" button below the line item
  8. You will be redirected to the new order, ensure this:
  • is showing as paid
  • is showing as charging the customer $1
  1. View the stripe logs in dashboard.stripe.com
  2. Ensure that GET requests are selected in the Methods filter
  3. Ensure the payment intent detach endpoint has been hit

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Add - Introduce support for automatic payment processing in WooCommerce Deposits

Comment

Post merge

peterwilsoncc and others added 30 commits April 28, 2025 10:27
/**
* Deposits order sets up payment intent.
*/
public function test_deposit_product_uses_setup_intents() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing: I think I've done the mock incorrectly.

There was 1 error:

1) WC_Stripe_UPE_Payment_Gateway_Test::test_deposit_product_uses_setup_intents
Cannot modify header information - headers already sent by (output started at /tmp/wordpress-tests-lib/includes/bootstrap.php:261)

/tmp/wordpress/wp-includes/pluggable.php:1450
/tmp/wordpress/wp-includes/pluggable.php:1560
/var/www/html/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php:1600
/var/www/html/wp-content/plugins/woocommerce-gateway-stripe/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway.php:2313
phpvfscomposer:///var/www/html/wp-content/plugins/woocommerce-gateway-stripe/vendor/phpunit/phpunit/phpunit:106

@peterwilsoncc peterwilsoncc requested a review from dkotter April 30, 2025 03:37
Comment on lines 310 to 313
// If cart or order contains a product that requires a payment token, enable payment method if it's reusable.
if ( $this->cart_contains_deposit() || ( ! empty( $order_id ) && $this->order_contains_deposit( $order_id ) ) ) {
return $this->is_reusable();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to just be a duplicate of the above unless I'm missing something in looking at this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to just be a duplicate of the above unless I'm missing something in looking at this

You're not missing anything, it is. I've removed it in d33b94d

@dkotter
Copy link

dkotter commented May 1, 2025

@vikrampm1 This is ready for the next step but because we normally don't work on Stripe, not sure what that step should be, if we should be aiming to QA this or just pass to the appropriate Woo team to review

@vikrampm1
Copy link

@dkotter we can do QA and then pass it over to Woo to take it from there. However, not sure how to track this over Linear as we also don't have the Stripe team setup. This might be a one-off that we need to track here and hand off once QA is complete cc @ankitguptaindia @qasumitbagthariya

@DustinHartzler
Copy link

@vikrampm1 -- will this only work with the Stripe plugin? Or can it work with WooPayments too?

@peterwilsoncc
Copy link
Author

@DustinHartzler WooPayments will need to add the feature, similar to support for Pre-orders and Subscriptions. On the Deposits PT, I was asked to prioritize this extension.

The code for the Deposits PR is in https://github.com/woocommerce/woocommerce-deposits/pull/720 (ie, unreleased). If WooPayments will require additional hooks, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants