Skip to content

Commit

Permalink
Enable automatic refunds for WCPay Subscriptions renewals (#3197)
Browse files Browse the repository at this point in the history
* Enables automatic refunds for WCPay Subscriptions renewals

- WCPay Subscription renewals were missing the payment method metadata which meant
only Manual refunds were supported.

* Set the payment method on failed invoices as well

I also moved the set payment method call to be above set_order_invoice_id
as it calls save() removing the need for us to call save twice.

Co-authored-by: James Allan <james.allan@automattic.com>
  • Loading branch information
mattallan and james-allan authored Oct 25, 2021
1 parent 52a403a commit bb0e5f5
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function handle_invoice_paid( array $body ) {
if ( is_wp_error( $order ) ) {
throw new Rest_Request_Exception( __( 'Unable to generate renewal order for subscription on the "invoice.paid" event.', 'woocommerce-payments' ) );
} else {
$order->set_payment_method( WC_Payment_Gateway_WCPay::GATEWAY_ID );
$this->invoice_service->set_order_invoice_id( $order, $wcpay_invoice_id );
}
}
Expand Down Expand Up @@ -156,6 +157,7 @@ public function handle_invoice_payment_failed( array $body ) {
if ( is_wp_error( $order ) ) {
throw new Rest_Request_Exception( __( 'Unable to generate renewal order for subscription to record the incoming "invoice.payment_failed" event.', 'woocommerce-payments' ) );
} else {
$order->set_payment_method( WC_Payment_Gateway_WCPay::GATEWAY_ID );
$this->invoice_service->set_order_invoice_id( $order, $wcpay_invoice_id );
}
}
Expand Down

0 comments on commit bb0e5f5

Please sign in to comment.