mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Add axo script attributes to blocks checkout
This commit is contained in:
parent
57e36ed954
commit
06c000b42b
4 changed files with 30 additions and 3 deletions
|
@ -27,12 +27,36 @@ const usePayPalScript = ( namespace, ppcpConfig, isConfigLoaded ) => {
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
const loadScript = async () => {
|
const loadScript = async () => {
|
||||||
if ( ! isPayPalLoaded && isConfigLoaded ) {
|
if ( ! isPayPalLoaded && isConfigLoaded ) {
|
||||||
|
const axoConfig = window.wc_ppcp_axo;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
axoConfig.ajax.axo_script_attributes.endpoint,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
body: JSON.stringify( {
|
||||||
|
nonce: axoConfig.ajax.axo_script_attributes
|
||||||
|
.nonce,
|
||||||
|
} ),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
if ( ! json.success ) {
|
||||||
|
log(
|
||||||
|
`Failed to load axo script attributes: ${ json.data.message }`,
|
||||||
|
'error'
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await loadPayPalScript( namespace, {
|
await loadPayPalScript( namespace, {
|
||||||
...ppcpConfig,
|
...ppcpConfig,
|
||||||
script_attributes: {
|
script_attributes: {
|
||||||
...ppcpConfig.script_attributes,
|
...ppcpConfig.script_attributes,
|
||||||
'data-sdk-client-token': 'abc123',
|
'data-sdk-client-token': json.data.sdk_client_token,
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
setIsPayPalLoaded( true );
|
setIsPayPalLoaded( true );
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\AxoBlock;
|
||||||
|
|
||||||
use WC_Payment_Gateway;
|
use WC_Payment_Gateway;
|
||||||
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
use WooCommerce\PayPalCommerce\Axo\Endpoint\AxoScriptAttributes;
|
||||||
use WooCommerce\PayPalCommerce\Axo\Endpoint\FrontendLogger;
|
use WooCommerce\PayPalCommerce\Axo\Endpoint\FrontendLogger;
|
||||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||||
|
@ -261,6 +262,10 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
||||||
'endpoint' => \WC_AJAX::get_endpoint( FrontendLogger::ENDPOINT ),
|
'endpoint' => \WC_AJAX::get_endpoint( FrontendLogger::ENDPOINT ),
|
||||||
'nonce' => wp_create_nonce( FrontendLogger::nonce() ),
|
'nonce' => wp_create_nonce( FrontendLogger::nonce() ),
|
||||||
),
|
),
|
||||||
|
'axo_script_attributes' => array(
|
||||||
|
'endpoint' => \WC_AJAX::get_endpoint( AxoScriptAttributes::ENDPOINT ),
|
||||||
|
'nonce' => wp_create_nonce( AxoScriptAttributes::nonce() ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||||
|
|
|
@ -35,7 +35,6 @@ import { log } from './Helper/Debug';
|
||||||
script_attributes: {
|
script_attributes: {
|
||||||
...ppcpConfig.script_attributes,
|
...ppcpConfig.script_attributes,
|
||||||
'data-sdk-client-token': json.data.sdk_client_token,
|
'data-sdk-client-token': json.data.sdk_client_token,
|
||||||
'data-client-metadata-id': json.data.client_metadata_id,
|
|
||||||
},
|
},
|
||||||
} )
|
} )
|
||||||
.then( () => {
|
.then( () => {
|
||||||
|
|
|
@ -44,7 +44,6 @@ class AxoScriptAttributes implements EndpointInterface {
|
||||||
wp_send_json_success(
|
wp_send_json_success(
|
||||||
array(
|
array(
|
||||||
'sdk_client_token' => $token,
|
'sdk_client_token' => $token,
|
||||||
'client_metadata_id' => str_replace('-', '', wp_generate_uuid4()),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue