From 74ea6cc76a45cc76eb06d73444a9890031f0507c Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Mon, 28 Oct 2024 09:44:54 -0600 Subject: [PATCH] fix: let "Cover fees" checkbox work with any payment method (#3491) * fix: let "Cover fees" checkbox work with any payment method * fix: only enable for Stripe payment gateway, for now * fix: support transaction fees for WooPayments too * chore: update method names + inline docs to exclude Stripe mentions * fix: remove WooPayments as a supported gateway for transaction fees, for now * fix: make default for newspack_donations_allow_covering_fees always true --- .../class-woocommerce-cover-fees.php | 40 +++++++++---------- src/other-scripts/wc-cover-fees/index.js | 30 ++++++++++---- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/includes/reader-revenue/woocommerce/class-woocommerce-cover-fees.php b/includes/reader-revenue/woocommerce/class-woocommerce-cover-fees.php index a3ea13c4c2..abba76c66b 100644 --- a/includes/reader-revenue/woocommerce/class-woocommerce-cover-fees.php +++ b/includes/reader-revenue/woocommerce/class-woocommerce-cover-fees.php @@ -1,6 +1,6 @@ session->get( self::CUSTOM_FIELD_NAME ) ) { - $order->add_order_note( __( 'The donor opted to cover Stripe\'s transaction fee.', 'newspack-plugin' ) ); + $order->add_order_note( __( 'The donor opted to cover transaction fees.', 'newspack-plugin' ) ); } } @@ -117,7 +118,7 @@ private static function should_allow_covering_fees() { // but at this point handling coupons + covering fees is an edge case. return false; } - if ( true !== boolval( get_option( 'newspack_donations_allow_covering_fees' ) ) ) { + if ( true !== boolval( get_option( 'newspack_donations_allow_covering_fees', true ) ) ) { return false; } return true; @@ -134,7 +135,7 @@ private static function should_apply_fee( $data ) { if ( ! self::should_allow_covering_fees() ) { return false; } - if ( ! isset( $data['payment_method'] ) || 'stripe' !== $data['payment_method'] ) { + if ( ! isset( $data['payment_method'] ) || ! in_array( $data['payment_method'], self::SUPPORTED_GATEWAYS, true ) ) { return false; } if ( ! isset( $data[ self::CUSTOM_FIELD_NAME ] ) || '1' !== $data[ self::CUSTOM_FIELD_NAME ] ) { @@ -144,17 +145,19 @@ private static function should_apply_fee( $data ) { } /** - * Render the "cover fees" input for Stripe. + * Render the "cover transaction fees" input for supported payment gateways. + * + * @param string $payment_gateway The slug for the payment gateway rendering these payment fields. */ - public static function render_stripe_input() { - if ( ! self::should_allow_covering_fees() ) { + public static function render_transaction_fee_input( $payment_gateway ) { + if ( ! self::should_allow_covering_fees() || ! in_array( $payment_gateway, self::SUPPORTED_GATEWAYS, true ) ) { return; } ?>

/> -