Skip to content

Commit

Permalink
Merge branch 'develop' into add/8808-woo-payment-method-logo
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaun1985 authored Jul 10, 2024
2 parents 4cbc726 + dfbbc19 commit 9fe143d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog/9037-giropay-deprecation
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Deprecate Giropay.
1 change: 0 additions & 1 deletion includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4029,7 +4029,6 @@ public function get_upe_available_payment_methods() {
$available_methods[] = Becs_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Bancontact_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Eps_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Giropay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Ideal_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Sofort_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Sepa_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
Expand Down
2 changes: 2 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,15 @@ function () {
require_once __DIR__ . '/migrations/class-link-woopay-mutual-exclusion-handler.php';
require_once __DIR__ . '/migrations/class-gateway-settings-sync.php';
require_once __DIR__ . '/migrations/class-delete-active-woopay-webhook.php';
require_once __DIR__ . '/migrations/class-giropay-deprecation-settings-update.php';
add_action( 'woocommerce_woocommerce_payments_updated', [ new Allowed_Payment_Request_Button_Types_Update( self::get_gateway() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Allowed_Payment_Request_Button_Sizes_Update( self::get_gateway() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Update_Service_Data_From_Server( self::get_account_service() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Additional_Payment_Methods_Admin_Notes_Removal(), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Link_WooPay_Mutual_Exclusion_Handler( self::get_gateway() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Gateway_Settings_Sync( self::get_gateway(), self::get_payment_gateway_map() ), 'maybe_sync' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ '\WCPay\Migrations\Delete_Active_WooPay_Webhook', 'maybe_delete' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Giropay_Deprecation_Settings_Update( self::get_gateway(), self::get_payment_gateway_map() ), 'maybe_migrate' ] );

include_once WCPAY_ABSPATH . '/includes/class-wc-payments-explicit-price-formatter.php';
WC_Payments_Explicit_Price_Formatter::init();
Expand Down
89 changes: 89 additions & 0 deletions includes/migrations/class-giropay-deprecation-settings-update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Class Giropay_Deprecation_Settings_Update
*
* @package WooCommerce\Payments
*/

namespace WCPay\Migrations;

use WC_Payment_Gateway_WCPay;

defined( 'ABSPATH' ) || exit;

/**
* Class Delete_Active_WooPay_Webhook
*
* Aligns settings object for every gateway to support new approach of settings handling without the need of using the settings controller.
*/
class Giropay_Deprecation_Settings_Update {

/**
* Version in which this migration was introduced.
*
* @var string
*/
const VERSION_SINCE = '7.9.0';

/**
* WCPay gateway.
*
* @var WC_Payment_Gateway_WCPay
*/
private $main_gateway;

/**
* All registered gateways.
*
* @var array
*/
private $all_registered_gateways;

/**
* Gateway_Settings_Sync constructor.
*
* @param WC_Payment_Gateway_WCPay $main_gateway WCPay gateway.
* @param array $all_registered_gateways All registered gateways.
*/
public function __construct( WC_Payment_Gateway_WCPay $main_gateway, $all_registered_gateways ) {
$this->main_gateway = $main_gateway;
$this->all_registered_gateways = $all_registered_gateways;
}

/**
* Checks whether we should trigger the event.
*/
public function maybe_migrate() {
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
if ( version_compare( self::VERSION_SINCE, $previous_version, '>' ) ) {
$this->migrate();
}
}

/**
* Syncs gateway setting objects.
*/
private function migrate() {
$enabled_payment_methods = $this->main_gateway->get_option( 'upe_enabled_payment_method_ids', [] );

$filtered_payment_methods = array_filter(
$enabled_payment_methods,
function ( $method ) {
return 'giropay' !== $method;
}
);

foreach ( $this->all_registered_gateways as $gateway ) {
if ( 'giropay' === $gateway->get_stripe_id() ) {
if ( in_array( $gateway->get_stripe_id(), $enabled_payment_methods, true ) ) {
$gateway->disable();
$gateway->update_option( 'upe_enabled_payment_method_ids', $filtered_payment_methods );
} else {
$gateway->update_option( 'upe_enabled_payment_method_ids', $filtered_payment_methods );
}
} else {
$gateway->update_option( 'upe_enabled_payment_method_ids', $filtered_payment_methods );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ public function test_get_settings_returns_available_payment_method_ids() {
Payment_Method::BECS,
Payment_Method::BANCONTACT,
Payment_Method::EPS,
Payment_Method::GIROPAY,
Payment_Method::IDEAL,
Payment_Method::SOFORT,
Payment_Method::SEPA,
Expand Down Expand Up @@ -376,11 +375,11 @@ public function test_update_settings_saves_enabled_payment_methods() {
WC_Payments::get_gateway()->update_option( 'upe_enabled_payment_method_ids', [ Payment_Method::CARD ] );

$request = new WP_REST_Request();
$request->set_param( 'enabled_payment_method_ids', [ Payment_Method::CARD, Payment_Method::GIROPAY ] );
$request->set_param( 'enabled_payment_method_ids', [ Payment_Method::CARD, Payment_Method::IDEAL ] );

$this->controller->update_settings( $request );

$this->assertEquals( [ Payment_Method::CARD, Payment_Method::GIROPAY ], WC_Payments::get_gateway()->get_option( 'upe_enabled_payment_method_ids' ) );
$this->assertEquals( [ Payment_Method::CARD, Payment_Method::IDEAL ], WC_Payments::get_gateway()->get_option( 'upe_enabled_payment_method_ids' ) );
}

public function test_update_settings_fails_if_user_cannot_manage_woocommerce() {
Expand Down

0 comments on commit 9fe143d

Please sign in to comment.