mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Add place order method in block together with express
This commit is contained in:
parent
ea35893a82
commit
758bb5da29
3 changed files with 53 additions and 31 deletions
|
@ -320,7 +320,7 @@ const PayPalComponent = ({
|
||||||
|
|
||||||
const features = ['products'];
|
const features = ['products'];
|
||||||
|
|
||||||
if (config.usePlaceOrder && !config.scriptData.continuation) {
|
if ((config.addPlaceOrderMethod || config.usePlaceOrder) && !config.scriptData.continuation) {
|
||||||
registerPaymentMethod({
|
registerPaymentMethod({
|
||||||
name: config.id,
|
name: config.id,
|
||||||
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
|
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
|
||||||
|
@ -333,39 +333,39 @@ if (config.usePlaceOrder && !config.scriptData.continuation) {
|
||||||
features: features,
|
features: features,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
if (config.scriptData.continuation) {
|
|
||||||
registerPaymentMethod({
|
if (config.scriptData.continuation) {
|
||||||
name: config.id,
|
registerPaymentMethod({
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
|
||||||
|
content: <PayPalComponent isEditing={false}/>,
|
||||||
|
edit: <PayPalComponent isEditing={true}/>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => true,
|
||||||
|
supports: {
|
||||||
|
features: [...features, 'ppcp_continuation'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (!config.usePlaceOrder) {
|
||||||
|
const paypalScriptPromise = loadPaypalScriptPromise(config.scriptData);
|
||||||
|
|
||||||
|
for (const fundingSource of ['paypal', ...config.enabledFundingSources]) {
|
||||||
|
registerExpressPaymentMethod({
|
||||||
|
name: `${config.id}-${fundingSource}`,
|
||||||
|
paymentMethodId: config.id,
|
||||||
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
|
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
|
||||||
content: <PayPalComponent isEditing={false}/>,
|
content: <PayPalComponent isEditing={false} fundingSource={fundingSource}/>,
|
||||||
edit: <PayPalComponent isEditing={true}/>,
|
edit: <PayPalComponent isEditing={true}/>,
|
||||||
ariaLabel: config.title,
|
ariaLabel: config.title,
|
||||||
canMakePayment: () => true,
|
canMakePayment: async () => {
|
||||||
|
await paypalScriptPromise;
|
||||||
|
|
||||||
|
return paypal.Buttons({fundingSource}).isEligible();
|
||||||
|
},
|
||||||
supports: {
|
supports: {
|
||||||
features: [...features, 'ppcp_continuation'],
|
features: features,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
const paypalScriptPromise = loadPaypalScriptPromise(config.scriptData);
|
|
||||||
|
|
||||||
for (const fundingSource of ['paypal', ...config.enabledFundingSources]) {
|
|
||||||
registerExpressPaymentMethod({
|
|
||||||
name: `${config.id}-${fundingSource}`,
|
|
||||||
paymentMethodId: config.id,
|
|
||||||
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
|
|
||||||
content: <PayPalComponent isEditing={false} fundingSource={fundingSource}/>,
|
|
||||||
edit: <PayPalComponent isEditing={true}/>,
|
|
||||||
ariaLabel: config.title,
|
|
||||||
canMakePayment: async () => {
|
|
||||||
await paypalScriptPromise;
|
|
||||||
|
|
||||||
return paypal.Buttons({fundingSource}).isEligible();
|
|
||||||
},
|
|
||||||
supports: {
|
|
||||||
features: features,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ return array(
|
||||||
$container->get( 'blocks.settings.final_review_enabled' ),
|
$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' ),
|
||||||
|
$container->get( 'blocks.add-place-order-method' ),
|
||||||
$container->get( 'wcgateway.use-place-order-button' ),
|
$container->get( 'wcgateway.use-place-order-button' ),
|
||||||
$container->get( 'wcgateway.place-order-button-text' ),
|
$container->get( 'wcgateway.place-order-button-text' ),
|
||||||
$container->get( 'wcgateway.all-funding-sources' )
|
$container->get( 'wcgateway.all-funding-sources' )
|
||||||
|
@ -57,4 +58,14 @@ return array(
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'blocks.add-place-order-method' => function ( ContainerInterface $container ) : bool {
|
||||||
|
/**
|
||||||
|
* Whether to create a non-express method with the standard "Place order" button redirecting to PayPal.
|
||||||
|
*/
|
||||||
|
return apply_filters(
|
||||||
|
'woocommerce_paypal_payments_blocks_add_place_order_method',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -88,7 +88,14 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
private $session_handler;
|
private $session_handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to use the standard "Place order" button.
|
* Whether to create a non-express method with the standard "Place order" button.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $add_place_order_method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use the standard "Place order" button instead of PayPal buttons.
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
|
@ -120,7 +127,8 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
* @param bool $final_review_enabled Whether the final review is enabled.
|
* @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.
|
||||||
* @param bool $use_place_order Whether to use the standard "Place order" button.
|
* @param bool $add_place_order_method Whether to create a non-express method with the standard "Place order" button.
|
||||||
|
* @param bool $use_place_order Whether to use the standard "Place order" button instead of PayPal buttons.
|
||||||
* @param string $place_order_button_text The text for the standard "Place order" button.
|
* @param string $place_order_button_text The text for the standard "Place order" button.
|
||||||
* @param array $all_funding_sources All existing funding sources for PayPal buttons.
|
* @param array $all_funding_sources All existing funding sources for PayPal buttons.
|
||||||
*/
|
*/
|
||||||
|
@ -134,6 +142,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
bool $final_review_enabled,
|
bool $final_review_enabled,
|
||||||
CancelView $cancellation_view,
|
CancelView $cancellation_view,
|
||||||
SessionHandler $session_handler,
|
SessionHandler $session_handler,
|
||||||
|
bool $add_place_order_method,
|
||||||
bool $use_place_order,
|
bool $use_place_order,
|
||||||
string $place_order_button_text,
|
string $place_order_button_text,
|
||||||
array $all_funding_sources
|
array $all_funding_sources
|
||||||
|
@ -148,6 +157,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
$this->final_review_enabled = $final_review_enabled;
|
$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;
|
||||||
|
$this->add_place_order_method = $add_place_order_method;
|
||||||
$this->use_place_order = $use_place_order;
|
$this->use_place_order = $use_place_order;
|
||||||
$this->place_order_button_text = $place_order_button_text;
|
$this->place_order_button_text = $place_order_button_text;
|
||||||
$this->all_funding_sources = $all_funding_sources;
|
$this->all_funding_sources = $all_funding_sources;
|
||||||
|
@ -219,6 +229,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
||||||
'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,
|
'finalReviewEnabled' => $this->final_review_enabled,
|
||||||
|
'addPlaceOrderMethod' => $this->add_place_order_method,
|
||||||
'usePlaceOrder' => $this->use_place_order,
|
'usePlaceOrder' => $this->use_place_order,
|
||||||
'placeOrderButtonText' => $this->place_order_button_text,
|
'placeOrderButtonText' => $this->place_order_button_text,
|
||||||
'enabledFundingSources' => $funding_sources,
|
'enabledFundingSources' => $funding_sources,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue