PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / PaymentGateways / PayPalCommerce / Migrations / RegisterPayPalDonationsRefreshTokenCronJobByMode.php

RegisterPayPalDonationsRefreshTokenCronJobByMode.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/PaymentGateways/PayPalCommerce/Migrations/RegisterPayPalDonationsRefreshTokenCronJobByMode.php

86 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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