Skip to content

Commit 61ccbab

Browse files
Bug Fixing (#135)
* Check if other gateways is enabled before hide checkout button issue #97 * Enable subscription amount change support Issue #106 * Accept states without letters mark variations on shipping restriction - Issue #122 * Render cart button on update shipping method * Unify version checker * Get order charge permission and charge id method * Force v2 version on orders * Remove duplicated assignation * Add charge id for the orders with open capture * Parse V1 ipn response to process it with V2 handler * Skip v1 IPN handler on migration done * Lowercase version on parsed IPN notification * Change string replace function and save order * Log notification Data for the V1 IPN * Fix typos * PHPCS issues * PHPCS manual fixes * PHPCS fixes * Fix function call. * Undo version change * Replace gateways object to avoid error on settings * Set Order Transaction Id (Saucal Issue #125) * Force Decimals to 2 on amounts sent to API * Hide API V1 settings after onboarding is made * Check other gateways existence early * Delay Init settings to ensure gateway addition * Add correct transaction Id to subscription and renewals orders Co-authored-by: Matias Saggiorato <saggiorato@saucal.com> Co-authored-by: Matias Saggiorato <matiassaggiorato@gmail.com>
1 parent 5329c78 commit 61ccbab

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

includes/class-wc-gateway-amazon-payments-advanced-abstract.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ public function __construct() {
123123
$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' );
124124
$this->id = 'amazon_payments_advanced';
125125
$this->icon = apply_filters( 'woocommerce_amazon_pa_logo', wc_apa()->plugin_url . '/assets/images/amazon-payments.png' );
126-
$this->debug = ( 'yes' === $this->get_option( 'debug' ) );
127126
$this->view_transaction_url = $this->get_transaction_url_format();
128127
$this->supports = array(
129128
'products',
@@ -132,17 +131,27 @@ public function __construct() {
132131
$this->supports = apply_filters( 'woocommerce_amazon_pa_supports', $this->supports, $this );
133132
$this->private_key = get_option( WC_Amazon_Payments_Advanced_Merchant_Onboarding_Handler::KEYS_OPTION_PRIVATE_KEY );
134133

134+
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
135+
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'validate_api_keys' ) );
136+
137+
add_action( 'woocommerce_amazon_checkout_init', array( $this, 'checkout_init_common' ) );
138+
139+
}
140+
141+
/**
142+
* Gateway Settings Init
143+
*
144+
* @since 2.3.4
145+
*/
146+
public function gateway_settings_init() {
135147
// Load the settings.
136148
$this->init_settings();
137149

138150
// Load saved settings.
139151
$this->load_settings();
140152

141-
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
142-
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'validate_api_keys' ) );
143-
144-
add_action( 'woocommerce_amazon_checkout_init', array( $this, 'checkout_init_common' ) );
145-
153+
// Set Debug option.
154+
$this->debug = ( 'yes' === $this->get_option( 'debug' ) );
146155
}
147156

148157
/**
@@ -487,7 +496,7 @@ public function get_form_fields() {
487496

488497
$this->form_fields = apply_filters( 'woocommerce_amazon_pa_form_fields_before_legacy', $this->form_fields );
489498

490-
if ( $this->has_v1_settings() ) {
499+
if ( $this->has_v1_settings() && ! WC_Amazon_Payments_Advanced_Merchant_Onboarding_Handler::get_migration_status() ) {
491500
$this->form_fields = array_merge(
492501
$this->form_fields,
493502
array(

includes/class-wc-gateway-amazon-payments-advanced.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,8 @@ public function handle_return() {
13281328

13291329
$charge_permission_id = $response->chargePermissionId; // phpcs:ignore WordPress.NamingConventions
13301330
$order->update_meta_data( 'amazon_charge_permission_id', $charge_permission_id );
1331-
$order->set_transaction_id( $charge_permission_id );
1331+
1332+
$this->maybe_set_transaction_id( $order, $charge_permission_id, $response->chargeId );
13321333

13331334
$order->save();
13341335
$this->log_charge_permission_status_change( $order );
@@ -1414,6 +1415,7 @@ public function log_charge_status_change( $order, $charge = null ) {
14141415
}
14151416
$this->refresh_cached_charge_status( $order, $charge );
14161417
$order->update_meta_data( 'amazon_charge_id', $charge_id );
1418+
$this->maybe_set_transaction_id( $order, '', $charge_id );
14171419
$order->save(); // Save early for less race conditions.
14181420

14191421
// @codingStandardsIgnoreStart
@@ -1507,7 +1509,6 @@ public function log_charge_permission_status_change( $order, $charge_permission
15071509
}
15081510
$this->refresh_cached_charge_permission_status( $order, $charge_permission );
15091511
$order->update_meta_data( 'amazon_charge_permission_id', $charge_permission_id ); // phpcs:ignore WordPress.NamingConventions
1510-
$order->set_transaction_id( $charge_permission_id );
15111512

15121513
$order->save(); // Save early for less race conditions.
15131514

@@ -2307,11 +2308,11 @@ public function filter_customer_field( $value ) {
23072308
* Maybe hide standard WC checkout button on the cart, if enabled
23082309
*/
23092310
public function maybe_hide_standard_checkout_button() {
2310-
if ( ! $this->is_available() ) {
2311+
if ( ! $this->is_available() || $this->has_other_gateways_enabled() ) {
23112312
return;
23122313
}
23132314

2314-
if ( 'yes' !== $this->settings['hide_standard_checkout_button'] || $this->has_other_gateways_enabled() ) {
2315+
if ( 'yes' !== $this->settings['hide_standard_checkout_button'] ) {
23152316
return;
23162317
}
23172318

@@ -2329,4 +2330,19 @@ public function maybe_hide_standard_checkout_button() {
23292330
<?php
23302331
}
23312332

2333+
/**
2334+
* Maybe set order transaction id.
2335+
*
2336+
* @param WC_Order $order Order object.
2337+
* @param string $charge_permission_id Charge Permission.
2338+
* @param string $charge_id Charge Id.
2339+
*/
2340+
public function maybe_set_transaction_id( $order, $charge_permission_id, $charge_id ) {
2341+
if ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order ) || wcs_order_contains_renewal( $order ) ) ) {
2342+
$charge_permission_id = substr( $charge_id, 0, strrpos( $charge_id, '-C' ) );
2343+
}
2344+
if ( ! empty( $charge_permission_id ) ) {
2345+
$order->set_transaction_id( $charge_permission_id );
2346+
}
2347+
}
23322348
}

woocommerce-gateway-amazon-payments-advanced.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ public function init_gateway() {
224224

225225
}
226226

227+
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
228+
227229
include_once $this->includes_path . 'legacy/class-wc-gateway-amazon-payments-advanced-legacy.php';
228230
if ( WC_Amazon_Payments_Advanced_Merchant_Onboarding_Handler::get_migration_status() ) {
229231
include_once $this->includes_path . 'class-wc-gateway-amazon-payments-advanced.php';
@@ -232,8 +234,7 @@ public function init_gateway() {
232234
} else {
233235
$this->gateway = new WC_Gateway_Amazon_Payments_Advanced_Legacy();
234236
}
235-
236-
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
237+
$this->gateway->gateway_settings_init();
237238
}
238239

239240
/**

0 commit comments

Comments
 (0)