give
/
src
/
PaymentGateways
/
PayPalCommerce
/
Migrations
/
RegisterPayPalDonationsRefreshTokenCronJobByMode.php
RegisterPayPalDonationsRefreshTokenCronJobByMode.php
3 years ago
RemoveLogWithCardInfo.php
4 years ago
RegisterPayPalDonationsRefreshTokenCronJobByMode.php
86 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Register PayPal Donations Refresh Token Cron Job By Mode |
| 4 | * |
| 5 | * This migration is used to register cron job for refresh token. |
| 6 | * Cron job add for live and sandbox mode if connected. |
| 7 | */ |
| 8 | |
| 9 | namespace Give\PaymentGateways\PayPalCommerce\Migrations; |
| 10 | |
| 11 | use Give\Framework\Migrations\Contracts\Migration; |
| 12 | use Give\PaymentGateways\PayPalCommerce\RefreshToken; |
| 13 | use Give\PaymentGateways\PayPalCommerce\Repositories\MerchantDetails; |
| 14 | |
| 15 | /** |
| 16 | * Class RegisterPayPalDonationsRefreshTokenCronJobByMode |
| 17 | * |
| 18 | * @since 2.30.0 |
| 19 | */ |
| 20 | class RegisterPayPalDonationsRefreshTokenCronJobByMode extends Migration |
| 21 | { |
| 22 | |
| 23 | /** |
| 24 | * @inerhitDoc |
| 25 | * @since 2.30.0 |
| 26 | */ |
| 27 | public function run() |
| 28 | { |
| 29 | $liveRefreshToken = clone give(RefreshToken::class); |
| 30 | $liveRefreshToken->setMode('live'); |
| 31 | |
| 32 | $sandboxRefreshToken = clone give(RefreshToken::class); |
| 33 | $sandboxRefreshToken->setMode('sandbox'); |
| 34 | |
| 35 | // Clean up any existing cron jobs. |
| 36 | wp_unschedule_hook('give_paypal_commerce_refresh_token'); // Legacy cron job. |
| 37 | $liveRefreshToken->deleteRefreshTokenCronJob(); |
| 38 | $sandboxRefreshToken->deleteRefreshTokenCronJob(); |
| 39 | |
| 40 | // Register cron job for live mode if connected. |
| 41 | $liveMerchantDetailsRepository = clone give(MerchantDetails::class); |
| 42 | $liveMerchantDetailsRepository->setMode('live'); |
| 43 | $liveMerchantDetails = $liveMerchantDetailsRepository->getDetails(); |
| 44 | |
| 45 | if ($liveMerchantDetails->accountIsReady) { |
| 46 | $liveRefreshToken->registerCronJobToRefreshToken($liveMerchantDetails->toArray()['token']['expiresIn']); |
| 47 | } |
| 48 | |
| 49 | // Register cron job for sandbox mode if connected. |
| 50 | $sandboxMerchantDetailsRepository = clone give(MerchantDetails::class); |
| 51 | $sandboxMerchantDetailsRepository->setMode('sandbox'); |
| 52 | $sandboxMerchantDetails = $sandboxMerchantDetailsRepository->getDetails(); |
| 53 | |
| 54 | if ($sandboxMerchantDetails->accountIsReady) { |
| 55 | $sandboxRefreshToken->registerCronJobToRefreshToken($sandboxMerchantDetails->toArray()['token']['expiresIn']); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @inerhitDoc |
| 61 | * @since 2.30.0 |
| 62 | */ |
| 63 | public static function id() |
| 64 | { |
| 65 | return 'register-paypal-donations-refresh-token-cron-job-by-mode'; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @inerhitDoc |
| 70 | * @since 2.30.0 |
| 71 | */ |
| 72 | public static function timestamp() |
| 73 | { |
| 74 | return strtotime('2023-06-21'); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @inerhitDoc |
| 79 | * @since 2.30.0 |
| 80 | */ |
| 81 | public static function title() |
| 82 | { |
| 83 | return 'Register PayPal Donations Refresh Token Cron Job By Mode'; |
| 84 | } |
| 85 | } |
| 86 |