mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge branch 'trunk' into PCP-4120-add-payment-method-modal-data-to-data-store
This commit is contained in:
commit
55a0dd4824
24 changed files with 346 additions and 181 deletions
|
@ -87,6 +87,8 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
$this->initialize_wc_bookings_compat_layer( $c );
|
||||
}
|
||||
|
||||
add_action( 'woocommerce_paypal_payments_gateway_migrate', static fn() => delete_transient( 'ppcp_has_ppec_subscriptions' ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,10 +75,10 @@ class PPECHelper {
|
|||
}
|
||||
|
||||
global $wpdb;
|
||||
if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() && isset( $wpdb->wc_orders ) ) {
|
||||
if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
||||
$result = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT 1 FROM {$wpdb->wc_orders} WHERE payment_method = %s",
|
||||
"SELECT 1 FROM {$wpdb->prefix}wc_orders WHERE payment_method = %s",
|
||||
self::PPEC_GATEWAY_ID
|
||||
)
|
||||
);
|
||||
|
|
|
@ -49,6 +49,8 @@ class RenewalHandler {
|
|||
public function process( array $subscriptions, string $transaction_id ): void {
|
||||
foreach ( $subscriptions as $subscription ) {
|
||||
if ( $this->is_for_renewal_order( $subscription ) ) {
|
||||
$subscription->update_status( 'on-hold' );
|
||||
|
||||
$renewal_order = wcs_create_renewal_order( $subscription );
|
||||
if ( is_a( $renewal_order, WC_Order::class ) ) {
|
||||
$this->logger->info(
|
||||
|
|
|
@ -20,75 +20,56 @@ return array(
|
|||
$save_payment_methods_applies = $container->get( 'save-payment-methods.helpers.save-payment-methods-applies' );
|
||||
assert( $save_payment_methods_applies instanceof SavePaymentMethodsApplies );
|
||||
|
||||
return $save_payment_methods_applies->for_country_currency();
|
||||
return $save_payment_methods_applies->for_country();
|
||||
},
|
||||
'save-payment-methods.helpers.save-payment-methods-applies' => static function ( ContainerInterface $container ) : SavePaymentMethodsApplies {
|
||||
return new SavePaymentMethodsApplies(
|
||||
$container->get( 'save-payment-methods.supported-country-currency-matrix' ),
|
||||
$container->get( 'api.shop.currency.getter' ),
|
||||
$container->get( 'save-payment-methods.supported-countries' ),
|
||||
$container->get( 'api.shop.country' )
|
||||
);
|
||||
},
|
||||
'save-payment-methods.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
|
||||
$default_currencies = array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
);
|
||||
'save-payment-methods.supported-countries' => static function ( ContainerInterface $container ) : array {
|
||||
if ( has_filter( 'woocommerce_paypal_payments_save_payment_methods_supported_country_currency_matrix' ) ) {
|
||||
_deprecated_hook( 'woocommerce_paypal_payments_save_payment_methods_supported_country_currency_matrix', '3.0.0', 'woocommerce_paypal_payments_save_payment_methods_supported_countries', esc_attr__( 'Please use the new Hook to filter countries for saved payments in PayPal Payments.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_save_payment_methods_supported_country_currency_matrix',
|
||||
'woocommerce_paypal_payments_save_payment_methods_supported_countries',
|
||||
array(
|
||||
'AU' => $default_currencies,
|
||||
'AT' => $default_currencies,
|
||||
'BE' => $default_currencies,
|
||||
'BG' => $default_currencies,
|
||||
'CA' => $default_currencies,
|
||||
'CN' => $default_currencies,
|
||||
'CY' => $default_currencies,
|
||||
'CZ' => $default_currencies,
|
||||
'DK' => $default_currencies,
|
||||
'EE' => $default_currencies,
|
||||
'FI' => $default_currencies,
|
||||
'FR' => $default_currencies,
|
||||
'DE' => $default_currencies,
|
||||
'GR' => $default_currencies,
|
||||
'HU' => $default_currencies,
|
||||
'IE' => $default_currencies,
|
||||
'IT' => $default_currencies,
|
||||
'LV' => $default_currencies,
|
||||
'LI' => $default_currencies,
|
||||
'LT' => $default_currencies,
|
||||
'LU' => $default_currencies,
|
||||
'MT' => $default_currencies,
|
||||
'NO' => $default_currencies,
|
||||
'NL' => $default_currencies,
|
||||
'PL' => $default_currencies,
|
||||
'PT' => $default_currencies,
|
||||
'RO' => $default_currencies,
|
||||
'SK' => $default_currencies,
|
||||
'SI' => $default_currencies,
|
||||
'ES' => $default_currencies,
|
||||
'SE' => $default_currencies,
|
||||
'GB' => $default_currencies,
|
||||
'US' => $default_currencies,
|
||||
'AU',
|
||||
'AT',
|
||||
'BE',
|
||||
'BG',
|
||||
'CA',
|
||||
'CN',
|
||||
'CY',
|
||||
'CZ',
|
||||
'DK',
|
||||
'EE',
|
||||
'FI',
|
||||
'FR',
|
||||
'DE',
|
||||
'HK',
|
||||
'HU',
|
||||
'IE',
|
||||
'IT',
|
||||
'LV',
|
||||
'LI',
|
||||
'LT',
|
||||
'LU',
|
||||
'MT',
|
||||
'NO',
|
||||
'NL',
|
||||
'PL',
|
||||
'PT',
|
||||
'RO',
|
||||
'SG',
|
||||
'SK',
|
||||
'SI',
|
||||
'ES',
|
||||
'SE',
|
||||
'GB',
|
||||
'US',
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -9,49 +9,37 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\SavePaymentMethods\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter;
|
||||
|
||||
/**
|
||||
* Class SavePaymentMethodsApplies
|
||||
*/
|
||||
class SavePaymentMethodsApplies {
|
||||
|
||||
/**
|
||||
* The matrix which countries and currency combinations can be used for Save Payment Methods.
|
||||
* The countries can be used for Save Payment Methods.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowed_country_currency_matrix;
|
||||
|
||||
/**
|
||||
* The getter of the 3-letter currency code of the shop.
|
||||
*
|
||||
* @var CurrencyGetter
|
||||
*/
|
||||
private CurrencyGetter $currency;
|
||||
private array $allowed_countries;
|
||||
|
||||
/**
|
||||
* 2-letter country code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $country;
|
||||
private string $country;
|
||||
|
||||
/**
|
||||
* SavePaymentMethodsApplies constructor.
|
||||
*
|
||||
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used for Save Payment Methods.
|
||||
* @param CurrencyGetter $currency The getter of the 3-letter currency code of the shop.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
* @param array $allowed_countries The matrix which countries and currency combinations can be used for Save Payment Methods.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
*/
|
||||
public function __construct(
|
||||
array $allowed_country_currency_matrix,
|
||||
CurrencyGetter $currency,
|
||||
array $allowed_countries,
|
||||
string $country
|
||||
) {
|
||||
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
|
||||
$this->currency = $currency;
|
||||
$this->country = $country;
|
||||
$this->allowed_countries = $allowed_countries;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,10 +47,8 @@ class SavePaymentMethodsApplies {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function for_country_currency(): bool {
|
||||
if ( ! in_array( $this->country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
return in_array( $this->currency->get(), $this->allowed_country_currency_matrix[ $this->country ], true );
|
||||
public function for_country(): bool {
|
||||
|
||||
return in_array( $this->country, $this->allowed_countries, true );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
border: 1px solid var(--color-separators);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
font-family: "PayPalPro", sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
|
||||
.css-1snxoyf.eolpigi0 {
|
||||
margin: 0;
|
||||
|
@ -46,30 +48,25 @@
|
|||
}
|
||||
|
||||
&__subheader, #configurator-controlPanelSubHeader {
|
||||
@include font(13, 20, 400);
|
||||
color: $color-gray-800;
|
||||
color: var(--color-text-description);
|
||||
margin: 0 0 18px 0;
|
||||
}
|
||||
|
||||
.css-1caaugt-links_base-text_body_strong, .css-dpyjrq-text_body {
|
||||
@include font(13, 20, 400);
|
||||
}
|
||||
|
||||
&__header, #configurator-controlPanelHeader, #configurator-previewSectionSubHeaderText.css-14ujlqd-text_body, .css-16jt5za-text_body {
|
||||
@include font(14, 20, 600);
|
||||
color: $color-gray-800;
|
||||
margin: 0 0 8px 0;
|
||||
display: block;
|
||||
@include font(16, 20, 600);
|
||||
color: var(--color-text-title);
|
||||
margin-bottom: 6px;
|
||||
font-family: "PayPalPro", sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.css-1yo2lxy-text_body_strong {
|
||||
@include font(13, 16, 600);
|
||||
color: $color-black;
|
||||
color: var(--color-text-description);
|
||||
margin: 0;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.css-rok10q {
|
||||
.css-rok10q, .css-dfgbdq-text_body_strong {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
|
@ -77,13 +74,40 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
.css-1oxdnb3-dropdown_menu_button-text_field_value_sm-active, .css-1wvwydd-dropdown_menu_button-text_field_value_sm-active-active, .css-16jt5za-text_body {
|
||||
font-size: 13px;
|
||||
line-height: 1.5384615385;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.css-udzaps {
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.css-104jwuk,
|
||||
.css-dpyjrq-text_body,
|
||||
.css-1oxdnb3-dropdown_menu_button-text_field_value_sm-active,
|
||||
.css-1wvwydd-dropdown_menu_button-text_field_value_sm-active-active,
|
||||
.css-16jt5za-text_body,
|
||||
.css-1caaugt-links_base-text_body_strong,
|
||||
.css-dpyjrq-text_body,
|
||||
&__subheader,
|
||||
#configurator-controlPanelSubHeader,
|
||||
.css-1yo2lxy-text_body_strong{
|
||||
@include font(13, 20, 400);
|
||||
font-family: "PayPalPro", sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.css-1k9r7mv-text_body, .css-ra9ecy-text_body_strong {
|
||||
font-family: "PayPalPro", sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.css-1hs85tj {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.css-4nclxm.e1vy3g880, {
|
||||
width: 100%;
|
||||
padding: 48px 8px;
|
||||
|
||||
.css-11hsg2u.e1vy3g880 {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,31 @@ const SelectBox = ( props ) => {
|
|||
boxClassName += ' selected';
|
||||
}
|
||||
|
||||
const handleClick = () => {
|
||||
if ( props.type === 'checkbox' ) {
|
||||
let newValue;
|
||||
|
||||
if ( Array.isArray( props.currentValue ) ) {
|
||||
if ( props.currentValue.includes( props.value ) ) {
|
||||
newValue = props.currentValue.filter(
|
||||
( optionValue ) => optionValue !== props.value
|
||||
);
|
||||
} else {
|
||||
newValue = [ ...props.currentValue, props.value ];
|
||||
}
|
||||
} else {
|
||||
newValue = ! props.currentValue;
|
||||
}
|
||||
|
||||
props.changeCallback( newValue );
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={ boxClassName }>
|
||||
<div
|
||||
className={ boxClassName }
|
||||
onClick={ props.type === 'checkbox' ? handleClick : undefined }
|
||||
>
|
||||
{ props.type === 'radio' && (
|
||||
<PayPalRdb
|
||||
{ ...{
|
||||
|
@ -22,11 +45,7 @@ const SelectBox = ( props ) => {
|
|||
} }
|
||||
/>
|
||||
) }
|
||||
{ props.type === 'checkbox' && (
|
||||
<PayPalCheckbox
|
||||
{ ...props }
|
||||
/>
|
||||
) }
|
||||
{ props.type === 'checkbox' && <PayPalCheckbox { ...props } /> }
|
||||
<div className="ppcp-r-select-box__content">
|
||||
<div className="ppcp-r-select-box__content-inner">
|
||||
<span className="ppcp-r-select-box__title">
|
||||
|
|
|
@ -36,7 +36,8 @@ const ALL_STEPS = [
|
|||
id: 'methods',
|
||||
title: __( 'Choose checkout options', 'woocommerce-paypal-payments' ),
|
||||
StepComponent: StepPaymentMethods,
|
||||
canProceed: () => true,
|
||||
canProceed: ( { methods } ) =>
|
||||
methods.areOptionalPaymentMethodsEnabled !== null,
|
||||
},
|
||||
{
|
||||
id: 'complete',
|
||||
|
|
|
@ -136,10 +136,12 @@ export const useSteps = () => {
|
|||
export const useNavigationState = () => {
|
||||
const products = useProducts();
|
||||
const business = useBusiness();
|
||||
const methods = useOptionalPaymentMethods();
|
||||
|
||||
return {
|
||||
products,
|
||||
business,
|
||||
methods,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -218,6 +218,8 @@ return array(
|
|||
return new SwitchSettingsUiEndpoint(
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'button.request-data' ),
|
||||
$container->get( 'settings.data.onboarding' ),
|
||||
$container->get( 'api.merchant_id' ) !== ''
|
||||
);
|
||||
},
|
||||
'settings.rest.settings' => static function( ContainerInterface $container ): SettingsRestEndpoint {
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Settings\Ajax;
|
|||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
|
||||
|
||||
/**
|
||||
* Class SwitchSettingsUiEndpoint
|
||||
|
@ -37,18 +38,38 @@ class SwitchSettingsUiEndpoint {
|
|||
*/
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* The Onboarding profile.
|
||||
*
|
||||
* @var OnboardingProfile
|
||||
*/
|
||||
protected OnboardingProfile $onboarding_profile;
|
||||
|
||||
/**
|
||||
* True if the merchant is onboarded, otherwise false.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $is_onboarded;
|
||||
|
||||
/**
|
||||
* SwitchSettingsUiEndpoint constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param RequestData $request_data The Request data.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param RequestData $request_data The Request data.
|
||||
* @param OnboardingProfile $onboarding_profile The Onboarding profile.
|
||||
* @param bool $is_onboarded True if the merchant is onboarded, otherwise false.
|
||||
*/
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
RequestData $request_data
|
||||
RequestData $request_data,
|
||||
OnboardingProfile $onboarding_profile,
|
||||
bool $is_onboarded
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->request_data = $request_data;
|
||||
$this->logger = $logger;
|
||||
$this->request_data = $request_data;
|
||||
$this->onboarding_profile = $onboarding_profile;
|
||||
$this->is_onboarded = $is_onboarded;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +83,12 @@ class SwitchSettingsUiEndpoint {
|
|||
|
||||
try {
|
||||
$this->request_data->read_request( $this->nonce() );
|
||||
update_option( self::OPTION_NAME_SHOULD_USE_OLD_UI, false );
|
||||
update_option( self::OPTION_NAME_SHOULD_USE_OLD_UI, 'no' );
|
||||
|
||||
if ( $this->is_onboarded ) {
|
||||
$this->onboarding_profile->set_completed( true );
|
||||
$this->onboarding_profile->save();
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
} catch ( Exception $error ) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
public static function should_use_the_old_ui() : bool {
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_should_use_the_old_ui',
|
||||
(bool) get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI ) === true
|
||||
get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI ) === 'yes'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,12 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
return true;
|
||||
}
|
||||
|
||||
add_action(
|
||||
'woocommerce_paypal_payments_gateway_migrate_on_update',
|
||||
static fn () => ! get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI )
|
||||
&& update_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI, 'yes' )
|
||||
);
|
||||
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,8 @@ use Psr\Log\LoggerInterface;
|
|||
use RuntimeException;
|
||||
use WC_Payment_Token;
|
||||
use WC_Payment_Tokens;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
|
@ -26,9 +28,18 @@ use WP_User_Query;
|
|||
|
||||
/**
|
||||
* Class StatusReportModule
|
||||
*
|
||||
* @psalm-suppress MissingConstructor
|
||||
*/
|
||||
class VaultingModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
||||
use ModuleClassNameIdTrait;
|
||||
use ModuleClassNameIdTrait, ContextTrait;
|
||||
|
||||
/**
|
||||
* Session Handler
|
||||
*
|
||||
* @var SessionHandler
|
||||
*/
|
||||
protected SessionHandler $session_handler;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -103,6 +114,7 @@ class VaultingModule implements ServiceModule, ExtendingModule, ExecutableModule
|
|||
}
|
||||
);
|
||||
|
||||
$this->session_handler = $container->get( 'session.handler' );
|
||||
add_filter(
|
||||
'woocommerce_get_customer_payment_tokens',
|
||||
/**
|
||||
|
@ -124,12 +136,18 @@ class VaultingModule implements ServiceModule, ExtendingModule, ExecutableModule
|
|||
&& ! $is_post // Don't check on POST so we have all payment methods on form submissions.
|
||||
) {
|
||||
foreach ( $tokens as $index => $token ) {
|
||||
if ( $token instanceof PaymentTokenApplePay ) {
|
||||
if ( $token instanceof PaymentTokenApplePay || $token instanceof PaymentTokenPayPal || $token instanceof PaymentTokenVenmo ) {
|
||||
unset( $tokens[ $index ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_checkout() && ! $is_post && $this->is_paypal_continuation() ) {
|
||||
foreach ( $tokens as $index => $token ) {
|
||||
unset( $tokens[ $index ] );
|
||||
}
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
},
|
||||
10,
|
||||
|
|
|
@ -362,4 +362,19 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
protected function settings_renderer(): SettingsRenderer {
|
||||
return $this->settings_renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the Gateway is available for use.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_available(): bool {
|
||||
$is_available = parent::is_available();
|
||||
|
||||
if ( $is_available && $this->is_free_trial_cart() ) {
|
||||
$is_available = false;
|
||||
}
|
||||
|
||||
return $is_available;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -444,28 +444,27 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $this->is_customer_changing_subscription_payment( $this->subscription_helper, $wc_order ) ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$wc_payment_token_id = wc_clean( wp_unslash( $_POST['wc-ppcp-credit-card-gateway-payment-token'] ?? '' ) );
|
||||
if ( ! $wc_payment_token_id ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$wc_payment_token_id = wc_clean( wp_unslash( $_POST['saved_credit_card'] ?? '' ) );
|
||||
}
|
||||
|
||||
if ( $wc_payment_token_id ) {
|
||||
return $this->add_payment_token_to_order( $wc_order, (int) $wc_payment_token_id, $this->get_return_url( $wc_order ), $this->session_handler );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vault v3 (save payment methods).
|
||||
* If customer has chosen a saved credit card payment from checkout page.
|
||||
*/
|
||||
if ( $card_payment_token_id ) {
|
||||
$customer_tokens = $this->wc_payment_tokens->customer_tokens( get_current_user_id() );
|
||||
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), self::ID );
|
||||
|
||||
if ( $customer_tokens && empty( $wc_tokens ) ) {
|
||||
$this->wc_payment_tokens->create_wc_tokens( $customer_tokens, get_current_user_id() );
|
||||
}
|
||||
|
||||
$customer_token_ids = array();
|
||||
foreach ( $customer_tokens as $customer_token ) {
|
||||
$customer_token_ids[] = $customer_token['id'];
|
||||
}
|
||||
|
||||
$tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id() );
|
||||
foreach ( $tokens as $token ) {
|
||||
if ( $token->get_id() === (int) $card_payment_token_id ) {
|
||||
if ( ! in_array( $token->get_token(), $customer_token_ids, true ) ) {
|
||||
$token->delete();
|
||||
continue;
|
||||
}
|
||||
|
||||
$custom_id = (string) $wc_order->get_id();
|
||||
$invoice_id = $this->prefix . $wc_order->get_order_number();
|
||||
$create_order = $this->capture_card_payment->create_order( $token->get_token(), $custom_id, $invoice_id, $wc_order );
|
||||
|
@ -514,40 +513,6 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If customer is changing subscription payment.
|
||||
*/
|
||||
if (
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
isset( $_POST['woocommerce_change_payment'] )
|
||||
&& $this->subscription_helper->has_subscription( $wc_order->get_id() )
|
||||
&& $this->subscription_helper->is_subscription_change_payment()
|
||||
) {
|
||||
$saved_credit_card = wc_clean( wp_unslash( $_POST['wc-ppcp-credit-card-gateway-payment-token'] ?? '' ) );
|
||||
if ( ! $saved_credit_card ) {
|
||||
$saved_credit_card = wc_clean( wp_unslash( $_POST['saved_credit_card'] ?? '' ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
}
|
||||
|
||||
if ( $saved_credit_card ) {
|
||||
$payment_token = WC_Payment_Tokens::get( $saved_credit_card );
|
||||
if ( $payment_token ) {
|
||||
$wc_order->add_payment_token( $payment_token );
|
||||
$wc_order->save();
|
||||
|
||||
return $this->handle_payment_success( $wc_order );
|
||||
}
|
||||
}
|
||||
|
||||
wc_add_notice( __( 'Could not change payment.', 'woocommerce-paypal-payments' ), 'error' );
|
||||
|
||||
return array(
|
||||
'result' => 'failure',
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'errorMessage' => __( 'Could not change payment.', 'woocommerce-paypal-payments' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the WC_Order is paid through the approved webhook.
|
||||
*/
|
||||
|
@ -676,4 +641,53 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
protected function settings_renderer(): SettingsRenderer {
|
||||
return $this->settings_renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether customer is changing subscription payment.
|
||||
*
|
||||
* @param SubscriptionHelper $subscription_helper Subscription helper.
|
||||
* @param WC_Order $wc_order WC order.
|
||||
* @return bool
|
||||
*/
|
||||
private function is_customer_changing_subscription_payment( SubscriptionHelper $subscription_helper, WC_Order $wc_order ): bool {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
return isset( $_POST['woocommerce_change_payment'] ) && $subscription_helper->has_subscription( $wc_order->get_id() ) && $subscription_helper->is_subscription_change_payment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given WC payment token into the given WC Order.
|
||||
*
|
||||
* @param WC_Order $wc_order WC order.
|
||||
* @param int $wc_payment_token_id WC payment token ID.
|
||||
* @param string $return_url Return url.
|
||||
* @param SessionHandler $session_handler Session handler.
|
||||
* @return array{result: string, redirect: string, errorMessage?: string}
|
||||
*/
|
||||
private function add_payment_token_to_order(
|
||||
WC_Order $wc_order,
|
||||
int $wc_payment_token_id,
|
||||
string $return_url,
|
||||
SessionHandler $session_handler
|
||||
): array {
|
||||
$payment_token = WC_Payment_Tokens::get( $wc_payment_token_id );
|
||||
if ( $payment_token ) {
|
||||
$wc_order->add_payment_token( $payment_token );
|
||||
$wc_order->save();
|
||||
|
||||
$session_handler->destroy_session_data();
|
||||
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => $return_url,
|
||||
);
|
||||
}
|
||||
|
||||
wc_add_notice( __( 'Could not change payment.', 'woocommerce-paypal-payments' ), 'error' );
|
||||
|
||||
return array(
|
||||
'result' => 'failure',
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'errorMessage' => __( 'Could not change payment.', 'woocommerce-paypal-payments' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ use WC_Subscriptions;
|
|||
use WC_Subscriptions_Product;
|
||||
use WCS_Manual_Renewal_Manager;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
/**
|
||||
* Class SubscriptionHelper
|
||||
|
@ -301,7 +303,11 @@ class SubscriptionHelper {
|
|||
|
||||
foreach ( $orders as $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( is_a( $order, WC_Order::class ) && in_array( $order->get_status(), array( 'processing', 'completed' ), true ) ) {
|
||||
if (
|
||||
is_a( $order, WC_Order::class )
|
||||
&& in_array( $order->get_status(), array( 'processing', 'completed' ), true )
|
||||
&& in_array( $order->get_payment_method(), array( PayPalGateway::ID, CreditCardGateway::ID ), true )
|
||||
) {
|
||||
$transaction_id = $order->get_transaction_id();
|
||||
if ( $transaction_id ) {
|
||||
return $transaction_id;
|
||||
|
|
|
@ -257,7 +257,8 @@ class RenewalHandler {
|
|||
|
||||
// Vault v3.
|
||||
$payment_source = null;
|
||||
if ( $wc_order->get_payment_method() === PayPalGateway::ID ) {
|
||||
$payment_method = $wc_order->get_payment_method();
|
||||
if ( $payment_method === PayPalGateway::ID ) {
|
||||
$customer_tokens = $this->wc_payment_tokens->customer_tokens( $user_id );
|
||||
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, PayPalGateway::ID );
|
||||
|
@ -309,7 +310,7 @@ class RenewalHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $wc_order->get_payment_method() === CreditCardGateway::ID ) {
|
||||
if ( $payment_method === CreditCardGateway::ID ) {
|
||||
$customer_tokens = $this->wc_payment_tokens->customer_tokens( $user_id );
|
||||
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, CreditCardGateway::ID );
|
||||
|
@ -352,7 +353,7 @@ class RenewalHandler {
|
|||
|
||||
$this->handle_paypal_order( $wc_order, $order );
|
||||
|
||||
if ( $wc_order->get_payment_method() === CreditCardGateway::ID ) {
|
||||
if ( $payment_method === CreditCardGateway::ID ) {
|
||||
$card_payment_source = $order->payment_source();
|
||||
if ( $card_payment_source ) {
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, CreditCardGateway::ID );
|
||||
|
@ -379,7 +380,7 @@ class RenewalHandler {
|
|||
// Vault v2.
|
||||
$token = $this->get_token_for_customer( $customer, $wc_order );
|
||||
if ( $token ) {
|
||||
if ( $wc_order->get_payment_method() === CreditCardGateway::ID ) {
|
||||
if ( $payment_method === CreditCardGateway::ID ) {
|
||||
$payment_source = $this->card_payment_source( $token->id(), $wc_order );
|
||||
|
||||
$order = $this->order_endpoint->create(
|
||||
|
@ -406,7 +407,7 @@ class RenewalHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( $wc_order->get_payment_method() === PayPalGateway::ID ) {
|
||||
if ( $payment_method === PayPalGateway::ID || $payment_method === 'ppec_paypal' ) {
|
||||
$order = $this->order_endpoint->create(
|
||||
array( $purchase_unit ),
|
||||
$shipping_preference,
|
||||
|
|
|
@ -14,6 +14,7 @@ use WC_Order;
|
|||
use WC_Payment_Token_CC;
|
||||
use WC_Payment_Tokens;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue