EnsureSubscriptionHasPaymentMode.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Give\LegacySubscriptions\Actions; |
| 6 | |
| 7 | use Give\Subscriptions\ValueObjects\SubscriptionMode; |
| 8 | |
| 9 | /** |
| 10 | * When payment mode was introduced it was possible for users to update core before updating Recurring. In this case, |
| 11 | * subscriptions could be made which did not have a payment mode. This action ensures that all subscriptions have a |
| 12 | * payment mode. |
| 13 | * |
| 14 | * @since 2.24.0 |
| 15 | */ |
| 16 | class EnsureSubscriptionHasPaymentMode |
| 17 | { |
| 18 | /** |
| 19 | * Makes sure the payment mode is set when the legacy recurring system is used. |
| 20 | * |
| 21 | * @since 2.24.0 |
| 22 | * |
| 23 | * @param int $id |
| 24 | * @param array $arguments |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function __invoke($id, $arguments) |
| 29 | { |
| 30 | if (!empty($arguments['payment_mode'])) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | give()->subscriptions->updatePaymentMode( |
| 35 | $id, |
| 36 | give_is_test_mode() ? SubscriptionMode::TEST() : SubscriptionMode::LIVE() |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 |