diff --git a/class-wc-calypso-bridge.php b/class-wc-calypso-bridge.php index 485fbeb5..66305baf 100644 --- a/class-wc-calypso-bridge.php +++ b/class-wc-calypso-bridge.php @@ -182,6 +182,7 @@ public function includes() { require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/class-wc-calypso-bridge-smart-shipping.php'; require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/class-wc-calypso-bridge-woo-express-introductory-offers.php'; require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/free-trial/partners/class-wc-calypso-bridge-partner-square.php'; + require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/free-trial/partners/class-wc-calypso-bridge-partner-stripe.php'; require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/free-trial/partners/class-wc-calypso-bridge-partner-paypal.php'; // Experiments. diff --git a/includes/free-trial/partners/class-wc-calypso-bridge-partner-stripe.php b/includes/free-trial/partners/class-wc-calypso-bridge-partner-stripe.php new file mode 100644 index 00000000..62baae8a --- /dev/null +++ b/includes/free-trial/partners/class-wc-calypso-bridge-partner-stripe.php @@ -0,0 +1,162 @@ +add_stripe_setup_task(); + $this->add_stripe_connect_url_to_js(); + $this->remove_woo_payments_from_payments_suggestions_feed(); + $this->remove_payments_note(); + } + + /** + * Remove woo payments from the payments suggestions feed. + * + * @return void + */ + private function remove_woo_payments_from_payments_suggestions_feed() { + add_filter( 'woocommerce_admin_payment_gateway_suggestion_specs', function( $specs ) { + $keys = array( + 'woocommerce_payments', + 'woocommerce_payments:with-in-person-payments', + 'woocommerce_payments:without-in-person-payments', + ); + foreach ( $keys as $key ) { + if ( isset( $specs[ $key ] ) ) { + unset( $specs[ $key ] ); + } + } + + return $specs; + }); + } + + private function has_stripe_plugin_class() { + return class_exists( '\WC_Stripe' ); + } + + /** + * Add Stripe setup task to the setup onboarding tasks list. + */ + private function add_stripe_setup_task() { + add_filter( 'woocommerce_admin_experimental_onboarding_tasklists', function( $lists ) { + if ( isset( $lists['setup'] ) ) { + require_once __DIR__ . '/../../tasks/class-wc-calypso-task-get-paid-with-stripe.php'; + + $lists['setup']->tasks = array_filter( $lists['setup']->tasks, function( $task ) { + $removeTasks = [ + 'Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\TrialPayments', + 'Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WooCommercePayments' + ]; + + if ( in_array( get_class( $task ), $removeTasks ) ) { + return false; + } + + return true; + }); + + // Place it at the third position. + array_splice( $lists['setup']->tasks, 2, 0, array( new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WCBridgeGetPaidWithStripe( $lists['setup'] ) ) ); + } + + return $lists; + } ); + } + + /** + * Add Stripe connect URL to the JS. + * + * @return void + */ + private function add_stripe_connect_url_to_js() { + add_filter( 'wc_calypso_bridge_shared_params', function( $params ) { + if ( ! $this->has_stripe_plugin_class() ) { + return $params; + } + + $stripe_oauth_url = woocommerce_gateway_stripe()->connect->get_oauth_url(); + if ( is_wp_error( $stripe_oauth_url ) ) { + // Fallback to the settings page + return $params['stripe_connect_url'] = add_query_arg( array( + 'page' => 'wc-settings', + 'tab' => 'square', + ), admin_url( 'admin.php' ) ); + } + + $params['stripe_connect_url'] = $stripe_oauth_url; + return $params; + }); + } + + /** + * Remove wc-admin-onboarding-payments-reminder note from the notes api endpoint. + * + * @return void + */ + private function remove_payments_note() { + add_filter( 'rest_request_after_callbacks', function( $response, $handler, $request ) { + if ( $request->get_route() === '/wc-analytics/admin/notes' ) { + $data = $response->get_data(); + foreach( $data as $key=>$note ) { + if ( isset( $note['name'] ) && $note['name'] === 'wc-admin-onboarding-payments-reminder' ) { + unset( $data[$key] ); + $headers = $response->get_headers(); + if ( isset( $headers['X-WP-Total'] ) ) { + $headers['X-WP-Total'] = (int) $headers['X-WP-Total'] - 1; + $response->set_headers( $headers ); + } + break; + } + } + $response->set_data( array_values( $data ) ); + } + return $response; + }, 10, 3); + } +} + +WC_Calypso_Bridge_Partner_Stripe::get_instance(); diff --git a/includes/tasks/class-wc-calypso-task-get-paid-with-stripe.php b/includes/tasks/class-wc-calypso-task-get-paid-with-stripe.php new file mode 100644 index 00000000..4b6fd878 --- /dev/null +++ b/includes/tasks/class-wc-calypso-task-get-paid-with-stripe.php @@ -0,0 +1,76 @@ +connect->is_connected(); + } + + /** + * Time. + * + * @return string + */ + public function get_time() { + return __( '2 minutes', 'wc-calypso-bridge' ); + } + + /** + * Action label. + * + * @return string + */ + public function get_action_label() { + return __( 'Get paid with Stripe', 'wc-calypso-bridge' ); + } +} diff --git a/src/index.js b/src/index.js index b8c4f141..cdffba76 100644 --- a/src/index.js +++ b/src/index.js @@ -27,11 +27,7 @@ import { } from './homescreen-progress-header'; import './index.scss'; import { CalypsoBridgeHomescreenBanner } from './homescreen-banner'; -import { - AppearanceFill, - GetPaidWithSquareFill, - GetPaidWithPayPalFill, -} from './task-fills'; +import { AppearanceFill, GetPaidWithSquareFill, GetPaidWithStripeFill, GetPaidWithPayPalFill } from './task-fills'; import './task-headers'; import './track-menu-item'; import { CalypsoBridgeIntroductoryOfferBanner } from './introductory-offer-banner'; @@ -180,6 +176,15 @@ if ( !! window.wcCalypsoBridge.isEcommercePlanTrial ) { render: GetPaidWithSquareFill, } ); } + + if ( window?.wcCalypsoBridge?.stripe_connect_url ) { + // Setup Stripe task fill (Partner Aware Onboarding). + registerPlugin( 'wc-calypso-bridge-task-setup-woocommerce-stripe', { + scope: 'woocommerce-tasks', + render: GetPaidWithStripeFill, + } ); + } + if ( window?.wcCalypsoBridge?.paypal_connect_url ) { // Setup PayPal task fill (Partner Aware Onboarding). registerPlugin( 'wc-calypso-bridge-task-setup-woocommerce-paypal', { diff --git a/src/task-fills/get-paid-with-stripe.js b/src/task-fills/get-paid-with-stripe.js new file mode 100644 index 00000000..3613e920 --- /dev/null +++ b/src/task-fills/get-paid-with-stripe.js @@ -0,0 +1,20 @@ +/** + * External dependencies + */ +import React from 'react'; +import { WooOnboardingTaskListItem } from '@woocommerce/onboarding'; + +export const GetPaidWithStripeFill = () => { + return ( + + { ( { defaultTaskItem: DefaultTaskItem } ) => ( + { + window.location.href = + window.wcCalypsoBridge.stripe_connect_url; + } } + /> + ) } + + ); +}; diff --git a/src/task-fills/index.js b/src/task-fills/index.js index 053c6f8e..3ba3c7a5 100644 --- a/src/task-fills/index.js +++ b/src/task-fills/index.js @@ -1,3 +1,4 @@ export * from './appearance.js'; export * from './get-paid-with-square.js'; +export * from './get-paid-with-stripe.js'; export * from './get-paid-with-paypal.js'; diff --git a/src/task-headers/get-paid-with-stripe.js b/src/task-headers/get-paid-with-stripe.js new file mode 100644 index 00000000..16ca29ab --- /dev/null +++ b/src/task-headers/get-paid-with-stripe.js @@ -0,0 +1,72 @@ +/** + * External dependencies + */ +import { Button } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { WooOnboardingTaskListHeader } from '@woocommerce/onboarding'; +import { registerPlugin } from '@wordpress/plugins'; + +/** + * Internal dependencies + */ +import TimerImage from './assets/images/timer.svg'; +import { WC_ASSET_URL } from '../utils/admin-settings'; + +const GetPaidWithStripeHeader = () => { + return ( + + { ( { task, goToTask } ) => { + return ( +
+ { +
+

+ { __( + "It's time to get paid", + 'wc-calypso-bridge' + ) } +

+

+ { __( + 'Accepting payments is easy with Stripe. Sell online and in person, and sync all payments, customers, items, and inventory.', + 'wc-calypso-bridge' + ) } +

+ +

+ Timer{ ' ' } + { task.time } +

+
+
+ ); + } } +
+ ); +}; + +registerPlugin( 'wc-calypso-bridge-get-paid-with-stripe-task-header', { + render: GetPaidWithStripeHeader, + scope: 'woocommerce-tasks', +} ); + +export default GetPaidWithStripeHeader; diff --git a/src/task-headers/index.ts b/src/task-headers/index.ts index cd8791e5..1c3d8b26 100644 --- a/src/task-headers/index.ts +++ b/src/task-headers/index.ts @@ -2,4 +2,5 @@ export * from './add-domain'; export * from './products'; export * from './appearance'; export * from './get-paid-with-square'; +export * from './get-paid-with-stripe'; export * from './get-paid-with-paypal';