Skip to content
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

Fix order total for partial capture #3319

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Tweak - Improve UX by using the 3DS verification modal to confirm setup intents for subscription sign-ups, ensuring customers stay on the checkout page.
* Tweak - Display a notice when the Stripe connect URL is not available.
* Fix - Prevent displaying the default admin description on the checkout page when a payment method description is empty.
* Fix - Mismatch in total in order after partial capture via Stripe dashboard

= 8.5.2 - 2024-07-22 =
* Fix - Fixed errors when using Link to purchase subscription products that could lead to duplicate payment attempts.
Expand Down
22 changes: 20 additions & 2 deletions includes/class-wc-stripe-webhook-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,29 @@ public function process_webhook_capture( $notification ) {
// Check and see if capture is partial.
if ( $this->is_partial_capture( $notification ) ) {
$partial_amount = $this->get_partial_amount_to_charge( $notification );
$order->set_total( $partial_amount );
$refunded = $order->get_total() - $partial_amount;
// Create the refund.
$refund = wc_create_refund(
[
'order_id' => $order->get_id(),
'amount' => $refunded,
'reason' => 'Partial capture',
]
);

if ( is_wp_error( $refund ) ) {
WC_Stripe_Logger::log( $refund->get_error_message() );
}

// If order is on "on-hold" change to processing.
if ( $order->has_status( 'on-hold' ) ) {
$order->update_status( 'processing' );
}

$refund_object = $this->get_refund_object( $notification );
$this->update_fees( $order, $refund_object->balance_transaction );
/* translators: partial captured amount */
$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: $%.2f', 'woocommerce-gateway-stripe' ), $partial_amount ) );
} else {
$order->payment_complete( $notification->data->object->id );

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
* Tweak - Improve UX by using the 3DS verification modal to confirm setup intents for subscription sign-ups, ensuring customers stay on the checkout page.
* Tweak - Display a notice when the Stripe connect URL is not available.
* Fix - Prevent displaying the default admin description on the checkout page when a payment method description is empty.
* Fix - Mismatch in total in order after partial capture via Stripe dashboard

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).