Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fixing #135

Merged
merged 39 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
314c602
Check if other gateways is enabled before hide checkout button issue #97
lauramelos Jul 16, 2021
5d7a5b0
Merge pull request #118 from saucal/fix/hide-standard-checkout-button
msaggiorato Jul 16, 2021
2d1fe9a
Enable subscription amount change support Issue #106
lauramelos Jul 16, 2021
f772df7
Merge pull request #119 from saucal/fix/support-recursive-coupons
msaggiorato Jul 16, 2021
d94072e
Accept states without letters mark variations on shipping restriction…
lauramelos Oct 15, 2021
4a04dbe
Render cart button on update shipping method
lauramelos Oct 15, 2021
8649ea9
Merge pull request #127 from saucal/feature/state-restrictions
msaggiorato Oct 15, 2021
395acf2
Merge pull request #126 from saucal/feature/cart-button-render
msaggiorato Oct 15, 2021
3fe0ed8
Unify version checker
lauramelos Oct 28, 2021
4ae7df0
Get order charge permission and charge id method
lauramelos Oct 29, 2021
6c8ad9e
Force v2 version on orders
lauramelos Oct 29, 2021
98925d1
Remove duplicated assignation
lauramelos Oct 29, 2021
3fc9695
Add charge id for the orders with open capture
lauramelos Nov 4, 2021
014e20e
Parse V1 ipn response to process it with V2 handler
lauramelos Nov 4, 2021
b76836b
Skip v1 IPN handler on migration done
lauramelos Nov 4, 2021
a8ce149
Lowercase version on parsed IPN notification
lauramelos Nov 4, 2021
cf90dde
Change string replace function and save order
lauramelos Nov 4, 2021
75dca78
Log notification Data for the V1 IPN
lauramelos Nov 4, 2021
71282ee
Fix typos
msaggiorato Nov 4, 2021
7d870f8
PHPCS issues
msaggiorato Nov 4, 2021
7c32df4
PHPCS manual fixes
msaggiorato Nov 4, 2021
f20eac1
PHPCS fixes
msaggiorato Nov 4, 2021
88b35f8
Fix function call.
msaggiorato Nov 4, 2021
6111dc9
Undo version change
msaggiorato Nov 4, 2021
ac2e497
Merge pull request #129 from saucal/fix/coding-standards
lauramelos Nov 4, 2021
a2e5b39
Merge pull request #128 from saucal/feature/legacy-remove
lauramelos Nov 4, 2021
61a3f01
Replace gateways object to avoid error on settings
lauramelos Nov 12, 2021
009bc02
Set Order Transaction Id
lauramelos Nov 15, 2021
f89b6eb
Force Decimals to 2 on amounts sent to API
lauramelos Nov 30, 2021
edae818
Merge pull request #134 from saucal/feature/set-transaction-id
msaggiorato Nov 30, 2021
35e23ac
Merge pull request #135 from saucal/feature/force-decimals
msaggiorato Nov 30, 2021
e1cdb0b
Hide API V1 settings after onboarding is made
lauramelos Nov 12, 2021
e8cec4f
Merge pull request #132 from saucal/feature/v1-keys-settings
msaggiorato Dec 3, 2021
8d31d76
Check other gateways existence early
lauramelos Dec 6, 2021
7fecfaf
Delay Init settings to ensure gateway addition
lauramelos Dec 6, 2021
d7865c8
Merge pull request #133 from saucal/feature/current-gateways
msaggiorato Dec 6, 2021
6f6d60b
Add correct transaction Id to subscription and renewals orders
lauramelos Dec 8, 2021
4aaf940
Merge pull request #136 from saucal/feature/set-transaction-id
msaggiorato Dec 8, 2021
589ebb9
Merge branch 'main' into develop
lauramelos Dec 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions includes/class-wc-gateway-amazon-payments-advanced-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' ) );
}

/**
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 20 additions & 4 deletions includes/class-wc-gateway-amazon-payments-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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;
}

Expand All @@ -2329,4 +2330,19 @@ public function maybe_hide_standard_checkout_button() {
<?php
}

/**
* Maybe set order transaction id.
*
* @param WC_Order $order Order object.
* @param string $charge_permission_id Charge Permission.
* @param string $charge_id Charge Id.
*/
public function maybe_set_transaction_id( $order, $charge_permission_id, $charge_id ) {
if ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order ) || wcs_order_contains_renewal( $order ) ) ) {
$charge_permission_id = substr( $charge_id, 0, strrpos( $charge_id, '-C' ) );
}
if ( ! empty( $charge_permission_id ) ) {
$order->set_transaction_id( $charge_permission_id );
}
}
}
5 changes: 3 additions & 2 deletions woocommerce-gateway-amazon-payments-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}

/**
Expand Down