Skip to content

Commit

Permalink
Updates to 6.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
WooCommerce committed Apr 11, 2024
1 parent d3348c6 commit cc9b3f8
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 233 deletions.
13 changes: 13 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
*** Woo Subscriptions Changelog ***

2024-04-11 - version 6.2.0
* Add: Declare WooCommerce as a plugin dependency in the plugin header.
* Fix: Ensure next payment dates are only extended when early renewal orders paid via the modal are fully paid. Prevents extending dates on authorized but not captured payments.
* Fix: Updated the switching calculator to handle situations where an upgrade has a new price per day less than the old price per day. Previously this would result in a negative upgrade cost.
* Fix: Update the failing payment method on a subscription when customers successfully pay for a failed renewal order via the block checkout.
* Fix: Resolved an issue that would cause subscriptions to be directly cancelled by the WooCommerce process of automatically cancelling unpaid orders in-line with the hold stock setting.
* Fix: Prevent duplicate status transition notes on subscriptions and potential infinite loops when processing subscription status transitions.
* Fix: Resolved an issue that could lead to "Undefined array key 'order-received'" errors.
* Fix: Resolved errors that could occur when paying for renewal orders via the checkout when the store has custom checkout fields.
* Fix: Resolved database errors that would occur when ordering the subscriptions list table by the 'Last order date' on sites with HPOS enabled.
* Dev: Introduced a new filter ('wcs_setup_cart_for_subscription_initial_payment') to enable third-party plugins to use the pay-for-order flow to complete a subscription's initial payment.
* Dev: Updated subscriptions-core to 7.0.0.

2024-03-28 - version 6.1.0
* Fix: Ensure the subscription renewal payment process doesn't attempt to reprocess previously paid renewal orders.
* Fix: Resolved an issue where discounts, when reapplied to failed or manual subscription order payments, would incorrectly account for inclusive tax.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ public static function process_early_renewal_request() {
wc_add_notice( __( 'Payment for the renewal order was unsuccessful with your payment method on file, please try again.', 'woocommerce-subscriptions' ), 'error' );
wp_redirect( wcs_get_early_renewal_url( $subscription ) );
exit();
} else {
}

// Paid early renewals trigger the subscription payment complete hooks, extend next payment dates and reset suspension counts and user roles.
// Orders which are on-hold (manual payment or auth/capture gateways) will be handled when the order eventually is marked as payment complete (process/completed).
if ( $renewal_order->is_paid() ) {
// Trigger the subscription payment complete hooks and reset suspension counts and user roles.
$subscription->payment_complete();

Expand Down
32 changes: 32 additions & 0 deletions includes/switching/class-wcs-switch-totals-calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public function calculate_prorated_totals() {
$this->reset_prorated_price( $switch_item );

$upgrade_cost = $this->calculate_upgrade_cost( $switch_item );

// If a negative upgrade cost has been calculated. Have the customer pay a full price minus what they are owed and set the next payment to be the new products first payment date.
if ( $upgrade_cost < 0 ) {
$upgrade_cost = $this->calculate_fully_reduced_upgrade_cost( $cart_item_key, $switch_item );
}

$this->set_upgrade_cost( $switch_item, $upgrade_cost );
}
}
Expand Down Expand Up @@ -514,6 +520,32 @@ protected function get_first_payment_timestamp( $cart_item_key ) {
return $this->cart->cart_contents[ $cart_item_key ]['subscription_switch']['first_payment_timestamp'];
}

/**
* Calculates the cost of the upgrade when the customer pays the new product's full price minus the amount paid and still owing.
*
* This function is used when a switch results in a negative upgrade cost which typically occurs when stores use the `wcs_switch_proration_switch_type` filter to change the default switch type.
* For example, if a customer is switching from a monthly subscription to a yearly subscription, they will pay the yearly product's full price minus whatever is still owed on the monthly product's price.
*
* eg $20/month switched to a $200 yearly product. The upgrade cost would be 200 - ((20/30) * days-left-in-the-current-billing-term).
* Switching on the first day of the month would result in the following calculation: 200 - ((20/30) * 30) = 200 - 20 = 180. The full $20 is owed.
* Switching halfway through the month would result in the following calculation: 200 - ((20/30) * 15) = 200 - 10 = 190. The customer is owed $10 or half what they paid.
*
* @param string $cart_item_key The switch item's cart item key.
* @param WCS_Switch_Cart_Item $switch_item The switch item.
*
* @return float The upgrade cost.
*/
protected function calculate_fully_reduced_upgrade_cost( $cart_item_key, $switch_item ) {
// When a customer pays the full new product price minus the amount already paid, we need to reduce the prepaid term and the subscription's next payment is 1 billing cycle away.
$this->cart->cart_contents[ $cart_item_key ]['subscription_switch']['first_payment_timestamp'] = WC_Subscriptions_Product::get_first_renewal_payment_time( $switch_item->product );

// The customer is owed whatever they didn't use. If they paid $100 for a monthly subscription and are switching half way through the month, they are owed $50.
$remaining_amount_not_consumed = ( $switch_item->get_total_paid_for_current_period() / $switch_item->get_days_in_old_cycle() ) * $switch_item->get_days_until_next_payment();

// The customer pays the full price of the new product minus the amount they didn't use.
return ( WC_Subscriptions_Product::get_price( $switch_item->product ) * $switch_item->cart_item['quantity'] ) - ( $remaining_amount_not_consumed );
}

/** Helpers */

/**
Expand Down
Loading

0 comments on commit cc9b3f8

Please sign in to comment.