Skip to content

Commit

Permalink
Feature: Payment Gateways Settings migration (#6928)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski authored Sep 12, 2023
1 parent 6661704 commit 18bdfe6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/PaymentGateways/Migrations/CopyV2GatewaysSettingsToV3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Give\PaymentGateways\Migrations;

use Give\Framework\Migrations\Contracts\Migration;

/**
* @unreleased
*/
class CopyV2GatewaysSettingsToV3 extends Migration
{

/**
* @inerhitDoc
*/
public static function id()
{
return 'copy-v2-gateways-settings-to-v3';
}

/**
* @inerhitDoc
*/
public static function timestamp()
{
return strtotime('2023-09-11');
}

/**
* @inerhitDoc
*/
public function run()
{
$v2Gateways = give_get_option('gateways', []);
$v3Gateways = array_intersect_key($v2Gateways, give()->gateways->getPaymentGateways(3));
give_update_option('gateways_v3', $v3Gateways);

$v2GatewaysLabels = give_get_option('gateways_label', []);
$v3GatewaysLabels = array_intersect_key($v2GatewaysLabels, $v3Gateways);
give_update_option('gateways_label_v3', $v3GatewaysLabels);

$v2DefaultGateway = give_get_option('default_gateway', '');
$v3DefaultGateway = array_key_exists($v2DefaultGateway, $v3Gateways) ? $v2DefaultGateway : current(
array_keys($v3Gateways)
);
give_update_option('default_gateway_v3', $v3DefaultGateway);
}

/**
* @inerhitDoc
*/
public static function title()
{
return 'Copy v2 Gateways Settings to v3';
}
}
3 changes: 3 additions & 0 deletions src/PaymentGateways/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Give\PaymentGateways\Gateways\Stripe\Migrations\AddMissingTransactionIdForUncompletedDonations;
use Give\PaymentGateways\Gateways\Stripe\Migrations\AddStatementDescriptorToStripeAccounts;
use Give\PaymentGateways\Gateways\Stripe\Migrations\RemovePaymentIntentSecretMeta;
use Give\PaymentGateways\Migrations\CopyV2GatewaysSettingsToV3;
use Give\PaymentGateways\PayPalCommerce\Banners\GatewaySettingPageBanner;
use Give\PaymentGateways\PayPalCommerce\Banners\PayPalStandardToDonationsMigrationGlobalBanner;
use Give\PaymentGateways\PayPalCommerce\Migrations\RegisterPayPalDonationsRefreshTokenCronJobByMode;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function boot()
}

/**
* @unreleased add CopyV2GatewaysSettingsToV3 migration
* @since 2.33.0 add RemovePaymentIntentSecretMeta migration
* @since 2.19.6
*/
Expand All @@ -76,6 +78,7 @@ private function registerMigrations()
RemoveLogWithCardInfo::class,
RemovePaymentIntentSecretMeta::class,
RegisterPayPalDonationsRefreshTokenCronJobByMode::class,
CopyV2GatewaysSettingsToV3::class,
]);
}

Expand Down

0 comments on commit 18bdfe6

Please sign in to comment.