give
/
src
/
PaymentGateways
/
Gateways
/
PayPalStandard
/
Migrations
/
SetPayPalStandardGatewayId.php
SetPayPalStandardGatewayId.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\PayPalStandard\Migrations; |
| 4 | |
| 5 | use Give\Framework\Migrations\Contracts\Migration; |
| 6 | |
| 7 | /** |
| 8 | * Class SetPayPalStandardGatewayId |
| 9 | * @package Give\PaymentGateways\Gateways\PayPalStandard\Migrations |
| 10 | * |
| 11 | * This migration fixes a bug that was introduced in 2.9.0 wherein the PayPal Standard gateway ID was changed from |
| 12 | * paypal to paypal-standard. This caused problems on existing sites using PayPal Standard. The purpose of this |
| 13 | * migration is to help those that are on 2.9.0 to recover to using the paypal ID for the gateway. |
| 14 | * |
| 15 | * @since 2.9.1 |
| 16 | */ |
| 17 | class SetPayPalStandardGatewayId extends Migration |
| 18 | { |
| 19 | |
| 20 | /** |
| 21 | * @inheritdoc |
| 22 | */ |
| 23 | public function run() |
| 24 | { |
| 25 | // Reset paypal gateway id to paypal. |
| 26 | $give_settings = give_get_settings(); |
| 27 | $gateways = $give_settings['gateways']; |
| 28 | $updateSettings = false; |
| 29 | |
| 30 | if (array_key_exists('paypal-standard', $gateways)) { |
| 31 | unset($gateways['paypal-standard']); |
| 32 | $gateways['paypal'] = '1'; |
| 33 | $give_settings['gateways'] = $gateways; |
| 34 | |
| 35 | $updateSettings = true; |
| 36 | } |
| 37 | |
| 38 | // Reset paypal gateway custom label. |
| 39 | if (isset($give_settings['gateways_label'])) { |
| 40 | $gateways_label = $give_settings['gateways_label']; |
| 41 | if (array_key_exists('paypal-standard', $gateways_label)) { |
| 42 | $gateways_label['paypal'] = $gateways_label['paypal-standard']; |
| 43 | unset($gateways_label['paypal-standard']); |
| 44 | $give_settings['gateways_label'] = $gateways_label; |
| 45 | $updateSettings = true; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Set paypal standard as default payment gateway. |
| 50 | if ('paypal-standard' === $give_settings['default_gateway']) { |
| 51 | $give_settings['default_gateway'] = 'paypal'; |
| 52 | $updateSettings = true; |
| 53 | } |
| 54 | |
| 55 | if ($updateSettings) { |
| 56 | update_option('give_settings', $give_settings); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @inheritdoc |
| 62 | */ |
| 63 | public static function id() |
| 64 | { |
| 65 | return 'set_paypal_standard_id_to_paypal_from_paypal_standard'; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @inheritdoc |
| 70 | */ |
| 71 | public static function timestamp() |
| 72 | { |
| 73 | return strtotime('2020-10-28'); |
| 74 | } |
| 75 | } |
| 76 |