mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Adding frontend logger (WIP)
This commit is contained in:
parent
1d83b0ce85
commit
f6d07d9225
5 changed files with 103 additions and 0 deletions
|
@ -88,6 +88,20 @@ class AxoManager {
|
|||
this.triggerGatewayChange();
|
||||
}
|
||||
|
||||
async log(message, level = 'info') {
|
||||
await fetch(axoConfig.ajax.frontend_logger.endpoint, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
nonce: axoConfig.ajax.frontend_logger.nonce,
|
||||
log: {
|
||||
message,
|
||||
level,
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
registerEventHandlers() {
|
||||
|
||||
this.$(document).on('change', 'input[name=payment_method]', (ev) => {
|
||||
|
@ -697,6 +711,8 @@ class AxoManager {
|
|||
|
||||
this.ensureBillingPhoneNumber(data);
|
||||
|
||||
this.log(`Ryan flow - submitted nonce: ${this.data.card.id}` )
|
||||
|
||||
this.submit(this.data.card.id, data);
|
||||
|
||||
} else { // Gary flow
|
||||
|
@ -706,6 +722,7 @@ class AxoManager {
|
|||
this.cardComponent.getPaymentToken(
|
||||
this.tokenizeData()
|
||||
).then((response) => {
|
||||
this.log(`Gary flow - submitted nonce: ${response.id}` )
|
||||
this.submit(response.id);
|
||||
});
|
||||
} catch (e) {
|
||||
|
|
|
@ -225,4 +225,10 @@ return array(
|
|||
|
||||
return '<div class="ppcp-notice ppcp-notice-warning"><p>' . $notice_content . '</p></div>';
|
||||
},
|
||||
'axo.endpoint.frontend-logger' => static function (ContainerInterface $container): FrontendLoggerEndpoint {
|
||||
return new FrontendLoggerEndpoint(
|
||||
$container->get( 'button.request-data' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Axo\Assets;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\Axo\FrontendLoggerEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
|
||||
|
@ -209,6 +210,12 @@ class AxoManager {
|
|||
),
|
||||
'icons_directory' => esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/',
|
||||
'module_url' => untrailingslashit( $this->module_url ),
|
||||
'ajax' => array(
|
||||
'frontend_logger' => array(
|
||||
'endpoint' => \WC_AJAX::get_endpoint( FrontendLoggerEndpoint::ENDPOINT ),
|
||||
'nonce' => wp_create_nonce( FrontendLoggerEndpoint::nonce() ),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -239,6 +239,16 @@ class AxoModule implements ModuleInterface {
|
|||
1
|
||||
);
|
||||
|
||||
add_action(
|
||||
'wc_ajax_' . FrontendLoggerEndpoint::ENDPOINT,
|
||||
static function () use ( $c ) {
|
||||
$endpoint = $c->get( 'axo.endpoint.frontend-logger' );
|
||||
assert( $endpoint instanceof FrontendLoggerEndpoint );
|
||||
|
||||
$endpoint->handle_request();
|
||||
}
|
||||
);
|
||||
|
||||
// Add the markup necessary for displaying overlays and loaders for Axo on the checkout page.
|
||||
$this->add_checkout_loader_markup( $c );
|
||||
}
|
||||
|
|
63
modules/ppcp-axo/src/FrontendLoggerEndpoint.php
Normal file
63
modules/ppcp-axo/src/FrontendLoggerEndpoint.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* The endpoint to log entries from frontend.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Button\Endpoint
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Axo;
|
||||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
|
||||
|
||||
class FrontendLoggerEndpoint implements EndpointInterface {
|
||||
|
||||
const ENDPOINT = 'ppc-frontend-logger';
|
||||
|
||||
/**
|
||||
* The request data helper.
|
||||
*
|
||||
* @var RequestData
|
||||
*/
|
||||
private $request_data;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
public function __construct(RequestData $request_data, LoggerInterface $logger){
|
||||
$this->request_data = $request_data;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nonce.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function nonce(): string {
|
||||
return self::ENDPOINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the request.
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception On Error.
|
||||
*/
|
||||
public function handle_request(): bool {
|
||||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
|
||||
$this->logger->info("[AXO] " . $data['log']['message']);
|
||||
|
||||
wp_send_json_success();
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue