[Beta tester] Add fake WooPayments completion tool (#50699)
* Add woocommerce beta tester fake wcpay tool * Add changelog
This commit is contained in:
parent
8b62cf87e1
commit
b04f535a54
|
@ -55,6 +55,7 @@ require 'tools/trigger-update-callbacks.php';
|
|||
require 'tools/reset-cys.php';
|
||||
require 'tools/set-block-template-logging-threshold.php';
|
||||
require 'tools/set-coming-soon-mode.php';
|
||||
require 'tools/fake-woo-payments-gateway.php';
|
||||
require 'tracks/class-tracks-debug-log.php';
|
||||
require 'features/features.php';
|
||||
require 'rest-api-filters/class-wca-test-helper-rest-api-filters.php';
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* Fake WooPayments class.
|
||||
*
|
||||
* @package WC_Beta_Tester
|
||||
*/
|
||||
class Fake_WCPayments extends WC_Payment_Gateway_WCPay {
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'woocommerce_payments';
|
||||
$this->has_fields = true;
|
||||
$this->method_title = 'WooPayments';
|
||||
$this->method_description = $this->get_method_description();
|
||||
|
||||
$this->description = '';
|
||||
$this->supports = array(
|
||||
'products',
|
||||
'refunds',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the gateway needs additional configuration, false if it's ready to use.
|
||||
*
|
||||
* @see WC_Payment_Gateway::needs_setup
|
||||
* @return bool
|
||||
*/
|
||||
public function needs_setup() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the payment gateway is connected. This method is also used by
|
||||
* external plugins to check if a connection has been established.
|
||||
*/
|
||||
public function is_connected() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection URL.
|
||||
* Called directly by WooCommerce Core.
|
||||
*
|
||||
* @return string Connection URL.
|
||||
*/
|
||||
public function get_connection_url() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the gateway is enabled, and also if it's configured enough to accept payments from customers.
|
||||
*
|
||||
* Use parent method value alongside other business rules to make the decision.
|
||||
*
|
||||
* @return bool Whether the gateway is enabled and ready to accept payments.
|
||||
*/
|
||||
public function is_available() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Fake WooCommercePayments account data for testing purposes.
|
||||
*
|
||||
* @package WC_Beta_Tester
|
||||
* */
|
||||
|
||||
defined( 'ABSPATH' ) || exit();
|
||||
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/fake-wcpay-completion/v1',
|
||||
'tools_get_fake_wcpay_completion_status',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
)
|
||||
);
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/fake-wcpay-completion/v1',
|
||||
'tools_set_fake_wcpay_completion',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'args' => array(
|
||||
'enabled' => array(
|
||||
'type' => 'enum',
|
||||
'enum' => array( 'yes', 'no' ),
|
||||
'required' => true,
|
||||
'description' => 'Whether to enable or disable fake WooPayments completion',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the current status of fake WooPayments completion.
|
||||
*/
|
||||
function tools_get_fake_wcpay_completion_status() {
|
||||
return new WP_REST_Response( array( 'enabled' => get_option( 'wc_beta_tester_fake_wcpay_completion', 'no' ) ), 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool to enable/disable fake WooPayments completion.
|
||||
*
|
||||
* @param WP_REST_Request $request Request object.
|
||||
*/
|
||||
function tools_set_fake_wcpay_completion( $request ) {
|
||||
$enabled = $request->get_param( 'enabled' );
|
||||
update_option( 'wc_beta_tester_fake_wcpay_completion', $enabled );
|
||||
|
||||
return new WP_REST_Response( array( 'enabled' => $enabled ), 200 );
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
'yes' === get_option( 'wc_beta_tester_fake_wcpay_completion', 'no' ) &&
|
||||
class_exists( 'WC_Payment_Gateway_WCPay' )
|
||||
) {
|
||||
add_filter( 'woocommerce_payment_gateways', 'tools_fake_wcpay' );
|
||||
add_filter( 'woocommerce_available_payment_gateways', 'tools_fake_wcpay' );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/class-fake-wcpayments.php';
|
||||
|
||||
/**
|
||||
* Fake WooPayments completion.
|
||||
*
|
||||
* @param array $gateways List of available payment gateways.
|
||||
*/
|
||||
function tools_fake_wcpay( $gateways ) {
|
||||
$gateways['woocommerce_payments'] = new Fake_WCPayments();
|
||||
return $gateways;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add fake WooPayments completion tool
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { STORE_KEY } from '../data/constants';
|
||||
|
||||
export const FAKE_WOO_PAYMENTS_ACTION_NAME = 'fakeWooPayments';
|
||||
|
||||
export const FakeWooPayments = () => {
|
||||
const isEnabled = useSelect( ( select ) =>
|
||||
select( STORE_KEY ).getIsFakeWooPaymentsEnabled()
|
||||
);
|
||||
const getDescription = () => {
|
||||
switch ( isEnabled ) {
|
||||
case 'yes':
|
||||
return 'Enabled 🟢';
|
||||
case 'no':
|
||||
return 'Disabled 🔴';
|
||||
case 'error':
|
||||
return 'Error 🙁';
|
||||
default:
|
||||
return 'Loading ...';
|
||||
}
|
||||
};
|
||||
|
||||
return <div>{ getDescription() }</div>;
|
||||
};
|
|
@ -15,6 +15,10 @@ import {
|
|||
SetComingSoonMode,
|
||||
UPDATE_COMING_SOON_MODE_ACTION_NAME,
|
||||
} from './set-coming-soon-mode';
|
||||
import {
|
||||
FakeWooPayments,
|
||||
FAKE_WOO_PAYMENTS_ACTION_NAME,
|
||||
} from './fake-woo-payments';
|
||||
|
||||
import {
|
||||
UPDATE_WCCOM_REQUEST_ERRORS_MODE,
|
||||
|
@ -97,4 +101,9 @@ export default [
|
|||
description: <SetWccomRequestErrros />,
|
||||
action: UPDATE_WCCOM_REQUEST_ERRORS_MODE,
|
||||
},
|
||||
{
|
||||
command: 'Toggle Fake WooPayments Completion Status',
|
||||
description: <FakeWooPayments />,
|
||||
action: FAKE_WOO_PAYMENTS_ACTION_NAME,
|
||||
},
|
||||
];
|
||||
|
|
|
@ -282,3 +282,28 @@ export function* updateWccomRequestErrorsMode( params ) {
|
|||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
export function* fakeWooPayments( params ) {
|
||||
yield runCommand( 'Toggle Fake WooPayments Completion', function* () {
|
||||
const newStatus = params.enabled === 'yes' ? 'no' : 'yes';
|
||||
|
||||
yield apiFetch( {
|
||||
path: API_NAMESPACE + '/tools/fake-wcpay-completion/v1',
|
||||
method: 'POST',
|
||||
data: {
|
||||
enabled: newStatus,
|
||||
},
|
||||
} );
|
||||
|
||||
yield updateCommandParams( 'fakeWooPayments', {
|
||||
enabled: newStatus,
|
||||
} );
|
||||
|
||||
yield updateMessage(
|
||||
'Toggle Fake WooPayments Completion',
|
||||
`Fake WooPayments completion ${
|
||||
newStatus === 'yes' ? 'disabled' : 'enabled'
|
||||
}`
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ const DEFAULT_STATE = {
|
|||
updateBlockTemplateLoggingThreshold: {},
|
||||
runSelectedUpdateCallbacks: {},
|
||||
updateWccomRequestErrorsMode: {},
|
||||
fakeWooPayments: {},
|
||||
},
|
||||
status: '',
|
||||
dbUpdateVersions: [],
|
||||
|
|
|
@ -18,6 +18,7 @@ import { UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD_ACTION_NAME } from '../commands
|
|||
import { UPDATE_COMING_SOON_MODE_ACTION_NAME } from '../commands/set-coming-soon-mode';
|
||||
import { TRIGGER_UPDATE_CALLBACKS_ACTION_NAME } from '../commands/trigger-update-callbacks';
|
||||
import { UPDATE_WCCOM_REQUEST_ERRORS_MODE } from '../commands/set-wccom-request-errors';
|
||||
import { FAKE_WOO_PAYMENTS_ACTION_NAME } from '../commands/fake-woo-payments';
|
||||
|
||||
export function* getCronJobs() {
|
||||
const path = `${ API_NAMESPACE }/tools/get-cron-list/v1`;
|
||||
|
@ -135,3 +136,17 @@ export function* getWccomRequestErrorsMode() {
|
|||
throw new Error( error );
|
||||
}
|
||||
}
|
||||
|
||||
export function* getIsFakeWooPaymentsEnabled() {
|
||||
try {
|
||||
const response = yield apiFetch( {
|
||||
path: API_NAMESPACE + '/tools/fake-wcpay-completion/v1',
|
||||
method: 'GET',
|
||||
} );
|
||||
yield updateCommandParams( FAKE_WOO_PAYMENTS_ACTION_NAME, {
|
||||
enabled: response.enabled || 'no',
|
||||
} );
|
||||
} catch ( error ) {
|
||||
throw new Error( error );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,3 +41,7 @@ export function getComingSoonMode( state ) {
|
|||
export function getWccomRequestErrorsMode( state ) {
|
||||
return state.params.updateWccomRequestErrorsMode.mode;
|
||||
}
|
||||
|
||||
export function getIsFakeWooPaymentsEnabled( state ) {
|
||||
return state.params.fakeWooPayments.enabled;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue