init
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Allowed_Payment_Request_Button_Sizes_Update
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
use WC_Payments_Notes_Additional_Payment_Methods;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Allowed_Payment_Request_Button_Sizes_Update
|
||||
*
|
||||
* In version 7.0.0, the UPE is further cleaned up and it is also the default now. This migration removes the admin notes for the additional payment methods.
|
||||
*
|
||||
* @since 7.0.0
|
||||
*/
|
||||
class Additional_Payment_Methods_Admin_Notes_Removal {
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_SINCE = '7.0.0';
|
||||
|
||||
/**
|
||||
* Only execute the migration if not applied yet.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( self::VERSION_SINCE, $previous_version, '>' ) ) {
|
||||
$this->migrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration as described in the class docblock.
|
||||
*/
|
||||
private function migrate() {
|
||||
// Delete UPE admin notes as UPE is the default now. This is part of the migration and should be removed in the future.
|
||||
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-additional-payment-methods.php';
|
||||
WC_Payments_Notes_Additional_Payment_Methods::possibly_delete_note();
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Allowed_Payment_Request_Button_Sizes_Update
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
use WC_Payment_Gateway_WCPay;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Allowed_Payment_Request_Button_Sizes_Update
|
||||
*
|
||||
* In version 6.9.0, the "default" size got renamed to "small" - ensure that the settings are up-to-date for existing merchants.
|
||||
*
|
||||
* @since 6.9.0
|
||||
*/
|
||||
class Allowed_Payment_Request_Button_Sizes_Update {
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_SINCE = '6.9.0';
|
||||
|
||||
/**
|
||||
* WCPay gateway.
|
||||
*
|
||||
* @var WC_Payment_Gateway_WCPay
|
||||
*/
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* Allowed_Payment_Request_Button_Sizes_Update constructor.
|
||||
*
|
||||
* @param WC_Payment_Gateway_WCPay $gateway WCPay gateway.
|
||||
*/
|
||||
public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
|
||||
$this->gateway = $gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only execute the migration if not applied yet.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( self::VERSION_SINCE, $previous_version, '>' ) ) {
|
||||
$this->migrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration as described in the class docblock.
|
||||
*/
|
||||
private function migrate() {
|
||||
$button_size = $this->gateway->get_option( 'payment_request_button_size' );
|
||||
if ( 'default' === $button_size ) {
|
||||
$this->gateway->update_option(
|
||||
'payment_request_button_size',
|
||||
'small'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Allowed_Payment_Request_Button_Types_Update
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
use WC_Payment_Gateway_WCPay;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Allowed_Payment_Request_Button_Types_Update
|
||||
*
|
||||
* Remaps deprecated payment request button types to fallback values.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
class Allowed_Payment_Request_Button_Types_Update {
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_SINCE = '2.6.0';
|
||||
|
||||
/**
|
||||
* WCPay gateway.
|
||||
*
|
||||
* @var WC_Payment_Gateway_WCPay
|
||||
*/
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* Allowed_Payment_Request_Button_Types_Update constructor.
|
||||
*
|
||||
* @param WC_Payment_Gateway_WCPay $gateway WCPay gateway.
|
||||
*/
|
||||
public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
|
||||
$this->gateway = $gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only execute the migration if not applied yet.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( self::VERSION_SINCE, $previous_version, '>' ) ) {
|
||||
$this->migrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration as described in the class docblock.
|
||||
*/
|
||||
private function migrate() {
|
||||
$button_type = $this->gateway->get_option( 'payment_request_button_type' );
|
||||
$branded_type = $this->gateway->get_option( 'payment_request_button_branded_type' );
|
||||
|
||||
$this->gateway->update_option(
|
||||
'payment_request_button_type',
|
||||
$this->map_button_type( $button_type, $branded_type )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps deprecated button types to fallback values.
|
||||
*
|
||||
* @param mixed $button_type "payment_request_button_type" value.
|
||||
* @param mixed $branded_type "payment_request_button_branded_type" value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function map_button_type( $button_type, $branded_type ) {
|
||||
if ( 'branded' === $button_type && 'short' === $branded_type ) {
|
||||
return 'default';
|
||||
}
|
||||
|
||||
if ( 'branded' === $button_type && 'short' !== $branded_type ) {
|
||||
return 'buy';
|
||||
}
|
||||
|
||||
if ( 'custom' === $button_type ) {
|
||||
return 'buy';
|
||||
}
|
||||
|
||||
return $button_type;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Delete_Active_WooPay_Webhook
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Delete_Active_WooPay_Webhook
|
||||
*
|
||||
* Fires an event on plugin upgrade to delete the active webhook.
|
||||
* Runs only once. We want to know whether existing install had it
|
||||
* enabled before the current version.
|
||||
*/
|
||||
class Delete_Active_WooPay_Webhook {
|
||||
/**
|
||||
* Checks whether we should trigger the event.
|
||||
*/
|
||||
public static function maybe_delete() {
|
||||
if ( version_compare( get_option( 'woocommerce_woocommerce_payments_version' ), '4.9.0', '>=' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the active webhook.
|
||||
*/
|
||||
private static function delete() {
|
||||
\WCPay\WooPay\WooPay_Order_Status_Sync::remove_webhook();
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Erase_Bnpl_Announcement_Meta
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Erase_Bnpl_Announcement_Meta
|
||||
*
|
||||
* Clearing up all meta data related to the BNPL April 2024 announcement.
|
||||
*
|
||||
* @since 8.1.0
|
||||
*/
|
||||
class Erase_Bnpl_Announcement_Meta {
|
||||
/**
|
||||
* Checks whether it's worth doing the migration.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( '8.1.0', $previous_version, '>' ) ) {
|
||||
$this->migrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration.
|
||||
*/
|
||||
private function migrate() {
|
||||
global $wpdb;
|
||||
|
||||
delete_transient( 'wcpay_bnpl_april15_successful_purchases_count' );
|
||||
// using a query directly, so we can delete the meta for all users.
|
||||
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = '_wcpay_bnpl_april15_viewed'" );
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Erase_Deprecated_Flags_And_Options
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Erase_Deprecated_Flags_And_Options
|
||||
*
|
||||
* Clearing up all flags and options that are no longer in use.
|
||||
*
|
||||
* @since 8.1.0
|
||||
*/
|
||||
class Erase_Deprecated_Flags_And_Options {
|
||||
/**
|
||||
* Checks whether it's worth doing the migration.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
// feel free to modify the version here to the next one, if you add a new flag to be deleted in the `migrate` method.
|
||||
if ( version_compare( '8.1.0', $previous_version, '>' ) ) {
|
||||
$this->migrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration.
|
||||
*/
|
||||
private function migrate() {
|
||||
// please update as necessary, when feature flags are removed.
|
||||
// you don't need to check for previous values or if the migration already ran in previous versions.
|
||||
// if the migration did already run, the operations below will just be noop.
|
||||
delete_option( '_wcpay_feature_progressive_onboarding' );
|
||||
delete_option( '_wcpay_feature_client_secret_encryption' );
|
||||
delete_option( '_wcpay_feature_allow_subscription_migrations' );
|
||||
delete_option( '_wcpay_feature_custom_deposit_schedules' );
|
||||
delete_option( '_wcpay_feature_account_overview_task_list' );
|
||||
delete_option( '_wcpay_feature_account_overview' );
|
||||
delete_option( '_wcpay_feature_sepa' );
|
||||
delete_option( '_wcpay_feature_sofort' );
|
||||
delete_option( '_wcpay_feature_giropay' );
|
||||
delete_option( '_wcpay_feature_grouped_settings' );
|
||||
delete_option( '_wcpay_feature_upe_settings_preview' );
|
||||
delete_option( '_wcpay_feature_upe' );
|
||||
delete_option( '_wcpay_feature_upe_split' );
|
||||
delete_option( '_wcpay_feature_upe_deferred_intent' );
|
||||
delete_option( '_wcpay_feature_dispute_on_transaction_page' );
|
||||
delete_option( '_wcpay_feature_streamline_refunds' );
|
||||
delete_option( 'wcpay_fraud_protection_settings_active' );
|
||||
delete_option( '_wcpay_feature_mc_order_meta_helper' );
|
||||
delete_option( '_wcpay_feature_pay_for_order_flow' );
|
||||
delete_option( '_wcpay_feature_simplify_deposits_ui' );
|
||||
delete_option( '_wcpay_fraud_protection_settings_enabled' );
|
||||
delete_option( '_wcpay_feature_platform_checkout_subscriptions_enabled' );
|
||||
delete_option( '_wcpay_feature_platform_checkout' );
|
||||
delete_option( '_wcpay_feature_capital' );
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Gateway_Settings_Sync
|
||||
*
|
||||
* @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 Gateway_Settings_Sync {
|
||||
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_SINCE = '7.4.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_sync() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( self::VERSION_SINCE, $previous_version, '>' ) ) {
|
||||
$this->sync();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs gateway setting objects.
|
||||
*/
|
||||
private function sync() {
|
||||
$enabled_payment_methods = $this->main_gateway->get_option( 'upe_enabled_payment_method_ids', [] );
|
||||
|
||||
foreach ( $this->all_registered_gateways as $gateway ) {
|
||||
// Skip the main gateway as it's settings are already in sync.
|
||||
if ( 'card' !== $gateway->get_stripe_id() ) {
|
||||
if ( in_array( $gateway->get_stripe_id(), $enabled_payment_methods, true ) ) {
|
||||
$gateway->enable();
|
||||
$gateway->update_option( 'upe_enabled_payment_method_ids', $enabled_payment_methods );
|
||||
} else {
|
||||
$gateway->update_option( 'upe_enabled_payment_method_ids', $enabled_payment_methods );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Link_WooPay_Mutual_Exclusion_Handler
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
use WC_Payment_Gateway_WCPay;
|
||||
use WC_Payments_Features;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Link_WooPay_Mutual_Exclusion_Handler
|
||||
*
|
||||
* In version 7.3.0, the logic responsible for disabling Stripe Link if WooPay is by default enabled, is moved from the gateways registration step to the migration.
|
||||
*
|
||||
* @since 7.3.0
|
||||
*/
|
||||
class Link_WooPay_Mutual_Exclusion_Handler {
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_SINCE = '7.3.0';
|
||||
|
||||
/**
|
||||
* WCPay gateway.
|
||||
*
|
||||
* @var WC_Payment_Gateway_WCPay
|
||||
*/
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* Link_WooPay_Mutual_Exclusion_Handler constructor.
|
||||
*
|
||||
* @param WC_Payment_Gateway_WCPay $gateway WCPay gateway.
|
||||
*/
|
||||
public function __construct( WC_Payment_Gateway_WCPay $gateway ) {
|
||||
$this->gateway = $gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only execute the migration if not applied yet.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( self::VERSION_SINCE, $previous_version, '>' ) ) {
|
||||
$this->migrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration as described in the class docblock.
|
||||
*/
|
||||
private function migrate() {
|
||||
// check if both Stripe Link and WooPay are enabled and if so - disable Stripe Link.
|
||||
$enabled_payment_methods = $this->gateway->get_payment_method_ids_enabled_at_checkout();
|
||||
$enabled_stripe_link_index = array_search( 'link', $enabled_payment_methods, true );
|
||||
|
||||
if ( false !== $enabled_stripe_link_index && WC_Payments_Features::is_woopay_enabled() ) {
|
||||
unset( $enabled_payment_methods[ $enabled_stripe_link_index ] );
|
||||
|
||||
$this->gateway->update_option( 'upe_enabled_payment_method_ids', $enabled_payment_methods );
|
||||
}
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Manual_Capture_Payment_Method_Settings_Update
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
use WCPay\Constants\Payment_Method;
|
||||
use WC_Payment_Gateway_WCPay;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Manual_Capture_Payment_Method_Settings_Update
|
||||
*
|
||||
* Updates payment methods when manual capture is enabled.
|
||||
*/
|
||||
class Manual_Capture_Payment_Method_Settings_Update {
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_SINCE = '8.3.0';
|
||||
|
||||
/**
|
||||
* WCPay gateway.
|
||||
*
|
||||
* @var WC_Payment_Gateway_WCPay
|
||||
*/
|
||||
private $main_gateway;
|
||||
|
||||
/**
|
||||
* All registered gateways.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $all_registered_gateways;
|
||||
|
||||
/**
|
||||
* Manual_Capture_Payment_Method_Settings_Update 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables payment methods that do not support manual capture, when manual capture is enabled and updates
|
||||
* the enabled payment methods for each gateway.
|
||||
*/
|
||||
private function migrate() {
|
||||
$enabled_payment_methods = $this->main_gateway->get_option( 'upe_enabled_payment_method_ids', [] );
|
||||
$is_manual_capture_enabled = 'yes' === $this->main_gateway->get_option( 'manual_capture' );
|
||||
|
||||
if ( $is_manual_capture_enabled ) {
|
||||
$filtered_payment_methods = array_filter(
|
||||
$enabled_payment_methods,
|
||||
function ( $method ) {
|
||||
return in_array( $method, [ Payment_Method::CARD, Payment_Method::LINK ], true );
|
||||
}
|
||||
);
|
||||
|
||||
foreach ( $this->all_registered_gateways as $gateway ) {
|
||||
$stripe_id = $gateway->get_stripe_id();
|
||||
if ( Payment_Method::CARD !== $stripe_id && Payment_Method::LINK !== $stripe_id ) {
|
||||
$gateway->disable();
|
||||
}
|
||||
$gateway->update_option( 'upe_enabled_payment_method_ids', $filtered_payment_methods );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Payment_Method_Deprecation_Settings_Update
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
use WC_Payment_Gateway_WCPay;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Payment_Method_Deprecation_Settings_Update
|
||||
*
|
||||
* Aligns settings object for every gateway to support new approach of settings handling without the need of using the settings controller.
|
||||
*/
|
||||
class Payment_Method_Deprecation_Settings_Update {
|
||||
/**
|
||||
* WCPay gateway.
|
||||
*
|
||||
* @var WC_Payment_Gateway_WCPay
|
||||
*/
|
||||
private $main_gateway;
|
||||
|
||||
/**
|
||||
* All registered gateways.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $all_registered_gateways;
|
||||
|
||||
/**
|
||||
* Payment method type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $payment_method_id;
|
||||
|
||||
/**
|
||||
* Version in which this migration was introduced.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $migration_version;
|
||||
|
||||
/**
|
||||
* Gateway_Settings_Sync constructor.
|
||||
*
|
||||
* @param WC_Payment_Gateway_WCPay $main_gateway WCPay gateway.
|
||||
* @param array $all_registered_gateways All registered gateways.
|
||||
* @param string $payment_method_id Stripe payment method ID of payment method to deprecate.
|
||||
* @param string $migration_version Plugin version after which migration should run.
|
||||
*/
|
||||
public function __construct( WC_Payment_Gateway_WCPay $main_gateway, $all_registered_gateways, $payment_method_id, $migration_version ) {
|
||||
$this->main_gateway = $main_gateway;
|
||||
$this->all_registered_gateways = $all_registered_gateways;
|
||||
$this->payment_method_id = $payment_method_id;
|
||||
$this->migration_version = $migration_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether we should trigger the event.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
|
||||
if ( version_compare( $this->migration_version, $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 $this->payment_method_id !== $method;
|
||||
}
|
||||
);
|
||||
|
||||
foreach ( $this->all_registered_gateways as $gateway ) {
|
||||
if ( $this->payment_method_id === $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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Update_Service_Data_From_Server
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
namespace WCPay\Migrations;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Update_Service_Data_From_Server
|
||||
*
|
||||
* Ensures that the service data is being updated after the upgrade to UPE.
|
||||
* Updating the service data ensures that the payment method fees are present.
|
||||
* If the fees are not present, the plugin shows "missing fees" text next to the UPE payment methods.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
class Update_Service_Data_From_Server {
|
||||
/**
|
||||
* Instance to get information about the account.
|
||||
*
|
||||
* @var \WC_Payments_Account
|
||||
*/
|
||||
private $account;
|
||||
|
||||
/**
|
||||
* Update_Service_Data_From_Server constructor.
|
||||
*
|
||||
* @param \WC_Payments_Account $account instance to get information about the account.
|
||||
*/
|
||||
public function __construct( \WC_Payments_Account $account ) {
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether it's worth doing the migration.
|
||||
*/
|
||||
public function maybe_migrate() {
|
||||
$account_data = $this->account->get_cached_account_data();
|
||||
// no need to migrate anything, maybe the site is disconnected.
|
||||
// the plugin will eventually fetch new account data.
|
||||
if ( empty( $account_data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we have account data, do we have the fees for sofort/sepa/giropay/p24 etc?
|
||||
// if we do, no need to migrate.
|
||||
$account_fees = $this->account->get_fees();
|
||||
if ( ! empty( $account_fees['giropay']['base'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->migrate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual migration.
|
||||
*/
|
||||
private function migrate() {
|
||||
$this->account->refresh_account_data();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user