diff --git a/includes/class-wc-gateway-amazon-payments-advanced-abstract.php b/includes/class-wc-gateway-amazon-payments-advanced-abstract.php index eb91364b..3321355e 100644 --- a/includes/class-wc-gateway-amazon-payments-advanced-abstract.php +++ b/includes/class-wc-gateway-amazon-payments-advanced-abstract.php @@ -123,7 +123,6 @@ public function __construct() { $this->method_description = __( 'Amazon Pay is embedded directly into your existing web site, and all the buyer interactions with Amazon Pay and Login with Amazon take place in embedded widgets so that the buyer never leaves your site. Buyers can log in using their Amazon account, select a shipping address and payment method, and then confirm their order. Requires an Amazon Pay seller account and supports USA, UK, Germany, France, Italy, Spain, Luxembourg, the Netherlands, Sweden, Portugal, Hungary, Denmark, and Japan.', 'woocommerce-gateway-amazon-payments-advanced' ); $this->id = 'amazon_payments_advanced'; $this->icon = apply_filters( 'woocommerce_amazon_pa_logo', wc_apa()->plugin_url . '/assets/images/amazon-payments.png' ); - $this->debug = ( 'yes' === $this->get_option( 'debug' ) ); $this->view_transaction_url = $this->get_transaction_url_format(); $this->supports = array( 'products', @@ -132,17 +131,27 @@ public function __construct() { $this->supports = apply_filters( 'woocommerce_amazon_pa_supports', $this->supports, $this ); $this->private_key = get_option( WC_Amazon_Payments_Advanced_Merchant_Onboarding_Handler::KEYS_OPTION_PRIVATE_KEY ); + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'validate_api_keys' ) ); + + add_action( 'woocommerce_amazon_checkout_init', array( $this, 'checkout_init_common' ) ); + + } + + /** + * Gateway Settings Init + * + * @since 2.3.4 + */ + public function gateway_settings_init() { // Load the settings. $this->init_settings(); // Load saved settings. $this->load_settings(); - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'validate_api_keys' ) ); - - add_action( 'woocommerce_amazon_checkout_init', array( $this, 'checkout_init_common' ) ); - + // Set Debug option. + $this->debug = ( 'yes' === $this->get_option( 'debug' ) ); } /** @@ -487,7 +496,7 @@ public function get_form_fields() { $this->form_fields = apply_filters( 'woocommerce_amazon_pa_form_fields_before_legacy', $this->form_fields ); - if ( $this->has_v1_settings() ) { + if ( $this->has_v1_settings() && ! WC_Amazon_Payments_Advanced_Merchant_Onboarding_Handler::get_migration_status() ) { $this->form_fields = array_merge( $this->form_fields, array( diff --git a/includes/class-wc-gateway-amazon-payments-advanced.php b/includes/class-wc-gateway-amazon-payments-advanced.php index 36519638..be0db512 100644 --- a/includes/class-wc-gateway-amazon-payments-advanced.php +++ b/includes/class-wc-gateway-amazon-payments-advanced.php @@ -1328,7 +1328,8 @@ public function handle_return() { $charge_permission_id = $response->chargePermissionId; // phpcs:ignore WordPress.NamingConventions $order->update_meta_data( 'amazon_charge_permission_id', $charge_permission_id ); - $order->set_transaction_id( $charge_permission_id ); + + $this->maybe_set_transaction_id( $order, $charge_permission_id, $response->chargeId ); $order->save(); $this->log_charge_permission_status_change( $order ); @@ -1414,6 +1415,7 @@ public function log_charge_status_change( $order, $charge = null ) { } $this->refresh_cached_charge_status( $order, $charge ); $order->update_meta_data( 'amazon_charge_id', $charge_id ); + $this->maybe_set_transaction_id( $order, '', $charge_id ); $order->save(); // Save early for less race conditions. // @codingStandardsIgnoreStart @@ -1507,7 +1509,6 @@ public function log_charge_permission_status_change( $order, $charge_permission } $this->refresh_cached_charge_permission_status( $order, $charge_permission ); $order->update_meta_data( 'amazon_charge_permission_id', $charge_permission_id ); // phpcs:ignore WordPress.NamingConventions - $order->set_transaction_id( $charge_permission_id ); $order->save(); // Save early for less race conditions. @@ -2307,11 +2308,11 @@ public function filter_customer_field( $value ) { * Maybe hide standard WC checkout button on the cart, if enabled */ public function maybe_hide_standard_checkout_button() { - if ( ! $this->is_available() ) { + if ( ! $this->is_available() || $this->has_other_gateways_enabled() ) { return; } - if ( 'yes' !== $this->settings['hide_standard_checkout_button'] || $this->has_other_gateways_enabled() ) { + if ( 'yes' !== $this->settings['hide_standard_checkout_button'] ) { return; } @@ -2329,4 +2330,19 @@ public function maybe_hide_standard_checkout_button() { set_transaction_id( $charge_permission_id ); + } + } } diff --git a/woocommerce-gateway-amazon-payments-advanced.php b/woocommerce-gateway-amazon-payments-advanced.php index 3f8a9814..fe2598e0 100644 --- a/woocommerce-gateway-amazon-payments-advanced.php +++ b/woocommerce-gateway-amazon-payments-advanced.php @@ -224,6 +224,8 @@ public function init_gateway() { } + add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); + include_once $this->includes_path . 'legacy/class-wc-gateway-amazon-payments-advanced-legacy.php'; if ( WC_Amazon_Payments_Advanced_Merchant_Onboarding_Handler::get_migration_status() ) { include_once $this->includes_path . 'class-wc-gateway-amazon-payments-advanced.php'; @@ -232,8 +234,7 @@ public function init_gateway() { } else { $this->gateway = new WC_Gateway_Amazon_Payments_Advanced_Legacy(); } - - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); + $this->gateway->gateway_settings_init(); } /**