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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / Notes / WooCommercePayments.php
woocommerce / src / Internal / Admin / Notes Last commit date
CustomizeStoreWithBlocks.php 2 years ago CustomizingProductCatalog.php 1 year ago EUVATNumber.php 2 years ago EditProductsOnTheMove.php 2 years ago EmailImprovements.php 1 year ago FirstProduct.php 1 year ago GivingFeedbackNotes.php 3 years ago InstallJPAndWCSPlugins.php 4 weeks ago LaunchChecklist.php 2 years ago MagentoMigration.php 2 years ago ManageOrdersOnTheGo.php 2 years ago MarketingJetpack.php 4 weeks ago MigrateFromShopify.php 2 years ago MobileApp.php 2 years ago NewSalesRecord.php 3 years ago NoteActionForbiddenException.php 4 weeks ago OnboardingPayments.php 2 years ago OnlineClothingStore.php 2 years ago OrderMilestones.php 2 years ago PaymentsMoreInfoNeeded.php 5 months ago PaymentsRemindMeLater.php 5 months ago PerformanceOnMobile.php 2 years ago PersonalizeStore.php 3 years ago RealTimeOrderAlerts.php 2 years ago ScheduledUpdatesPromotion.php 5 months ago SellingOnlineCourses.php 2 years ago TrackingOptIn.php 1 year ago UnsecuredReportFiles.php 2 years ago WooCommercePayments.php 2 years ago WooCommerceSubscriptions.php 2 years ago WooSubscriptionsNotes.php 1 year ago
WooCommercePayments.php
225 lines
1 <?php
2 /**
3 * WooCommerce Admin WooCommerce Payments Note Provider.
4 *
5 * Adds a note to the merchant's inbox showing the benefits of the WooCommerce Payments.
6 */
7
8 namespace Automattic\WooCommerce\Internal\Admin\Notes;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Automattic\WooCommerce\Admin\Notes\Note;
13 use Automattic\WooCommerce\Admin\Notes\Notes;
14 use Automattic\WooCommerce\Admin\Notes\NoteTraits;
15
16 /**
17 * WooCommerce_Payments
18 */
19 class WooCommercePayments {
20 /**
21 * Note traits.
22 */
23 use NoteTraits;
24
25 /**
26 * Name of the note for use in the database.
27 */
28 const NOTE_NAME = 'wc-admin-woocommerce-payments';
29
30 /**
31 * Name of the note for use in the database.
32 */
33 const PLUGIN_SLUG = 'woocommerce-payments';
34
35 /**
36 * Name of the note for use in the database.
37 */
38 const PLUGIN_FILE = 'woocommerce-payments/woocommerce-payments.php';
39
40 /**
41 * Attach hooks.
42 */
43 public function __construct() {
44 add_action( 'init', array( $this, 'install_on_action' ) );
45 add_action( 'wc-admin-woocommerce-payments_add_note', array( $this, 'add_note' ) );
46 }
47
48 /**
49 * Maybe add a note on WooCommerce Payments for US based sites older than a week without the plugin installed.
50 */
51 public static function possibly_add_note() {
52 if ( ! self::is_wc_admin_active_in_date_range( 'week-1-4' ) || 'US' !== WC()->countries->get_base_country() ) {
53 return;
54 }
55
56 $data_store = Notes::load_data_store();
57
58 // We already have this note? Then mark the note as actioned.
59 $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
60 if ( ! empty( $note_ids ) ) {
61
62 $note_id = array_pop( $note_ids );
63 $note = Notes::get_note( $note_id );
64 if ( false === $note ) {
65 return;
66 }
67
68 // If the WooCommerce Payments plugin was installed after the note was created, make sure it's marked as actioned.
69 if ( self::is_installed() && Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
70 $note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED );
71 $note->save();
72 }
73
74 return;
75 }
76
77 $current_date = new \DateTime();
78 $publish_date = new \DateTime( '2020-04-14' );
79
80 if ( $current_date >= $publish_date ) {
81
82 $note = self::get_note();
83 if ( self::can_be_added() ) {
84 $note->save();
85 }
86
87 return;
88
89 } else {
90
91 $hook_name = sprintf( '%s_add_note', self::NOTE_NAME );
92
93 if ( ! WC()->queue()->get_next( $hook_name ) ) {
94 WC()->queue()->schedule_single( $publish_date->getTimestamp(), $hook_name );
95 }
96 }
97 }
98
99 /**
100 * Add a note about WooCommerce Payments.
101 *
102 * @return Note
103 */
104 public static function get_note() {
105 $note = new Note();
106 $note->set_title( __( 'Try the new way to get paid', 'woocommerce' ) );
107 $note->set_content(
108 __( 'Securely accept credit and debit cards on your site. Manage transactions without leaving your WordPress dashboard. Only with <strong>WooPayments</strong>.', 'woocommerce' ) .
109 '<br><br>' .
110 sprintf(
111 /* translators: 1: opening link tag, 2: closing tag */
112 __( 'By clicking "Get started", you agree to our %1$sTerms of Service%2$s', 'woocommerce' ),
113 '<a href="https://wordpress.com/tos/" target="_blank">',
114 '</a>'
115 )
116 );
117 $note->set_content_data( (object) array() );
118 $note->set_type( Note::E_WC_ADMIN_NOTE_MARKETING );
119 $note->set_name( self::NOTE_NAME );
120 $note->set_source( 'woocommerce-admin' );
121 $note->add_action( 'learn-more', __( 'Learn more', 'woocommerce' ), 'https://woocommerce.com/payments/?utm_medium=product', Note::E_WC_ADMIN_NOTE_UNACTIONED );
122 $note->add_action( 'get-started', __( 'Get started', 'woocommerce' ), wc_admin_url( '&action=setup-woocommerce-payments' ), Note::E_WC_ADMIN_NOTE_ACTIONED, true );
123 $note->add_nonce_to_action( 'get-started', 'setup-woocommerce-payments', '' );
124
125 // Create the note as "actioned" if the plugin is already installed.
126 if ( self::is_installed() ) {
127 $note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED );
128 }
129 return $note;
130 }
131
132
133 /**
134 * Check if the WooCommerce Payments plugin is active or installed.
135 */
136 protected static function is_installed() {
137 if ( defined( 'WC_Payments' ) ) {
138 return true;
139 }
140 include_once ABSPATH . '/wp-admin/includes/plugin.php';
141 return 0 === validate_plugin( self::PLUGIN_FILE );
142 }
143
144 /**
145 * Install and activate WooCommerce Payments.
146 *
147 * @return boolean Whether the plugin was successfully activated.
148 */
149 private function install_and_activate_wcpay() {
150 $install_request = array( 'plugins' => self::PLUGIN_SLUG );
151 $installer = new \Automattic\WooCommerce\Admin\API\Plugins();
152 $result = $installer->install_plugins( $install_request );
153 if ( is_wp_error( $result ) ) {
154 return false;
155 }
156
157 wc_admin_record_tracks_event( 'woocommerce_payments_install', array( 'context' => 'inbox' ) );
158
159 $activate_request = array( 'plugins' => self::PLUGIN_SLUG );
160 $result = $installer->activate_plugins( $activate_request );
161 if ( is_wp_error( $result ) ) {
162 return false;
163 }
164
165 return true;
166 }
167
168 /**
169 * Install & activate WooCommerce Payments plugin, and redirect to setup.
170 */
171 public function install_on_action() {
172 // TODO: Need to validate this request more strictly since we're taking install actions directly?
173 if (
174 ! isset( $_GET['page'] ) ||
175 'wc-admin' !== $_GET['page'] ||
176 ! isset( $_GET['action'] ) ||
177 'setup-woocommerce-payments' !== $_GET['action']
178 ) {
179 return;
180 }
181
182 $data_store = Notes::load_data_store();
183
184 // We already have this note? Then mark the note as actioned.
185 $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
186 if ( empty( $note_ids ) ) {
187 return;
188 }
189
190 $note_id = array_pop( $note_ids );
191 $note = Notes::get_note( $note_id );
192 if ( false === $note ) {
193 return;
194 }
195 $action = $note->get_action( 'get-started' );
196 if ( ! $action ||
197 ( isset( $action->nonce_action ) &&
198 (
199 empty( $_GET['_wpnonce'] ) ||
200 ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action->nonce_action ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
201 )
202 )
203 ) {
204 return;
205 }
206
207 if ( ! current_user_can( 'install_plugins' ) ) {
208 return;
209 }
210
211 $this->install_and_activate_wcpay();
212
213 // WooCommerce Payments is installed at this point, so link straight into the onboarding flow.
214 $connect_url = add_query_arg(
215 array(
216 'wcpay-connect' => '1',
217 '_wpnonce' => wp_create_nonce( 'wcpay-connect' ),
218 ),
219 admin_url()
220 );
221 wp_safe_redirect( $connect_url );
222 exit;
223 }
224 }
225