mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Handle final review option
This commit is contained in:
parent
57414cff9f
commit
37959ad2d8
6 changed files with 90 additions and 42 deletions
|
@ -41,7 +41,7 @@ return array(
|
||||||
$fields,
|
$fields,
|
||||||
'smart_button_enable_styling_per_location',
|
'smart_button_enable_styling_per_location',
|
||||||
array(
|
array(
|
||||||
'blocks_no_final_review' => array(
|
'blocks_final_review_enabled' => array(
|
||||||
'title' => __( 'Block Express payments Final Review', 'woocommerce-paypal-payments' ),
|
'title' => __( 'Block Express payments Final Review', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'label' => __( 'Require customers to confirm Block Express payments on the Checkout page. If disabled, the Checkout page is skipped for Block Express payments.', 'woocommerce-paypal-payments' ),
|
'label' => __( 'Require customers to confirm Block Express payments on the Checkout page. If disabled, the Checkout page is skipped for Block Express payments.', 'woocommerce-paypal-payments' ),
|
||||||
|
|
|
@ -100,3 +100,19 @@ export const paypalOrderToWcShippingAddress = (order) => {
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param order
|
||||||
|
* @returns {{shippingAddress: Object, billingAddress: Object}}
|
||||||
|
*/
|
||||||
|
export const paypalOrderToWcAddresses = (order) => {
|
||||||
|
const shippingAddress = paypalOrderToWcShippingAddress(order);
|
||||||
|
let billingAddress = paypalPayerToWc(order.payer);
|
||||||
|
// no billing address, such as if billing address retrieval is not allowed in the merchant account
|
||||||
|
if (!billingAddress.address_line_1) {
|
||||||
|
billingAddress = {...shippingAddress, ...paypalPayerToWc(order.payer)};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {billingAddress, shippingAddress};
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {useEffect, useState} from '@wordpress/element';
|
import {useEffect, useState} from '@wordpress/element';
|
||||||
import {registerExpressPaymentMethod, registerPaymentMethod} from '@woocommerce/blocks-registry';
|
import {registerExpressPaymentMethod, registerPaymentMethod} from '@woocommerce/blocks-registry';
|
||||||
import {paypalOrderToWcShippingAddress, paypalPayerToWc} from "./Helper/Address";
|
import {paypalOrderToWcAddresses} from "./Helper/Address";
|
||||||
import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading'
|
import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading'
|
||||||
|
|
||||||
const config = wc.wcSettings.getSetting('ppcp-gateway_data');
|
const config = wc.wcSettings.getSetting('ppcp-gateway_data');
|
||||||
|
@ -96,24 +96,22 @@ const PayPalComponent = ({
|
||||||
|
|
||||||
setPaypalOrder(order);
|
setPaypalOrder(order);
|
||||||
|
|
||||||
const shippingAddress = paypalOrderToWcShippingAddress(order);
|
if (config.finalReviewEnabled) {
|
||||||
let billingAddress = paypalPayerToWc(order.payer);
|
const addresses = paypalOrderToWcAddresses(order);
|
||||||
// no billing address, such as if billing address retrieval is not allowed in the merchant account
|
|
||||||
if (!billingAddress.address_line_1) {
|
|
||||||
billingAddress = {...shippingAddress, ...paypalPayerToWc(order.payer)};
|
|
||||||
}
|
|
||||||
|
|
||||||
await wp.data.dispatch('wc/store/cart').updateCustomerData({
|
await wp.data.dispatch('wc/store/cart').updateCustomerData({
|
||||||
billing_address: billingAddress,
|
billing_address: addresses.billingAddress,
|
||||||
shipping_address: shippingAddress,
|
shipping_address: addresses.shippingAddress,
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkoutUrl = new URL(config.scriptData.redirect);
|
const checkoutUrl = new URL(config.scriptData.redirect);
|
||||||
// sometimes some browsers may load some kind of cached version of the page,
|
// sometimes some browsers may load some kind of cached version of the page,
|
||||||
// so adding a parameter to avoid that
|
// so adding a parameter to avoid that
|
||||||
checkoutUrl.searchParams.append('ppcp-continuation-redirect', (new Date()).getTime().toString());
|
checkoutUrl.searchParams.append('ppcp-continuation-redirect', (new Date()).getTime().toString());
|
||||||
|
|
||||||
location.href = checkoutUrl.toString();
|
location.href = checkoutUrl.toString();
|
||||||
|
} else {
|
||||||
|
onSubmit();
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
|
@ -144,10 +142,23 @@ const PayPalComponent = ({
|
||||||
paymentMethodData: {
|
paymentMethodData: {
|
||||||
'paypal_order_id': config.scriptData.continuation.order_id,
|
'paypal_order_id': config.scriptData.continuation.order_id,
|
||||||
'funding_source': window.ppcpFundingSource ?? 'paypal',
|
'funding_source': window.ppcpFundingSource ?? 'paypal',
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addresses = paypalOrderToWcAddresses(paypalOrder);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: responseTypes.SUCCESS,
|
||||||
|
meta: {
|
||||||
|
paymentMethodData: {
|
||||||
|
'paypal_order_id': paypalOrder.id,
|
||||||
|
'funding_source': window.ppcpFundingSource ?? 'paypal',
|
||||||
|
},
|
||||||
|
...addresses,
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
unsubscribeProcessing();
|
unsubscribeProcessing();
|
||||||
|
|
|
@ -31,8 +31,17 @@ return array(
|
||||||
$container->get( 'wcgateway.settings' ),
|
$container->get( 'wcgateway.settings' ),
|
||||||
$container->get( 'wcgateway.settings.status' ),
|
$container->get( 'wcgateway.settings.status' ),
|
||||||
$container->get( 'wcgateway.paypal-gateway' ),
|
$container->get( 'wcgateway.paypal-gateway' ),
|
||||||
|
$container->get( 'blocks.settings.final_review_enabled' ),
|
||||||
$container->get( 'session.cancellation.view' ),
|
$container->get( 'session.cancellation.view' ),
|
||||||
$container->get( 'session.handler' )
|
$container->get( 'session.handler' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'blocks.settings.final_review_enabled' => static function ( ContainerInterface $container ): bool {
|
||||||
|
$settings = $container->get( 'wcgateway.settings' );
|
||||||
|
assert( $settings instanceof ContainerInterface );
|
||||||
|
|
||||||
|
return $settings->has( 'blocks_final_review_enabled' ) ?
|
||||||
|
(bool) $settings->get( 'blocks_final_review_enabled' ) :
|
||||||
|
true;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -64,6 +64,13 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
*/
|
*/
|
||||||
private $gateway;
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the final review is enabled.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $final_review_enabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The cancellation view.
|
* The cancellation view.
|
||||||
*
|
*
|
||||||
|
@ -87,6 +94,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
* @param Settings $plugin_settings The settings.
|
* @param Settings $plugin_settings The settings.
|
||||||
* @param SettingsStatus $settings_status The Settings status helper.
|
* @param SettingsStatus $settings_status The Settings status helper.
|
||||||
* @param PayPalGateway $gateway The WC gateway.
|
* @param PayPalGateway $gateway The WC gateway.
|
||||||
|
* @param bool $final_review_enabled Whether the final review is enabled.
|
||||||
* @param CancelView $cancellation_view The cancellation view.
|
* @param CancelView $cancellation_view The cancellation view.
|
||||||
* @param SessionHandler $session_handler The Session handler.
|
* @param SessionHandler $session_handler The Session handler.
|
||||||
*/
|
*/
|
||||||
|
@ -97,6 +105,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
Settings $plugin_settings,
|
Settings $plugin_settings,
|
||||||
SettingsStatus $settings_status,
|
SettingsStatus $settings_status,
|
||||||
PayPalGateway $gateway,
|
PayPalGateway $gateway,
|
||||||
|
bool $final_review_enabled,
|
||||||
CancelView $cancellation_view,
|
CancelView $cancellation_view,
|
||||||
SessionHandler $session_handler
|
SessionHandler $session_handler
|
||||||
) {
|
) {
|
||||||
|
@ -107,6 +116,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
$this->plugin_settings = $plugin_settings;
|
$this->plugin_settings = $plugin_settings;
|
||||||
$this->settings_status = $settings_status;
|
$this->settings_status = $settings_status;
|
||||||
$this->gateway = $gateway;
|
$this->gateway = $gateway;
|
||||||
|
$this->final_review_enabled = $final_review_enabled;
|
||||||
$this->cancellation_view = $cancellation_view;
|
$this->cancellation_view = $cancellation_view;
|
||||||
$this->session_handler = $session_handler;
|
$this->session_handler = $session_handler;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +173,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
'description' => $this->gateway->description,
|
'description' => $this->gateway->description,
|
||||||
'enabled' => $this->settings_status->is_smart_button_enabled_for_location( $script_data['context'] ),
|
'enabled' => $this->settings_status->is_smart_button_enabled_for_location( $script_data['context'] ),
|
||||||
'fundingSource' => $this->session_handler->funding_source(),
|
'fundingSource' => $this->session_handler->funding_source(),
|
||||||
|
'finalReviewEnabled' => $this->final_review_enabled,
|
||||||
'scriptData' => $script_data,
|
'scriptData' => $script_data,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,13 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo
|
||||||
|
|
||||||
const form = jQuery('#mainform');
|
const form = jQuery('#mainform');
|
||||||
|
|
||||||
const noReviewChk = document.querySelector('#ppcp-blocks_no_final_review');
|
// TODO: maybe move to a separate JS file in blocks module, when we need more JS for block settings
|
||||||
if (noReviewChk) {
|
const finalReviewCheckbox = document.querySelector('#ppcp-blocks_final_review_enabled');
|
||||||
noReviewChk.addEventListener('click', (e) => {
|
if (finalReviewCheckbox) {
|
||||||
if (!noReviewChk.checked) {
|
finalReviewCheckbox.addEventListener('click', () => {
|
||||||
|
if (!finalReviewCheckbox.checked) {
|
||||||
if (!window.confirm('Are you sure you want to disable the final review on the Checkout page for Block Express payments?')) {
|
if (!window.confirm('Are you sure you want to disable the final review on the Checkout page for Block Express payments?')) {
|
||||||
noReviewChk.checked = true;
|
finalReviewCheckbox.checked = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue