Skip to content

Commit

Permalink
Remove payments note, add a condition to avoid errors when plugin not…
Browse files Browse the repository at this point in the history
… installed
  • Loading branch information
epeicher committed Jul 18, 2024
1 parent 430ad63 commit da50aad
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct() {
$this->add_paypal_setup_task();
$this->add_paypal_connect_url_to_js();
$this->remove_woo_payments_from_payments_suggestions_feed();
$this->remove_payments_note();
}

/**
Expand Down Expand Up @@ -113,6 +114,7 @@ private function add_paypal_setup_task() {
private function add_paypal_connect_url_to_js() {
add_filter( 'wc_calypso_bridge_shared_params', function( $params ) {
if ( !$this->has_paypal_plugin_class() ){
$params['paypal_connect_url'] = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=connection_tab_id' );
return $params;
}

Expand All @@ -130,6 +132,32 @@ private function add_paypal_connect_url_to_js() {
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_PayPal::get_instance();
11 changes: 6 additions & 5 deletions includes/tasks/class-wc-calypso-task-get-paid-with-paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public function get_content() {
*
*/
public function is_complete() {
if(class_exists( '\WooCommerce\PayPalCommerce\PPCP' )) {
$paypal_container = \WooCommerce\PayPalCommerce\PPCP::container();
$onboarding_state = $paypal_container->get('onboarding.state');
return ( $onboarding_state->current_state() >= \WooCommerce\PayPalCommerce\Onboarding\State::STATE_ONBOARDED );
}

$paypal_container = \WooCommerce\PayPalCommerce\PPCP::container();
$onboarding_state = $paypal_container->get('onboarding.state');
$is_onboarded = ( $onboarding_state->current_state() >= \WooCommerce\PayPalCommerce\Onboarding\State::STATE_ONBOARDED );

return $is_onboarded;
return false;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ if ( !! window.wcCalypsoBridge.isWooExpress ) {
scope: 'woocommerce-admin',
} );
}
console.log(
'is it ecommerce plan trial??',
window.wcCalypsoBridge.isEcommercePlanTrial
);

if ( !! window.wcCalypsoBridge.isEcommercePlanTrial ) {
import( './free-trial/fills' );
Expand Down Expand Up @@ -180,7 +184,9 @@ if ( !! window.wcCalypsoBridge.isEcommercePlanTrial ) {
render: GetPaidWithSquareFill,
} );
}
console.log( 'in the main index but outside paypal connect url??' );
if ( window?.wcCalypsoBridge?.paypal_connect_url ) {
console.log( 'in the main index??' );
// Setup PayPal task fill (Partner Aware Onboarding).
registerPlugin( 'wc-calypso-bridge-task-setup-woocommerce-paypal', {
scope: 'woocommerce-tasks',
Expand Down
4 changes: 4 additions & 0 deletions src/task-fills/get-paid-with-paypal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import React from 'react';
import { WooOnboardingTaskListItem } from '@woocommerce/onboarding';

export const GetPaidWithPayPalFill = () => {
console.log(
'hola en el getpaid fill',
window.wcCalypsoBridge.paypal_connect_url
);
return (
<WooOnboardingTaskListItem id="get-paid-with-paypal">
{ ( { defaultTaskItem: DefaultTaskItem } ) => (
Expand Down
4 changes: 4 additions & 0 deletions src/task-headers/get-paid-with-paypal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import TimerImage from './assets/images/timer.svg';
import { WC_ASSET_URL } from '../utils/admin-settings';

const GetPaidWithPayPalHeader = () => {
console.log(
'hola en el getpaid',
window.wcCalypsoBridge.paypal_connect_url
);
return (
<WooOnboardingTaskListHeader id="get-paid-with-paypal">
{ ( { task, goToTask } ) => {
Expand Down

0 comments on commit da50aad

Please sign in to comment.