mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
🔀 Merge branch 'trunk'
This commit is contained in:
commit
e1de89e25f
11 changed files with 187 additions and 135 deletions
|
@ -682,6 +682,11 @@ return array(
|
|||
'GB' => $default_currencies,
|
||||
'US' => $default_currencies,
|
||||
'NO' => $default_currencies,
|
||||
'YT' => $default_currencies,
|
||||
'RE' => $default_currencies,
|
||||
'GP' => $default_currencies,
|
||||
'GF' => $default_currencies,
|
||||
'MQ' => $default_currencies,
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Applepay;
|
|||
|
||||
use WC_Payment_Gateway;
|
||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Assets\ApplePayButton;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
|
||||
|
@ -198,6 +199,31 @@ class ApplepayModule implements ServiceModule, ExtendingModule, ExecutableModule
|
|||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'ppcp_create_order_request_body_data',
|
||||
static function ( array $data, string $payment_method, array $request ) use ( $c ) : array {
|
||||
|
||||
if ( $payment_method !== ApplePayGateway::ID ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$experience_context_builder = $c->get( 'wcgateway.builder.experience-context' );
|
||||
assert( $experience_context_builder instanceof ExperienceContextBuilder );
|
||||
|
||||
$data['payment_source'] = array(
|
||||
'apple_pay' => array(
|
||||
'experience_context' => $experience_context_builder
|
||||
->with_endpoint_return_urls()
|
||||
->build()->to_array(),
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -392,50 +392,6 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once the checkout has been validated we execute this method.
|
||||
*
|
||||
* @param array $data The data.
|
||||
* @param \WP_Error $errors The errors, which occurred.
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception On Error.
|
||||
*/
|
||||
public function after_checkout_validation( array $data, \WP_Error $errors ): array {
|
||||
if ( ! $errors->errors ) {
|
||||
try {
|
||||
$order = $this->create_paypal_order();
|
||||
} catch ( Exception $exception ) {
|
||||
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case we are onboarded and everything is fine with the \WC_Order
|
||||
* we want this order to be created. We will intercept it and leave it
|
||||
* in the "Pending payment" status though, which than later will change
|
||||
* during the "onApprove"-JS callback or the webhook listener.
|
||||
*/
|
||||
if ( ! $this->early_order_handler->should_create_early_order() ) {
|
||||
wp_send_json_success( $this->make_response( $order ) );
|
||||
}
|
||||
$this->early_order_handler->register_for_order( $order );
|
||||
return $data;
|
||||
}
|
||||
|
||||
$this->logger->error( 'Checkout validation failed: ' . $errors->get_error_message() );
|
||||
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'name' => '',
|
||||
'message' => $errors->get_error_message(),
|
||||
'code' => (int) $errors->get_error_code(),
|
||||
'details' => array(),
|
||||
)
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the order in the PayPal, uses data from WC order if provided.
|
||||
*
|
||||
|
@ -485,8 +441,13 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
}
|
||||
}
|
||||
|
||||
$payment_source_key = 'paypal';
|
||||
if ( in_array( $funding_source, array( 'venmo' ), true ) ) {
|
||||
$payment_source_key = $funding_source;
|
||||
}
|
||||
|
||||
$payment_source = new PaymentSource(
|
||||
'paypal',
|
||||
$payment_source_key,
|
||||
(object) array(
|
||||
'experience_context' => $this->experience_context_builder
|
||||
->with_default_paypal_config( $shipping_preference, $action )
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\CardFields;
|
|||
use DomainException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
|
||||
use WooCommerce\PayPalCommerce\CardFields\Service\CardCaptureValidator;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
|
@ -150,6 +151,15 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
|
|||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$experience_context_builder = $c->get( 'wcgateway.builder.experience-context' );
|
||||
assert( $experience_context_builder instanceof ExperienceContextBuilder );
|
||||
|
||||
$payment_source_data = array(
|
||||
'experience_context' => $experience_context_builder
|
||||
->with_endpoint_return_urls()
|
||||
->build()->to_array(),
|
||||
);
|
||||
|
||||
$three_d_secure_contingency =
|
||||
$settings->has( '3d_secure_contingency' )
|
||||
? apply_filters( 'woocommerce_paypal_payments_three_d_secure_contingency', $settings->get( '3d_secure_contingency' ) )
|
||||
|
@ -159,15 +169,15 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
|
|||
$three_d_secure_contingency === 'SCA_ALWAYS'
|
||||
|| $three_d_secure_contingency === 'SCA_WHEN_REQUIRED'
|
||||
) {
|
||||
$data['payment_source']['card'] = array(
|
||||
'attributes' => array(
|
||||
'verification' => array(
|
||||
'method' => $three_d_secure_contingency,
|
||||
),
|
||||
$payment_source_data['attributes'] = array(
|
||||
'verification' => array(
|
||||
'method' => $three_d_secure_contingency,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$data['payment_source'] = array( 'card' => $payment_source_data );
|
||||
|
||||
return $data;
|
||||
},
|
||||
10,
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Googlepay;
|
|||
|
||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||
use WC_Payment_Gateway;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
|
||||
|
@ -261,6 +262,15 @@ class GooglepayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$experience_context_builder = $c->get( 'wcgateway.builder.experience-context' );
|
||||
assert( $experience_context_builder instanceof ExperienceContextBuilder );
|
||||
|
||||
$payment_source_data = array(
|
||||
'experience_context' => $experience_context_builder
|
||||
->with_endpoint_return_urls()
|
||||
->build()->to_array(),
|
||||
);
|
||||
|
||||
$three_d_secure_contingency =
|
||||
$settings->has( '3d_secure_contingency' )
|
||||
? apply_filters( 'woocommerce_paypal_payments_three_d_secure_contingency', $settings->get( '3d_secure_contingency' ) )
|
||||
|
@ -270,15 +280,15 @@ class GooglepayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
$three_d_secure_contingency === 'SCA_ALWAYS'
|
||||
|| $three_d_secure_contingency === 'SCA_WHEN_REQUIRED'
|
||||
) {
|
||||
$data['payment_source']['google_pay'] = array(
|
||||
'attributes' => array(
|
||||
'verification' => array(
|
||||
'method' => $three_d_secure_contingency,
|
||||
),
|
||||
$payment_source_data['attributes'] = array(
|
||||
'verification' => array(
|
||||
'method' => $three_d_secure_contingency,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$data['payment_source'] = array( 'google_pay' => $payment_source_data );
|
||||
|
||||
return $data;
|
||||
},
|
||||
10,
|
||||
|
|
|
@ -78,6 +78,11 @@ return array(
|
|||
'SE',
|
||||
'GB',
|
||||
'US',
|
||||
'YT',
|
||||
'RE',
|
||||
'GP',
|
||||
'GF',
|
||||
'MQ',
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -115,87 +115,67 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
|
|||
function ( array $data, string $payment_method, array $request_data ) use ( $c ): array {
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$new_attributes = array(
|
||||
'vault' => array(
|
||||
'store_in_vault' => 'ON_SUCCESS',
|
||||
),
|
||||
);
|
||||
|
||||
$target_customer_id = get_user_meta( get_current_user_id(), '_ppcp_target_customer_id', true );
|
||||
if ( ! $target_customer_id ) {
|
||||
$target_customer_id = get_user_meta( get_current_user_id(), 'ppcp_customer_id', true );
|
||||
}
|
||||
if ( $target_customer_id ) {
|
||||
$new_attributes['customer'] = array(
|
||||
'id' => $target_customer_id,
|
||||
);
|
||||
}
|
||||
|
||||
$funding_source = (string) ( $request_data['funding_source'] ?? '' );
|
||||
|
||||
if ( $payment_method === CreditCardGateway::ID ) {
|
||||
if ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$save_payment_method = $request_data['save_payment_method'] ?? false;
|
||||
if ( $save_payment_method ) {
|
||||
$data['payment_source'] = array(
|
||||
'card' => array(
|
||||
'attributes' => array(
|
||||
'vault' => array(
|
||||
'store_in_vault' => 'ON_SUCCESS',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$target_customer_id = get_user_meta( get_current_user_id(), '_ppcp_target_customer_id', true );
|
||||
if ( ! $target_customer_id ) {
|
||||
$target_customer_id = get_user_meta( get_current_user_id(), 'ppcp_customer_id', true );
|
||||
}
|
||||
|
||||
if ( $target_customer_id ) {
|
||||
$data['payment_source']['card']['attributes']['customer'] = array(
|
||||
'id' => $target_customer_id,
|
||||
);
|
||||
}
|
||||
if ( ! $save_payment_method ) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $payment_method === PayPalGateway::ID ) {
|
||||
} elseif ( $payment_method === PayPalGateway::ID ) {
|
||||
if ( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$funding_source = $request_data['funding_source'] ?? null;
|
||||
|
||||
if ( $funding_source && $funding_source === 'venmo' ) {
|
||||
$data['payment_source'] = array(
|
||||
'venmo' => array(
|
||||
'attributes' => array(
|
||||
'vault' => array(
|
||||
'store_in_vault' => 'ON_SUCCESS',
|
||||
'usage_type' => 'MERCHANT',
|
||||
'permit_multiple_payment_tokens' => apply_filters( 'woocommerce_paypal_payments_permit_multiple_payment_tokens', false ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} elseif ( $funding_source && $funding_source === 'apple_pay' ) {
|
||||
$data['payment_source'] = array(
|
||||
'apple_pay' => array(
|
||||
'stored_credential' => array(
|
||||
'payment_initiator' => 'CUSTOMER',
|
||||
'payment_type' => 'RECURRING',
|
||||
),
|
||||
'attributes' => array(
|
||||
'vault' => array(
|
||||
'store_in_vault' => 'ON_SUCCESS',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
$data['payment_source'] = array(
|
||||
'paypal' => array(
|
||||
'attributes' => array(
|
||||
'vault' => array(
|
||||
'store_in_vault' => 'ON_SUCCESS',
|
||||
'usage_type' => 'MERCHANT',
|
||||
'permit_multiple_payment_tokens' => apply_filters( 'woocommerce_paypal_payments_permit_multiple_payment_tokens', false ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if ( ! in_array( $funding_source, array( 'paypal', 'venmo' ), true ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$new_attributes['vault']['usage_type'] = 'MERCHANT';
|
||||
$new_attributes['vault']['permit_multiple_payment_tokens'] = apply_filters( 'woocommerce_paypal_payments_permit_multiple_payment_tokens', false );
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$payment_source = (array) ( $data['payment_source'] ?? array() );
|
||||
$key = array_key_first( $payment_source );
|
||||
if ( ! is_string( $key ) || empty( $key ) ) {
|
||||
$key = $payment_method;
|
||||
if ( $payment_method === PayPalGateway::ID && $funding_source ) {
|
||||
$key = $funding_source;
|
||||
}
|
||||
$payment_source[ $key ] = array();
|
||||
}
|
||||
$payment_source[ $key ] = (array) $payment_source[ $key ];
|
||||
$attributes = (array) ( $payment_source[ $key ]['attributes'] ?? array() );
|
||||
$payment_source[ $key ]['attributes'] = array_merge( $attributes, $new_attributes );
|
||||
|
||||
$data['payment_source'] = $payment_source;
|
||||
|
||||
return $data;
|
||||
},
|
||||
10,
|
||||
20,
|
||||
3
|
||||
);
|
||||
|
||||
|
|
|
@ -269,7 +269,6 @@ class SettingsDataManager {
|
|||
// Enable BCDC for business sellers without ACDC.
|
||||
$this->payment_methods->toggle_method_state( CardButtonGateway::ID, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow plugins to modify apm payment gateway states before saving.
|
||||
*
|
||||
|
|
|
@ -576,7 +576,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
// Enable APMs after onboarding if the country is compatible.
|
||||
add_action(
|
||||
'woocommerce_paypal_payments_toggle_payment_gateways_apms',
|
||||
function ( PaymentSettings $payment_methods, array $methods_apm ) use ( $container ) {
|
||||
function ( PaymentSettings $payment_methods, array $methods_apm, ConfigurationFlagsDTO $flags ) use ( $container ) {
|
||||
|
||||
$general_settings = $container->get( 'settings.data.general' );
|
||||
assert( $general_settings instanceof GeneralSettings );
|
||||
|
@ -586,6 +586,11 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
|
||||
// Enable all APM methods.
|
||||
foreach ( $methods_apm as $method ) {
|
||||
if ( $flags->use_card_payments === false ) {
|
||||
$payment_methods->toggle_method_state( $method['id'], $flags->use_card_payments );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip PayUponInvoice if merchant is not in Germany.
|
||||
if ( PayUponInvoiceGateway::ID === $method['id'] && 'DE' !== $merchant_country ) {
|
||||
continue;
|
||||
|
@ -606,7 +611,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
}
|
||||
},
|
||||
10,
|
||||
2
|
||||
3
|
||||
);
|
||||
|
||||
// Toggle payment gateways after onboarding based on flags.
|
||||
|
|
|
@ -2022,6 +2022,49 @@ return array(
|
|||
return new TaskRegistrar();
|
||||
},
|
||||
|
||||
'wcgateway.settings.wc-tasks.pay-later-task-config' => static function( ContainerInterface $container ): array {
|
||||
$section_id = PayPalGateway::ID;
|
||||
$pay_later_tab_id = Settings::PAY_LATER_TAB_ID;
|
||||
|
||||
if ( $container->has( 'paylater-configurator.is-available' ) && $container->get( 'paylater-configurator.is-available' ) ) {
|
||||
return array(
|
||||
array(
|
||||
'id' => 'pay-later-messaging-task',
|
||||
'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ),
|
||||
'redirect_url' => admin_url( "admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}" ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return array();
|
||||
},
|
||||
|
||||
'wcgateway.settings.wc-tasks.connect-task-config' => static function( ContainerInterface $container ): array {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
$is_current_country_send_only = $container->get( 'wcgateway.is-send-only-country' );
|
||||
|
||||
if ( ! $is_connected && ! $is_current_country_send_only ) {
|
||||
return array(
|
||||
array(
|
||||
'id' => 'connect-to-paypal-task',
|
||||
'title' => __( 'Connect PayPal to complete setup', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'PayPal Payments is almost ready. To get started, connect your account with the Activate PayPal Payments button.', 'woocommerce-paypal-payments' ),
|
||||
'redirect_url' => admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=' . Settings::CONNECTION_TAB_ID ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return array();
|
||||
},
|
||||
|
||||
'wcgateway.settings.wc-tasks.task-config-services' => static function(): array {
|
||||
return array(
|
||||
'wcgateway.settings.wc-tasks.pay-later-task-config',
|
||||
'wcgateway.settings.wc-tasks.connect-task-config',
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* A configuration for simple redirect wc tasks.
|
||||
*
|
||||
|
@ -2033,18 +2076,14 @@ return array(
|
|||
* }>
|
||||
*/
|
||||
'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' => static function( ContainerInterface $container ): array {
|
||||
$section_id = PayPalGateway::ID;
|
||||
$pay_later_tab_id = Settings::PAY_LATER_TAB_ID;
|
||||
|
||||
$list_of_config = array();
|
||||
$task_config_services = $container->get( 'wcgateway.settings.wc-tasks.task-config-services' );
|
||||
|
||||
if ( $container->has( 'paylater-configurator.is-available' ) && $container->get( 'paylater-configurator.is-available' ) ) {
|
||||
$list_of_config[] = array(
|
||||
'id' => 'pay-later-messaging-task',
|
||||
'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ),
|
||||
'redirect_url' => admin_url( "admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}" ),
|
||||
);
|
||||
foreach ( $task_config_services as $service_id ) {
|
||||
if ( $container->has( $service_id ) ) {
|
||||
$task_config = $container->get( $service_id );
|
||||
$list_of_config = array_merge( $list_of_config, $task_config );
|
||||
}
|
||||
}
|
||||
|
||||
return $list_of_config;
|
||||
|
|
|
@ -69,7 +69,7 @@ class ConnectAdminNotice {
|
|||
$message = sprintf(
|
||||
/* translators: %1$s the gateway name. */
|
||||
__(
|
||||
'PayPal Payments is almost ready. To get started, connect your account with the <b>Activate PayPal</b> button <a href="%1$s">on the Account Setup page</a>.',
|
||||
'PayPal Payments is almost ready. To get started, connect your account with the <b>Activate PayPal Payments</b> button <a href="%1$s">on the Account Setup page</a>.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=' . Settings::CONNECTION_TAB_ID )
|
||||
|
@ -77,6 +77,16 @@ class ConnectAdminNotice {
|
|||
return new Message( $message, 'warning' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current page is plugins.php.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_current_page_plugins_page(): bool {
|
||||
global $pagenow;
|
||||
return isset( $pagenow ) && $pagenow === 'plugins.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the message should display.
|
||||
*
|
||||
|
@ -87,6 +97,8 @@ class ConnectAdminNotice {
|
|||
* @return bool
|
||||
*/
|
||||
protected function should_display(): bool {
|
||||
return ! $this->is_connected && ! $this->is_current_country_send_only;
|
||||
return $this->is_current_page_plugins_page()
|
||||
&& ! $this->is_connected
|
||||
&& ! $this->is_current_country_send_only;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue