Forum Replies Created

Viewing 15 replies - 1 through 15 (of 19 total)
  • Adding on — we also found the plugin to cause this issue on one of our client sites this morning.

    Thread Starter eriktdesign

    (@eriktdesign)

    Still waiting to hear back on this issue.

    Thread Starter eriktdesign

    (@eriktdesign)

    Any update?

    Thread Starter eriktdesign

    (@eriktdesign)

    Hi there,

    1. Number of users: ~14,000
    2. Server specifications: This site is hosted on Pantheon, on a Performance Medium plan.
      • Memory: 512mb
      • Application containers: 2
      • PHP Workers: 16
      • CPU: Don’t know, Pantheon doesn’t advertise this information. It should be pretty beefy though.
    Thread Starter eriktdesign

    (@eriktdesign)

    I wound up kludging a redirect into the site to make the API endpoint go to the right place, but the report is still not getting any data. Can I have some assistance on this?

    Thread Starter eriktdesign

    (@eriktdesign)

    Hi @rainfallnixfig,

    Sorry this took a bit — had to wait for this to come back up in my stack. Here are the System Status report and a selection from the Stripe log.

    System status: https://pastebin.com/X0zUcBVA

    Selected stripe logs (redacted): https://pastebin.com/MHnNNvfu

    Yeah, it looks like the IPN fails without also adding some kind of filter in the plugin there. I added a PR to the repo: https://github.com/woocommerce/woocommerce-gateway-amazon-pay/pull/133

    Or maybe yours _will_ work and I’m just tired. I’m going to do some testing with both.

    @jurgen-oldenburg Eyyyyy that’s a nice find. I was looking inside the WC_Amazon_Payments_Advanced_API::get_merchant_metadata() function and wanting a filter in there, but I see that the filter you found is just after the call to that function — nice.

    Some notes/thoughts —
    * It looks like that filter isn’t applied on scheduled subscription payments, so this solution probably won’t work right with Subscription stores
    * Oops, and here I see why I didn’t see that filter — it doesn’t get applied when running an _authorization_ in the WC_Gateway_Amazon_Payments_Advanced::perform_authorization() function, only when it’s a capture (the store I’m debugging this for uses authorize -> capture on complete).
    * I have no idea the implications of this for IPN functionality — mostly because I don’t really know what this plugin uses IPN for. I think just hotwiring the order number in at the payload stage will cause issues if the order subsequently gets updated via the IPN update method because the order ID coming back from the Amazon API won’t match the database.

    I’m working on some adjustments of my own to make this work in our situation, and I’ll share here since this is the only relevant thread I’ve found. I’m planning on submitting a pull request on the Amazon Pay plugin github to request some filters be added so we can do this kind of thing without hacking the plugin.

    So, first I’m adding a filter to the WC_Amazon_Payments_Advanced_API::get_merchant_metadata() function, making the return statement look like this:

    return apply_filters( 'woocommerce_amazon_pa_merchant_metadata', array(
    	'merchantReferenceId' => $order_id,
    	'merchantStoreName'   => WC_Amazon_Payments_Advanced::get_site_name(),
    	'customInformation'   => $version_note,
    ) );
    

    Then I’m adding another filter to WC_Amazon_Payments_Advanced_IPN_Handler::handle_notification_ipn_v2() after the first switch statement (line 439) that allows us to filter the order ID that’s coming in from IPN:

    
    $order_id = apply_filters( 'woocommerce_amazon_pa_ipn_order_id', $order_id );
    

    Annoyingly, there’s already a filter on the $order object right below that on line 446, but the is_numeric check above that will already dump out of the function if the order number returned by the API isn’t numeric (we use a alpha prefix for ours, so no bueno).

    So anyway, with those two filters added, I’ve popped these two functions into a plugin:

    
    /**
     * Use the WooCommerce Sequential Order Numbers Pro order number for Amazon API
     *
     * @param array $metadata Metadata array that goes to the Amazon API
     * @return array Filtered data with the merchantReferenceId replaced
     */
    function apcc_use_sequential_order_number_on_submit( $metadata ) {
    	$order = wc_get_order( $metadata['merchantReferenceId'] );
    	$metadata['merchantReferenceId'] = $order->get_order_number();
    	return $metadata;
    }
    add_filter( 'woocommerce_amazon_pa_merchant_metadata', 'apcc_use_sequential_order_number_on_submit' );
    
    /**
     * Lookup the IPN requested order by the sequential order number and return the order id
     *
     * @param string $order_id merchantReferenceId returned from the API
     * @return int Internal order ID
     */
    function apcc_lookup_order_by_seq_order_number( $order_number ) {
    	// Use the WooCommerce Sequential Order Numbers Pro helper function to look up the order ID
    	$order_id = wc_seq_order_number_pro()->find_order_by_order_number( $order_number );
    	// If an order ID is found, return it to the filter
    	if ( $order_id ) return $order_id;
    	// If it wasn't found, this might not be a sequential order number, so sent it back as-is
    	else return $order_number;
    }
    add_filter( 'woocommerce_amazon_pa_ipn_order_id', 'apcc_lookup_order_by_seq_order_number' );
    

    This code is actually set up for the _other_ Sequential Order Numbers plugin (sorry @webtoffee I’m sure this one is great too!), but the line with wc_seq_order_number_pro()->find_order_by_order_number( $order_number ) line can be replaced with whatever function is used to look up orders by the sequential order number in the Webtoffee plugin.

    I’ve done initial testing with this code in an Amazon Pay sandbox. I’m going to write some of this up and drop it on their Github as well.

    Thanks for your work on this — I got so hopeful that with your solution there was a simpler way to do this than mine, but looks like not quite!

    • This reply was modified 2 years, 11 months ago by eriktdesign. Reason: formatting
    Thread Starter eriktdesign

    (@eriktdesign)

    Hi,

    The plugin was previously installed by another developer. When I re-installed and activated it, I got the 500 error. (Note, this is only on the plugin options page). I deleted the table the plugin was using in the database and reactivated, but that didn’t work.

    It’s an e-commerce site with a reasonably large number of Woocommerce products.

    Thread Starter eriktdesign

    (@eriktdesign)

    PHP error log, with stack trace:

    `
    [22-Jan-2020 14:37:39 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 536576 bytes) in /Users/erik/Local Sites/schweitzer/app/public/wp-includes/functions.php on line 4552
    [22-Jan-2020 14:37:39 UTC] PHP Stack trace:
    [22-Jan-2020 14:37:39 UTC] PHP 1. {main}() /Users/erik/Local Sites/schweitzer/app/public/wp-admin/options-general.php:0
    [22-Jan-2020 14:37:39 UTC] PHP 2. require_once() /Users/erik/Local Sites/schweitzer/app/public/wp-admin/options-general.php:10
    [22-Jan-2020 14:37:39 UTC] PHP 3. do_action() /Users/erik/Local Sites/schweitzer/app/public/wp-admin/admin.php:254
    [22-Jan-2020 14:37:39 UTC] PHP 4. WP_Hook->do_action() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/plugin.php:478
    [22-Jan-2020 14:37:39 UTC] PHP 5. WP_Hook->apply_filters() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-hook.php:312
    [22-Jan-2020 14:37:39 UTC] PHP 6. EPS_Redirects_Plugin_Options->do_admin_page() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-hook.php:288
    [22-Jan-2020 14:37:39 UTC] PHP 7. EPS_Redirects_Plugin_Options->get_tab() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/libs/eps-plugin-options.php:278
    [22-Jan-2020 14:37:39 UTC] PHP 8. do_action() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/libs/eps-plugin-options.php:321
    [22-Jan-2020 14:37:39 UTC] PHP 9. WP_Hook->do_action() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/plugin.php:478
    [22-Jan-2020 14:37:39 UTC] PHP 10. WP_Hook->apply_filters() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-hook.php:312
    [22-Jan-2020 14:37:39 UTC] PHP 11. EPS_Redirects_Plugin->admin_tab_redirects() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-hook.php:288
    [22-Jan-2020 14:37:39 UTC] PHP 12. include() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/plugin.php:564
    [22-Jan-2020 14:37:39 UTC] PHP 13. EPS_Redirects::get_inline_edit_entry() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/templates/admin-tab-redirects.php:37
    [22-Jan-2020 14:37:39 UTC] PHP 14. include() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/eps-301-redirects.php:505
    [22-Jan-2020 14:37:39 UTC] PHP 15. include() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/templates/template.redirect-entry-edit-inline.php:23
    [22-Jan-2020 14:37:39 UTC] PHP 16. eps_get_selector() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/templates/template.redirect-entry-edit.php:33
    [22-Jan-2020 14:37:39 UTC] PHP 17. eps_get_post_type_selects() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/eps-form-elements.php:46
    [22-Jan-2020 14:37:39 UTC] PHP 18. eps_dropdown_pages() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/eps-form-elements.php:155
    [22-Jan-2020 14:37:39 UTC] PHP 19. get_posts() /Users/erik/Local Sites/schweitzer/app/public/wp-content/plugins/eps-301-redirects/class.drop-down-pages.php:44
    [22-Jan-2020 14:37:39 UTC] PHP 20. WP_Query->query() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/post.php:2039
    [22-Jan-2020 14:37:39 UTC] PHP 21. WP_Query->get_posts() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-query.php:3413
    [22-Jan-2020 14:37:39 UTC] PHP 22. array_map() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-query.php:3011
    [22-Jan-2020 14:37:39 UTC] PHP 23. get_post() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-query.php:3011
    [22-Jan-2020 14:37:39 UTC] PHP 24. shutdown_action_hook() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/load.php:0
    [22-Jan-2020 14:37:39 UTC] PHP 25. do_action() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/load.php:947
    [22-Jan-2020 14:37:39 UTC] PHP 26. WP_Hook->do_action() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/plugin.php:478
    [22-Jan-2020 14:37:39 UTC] PHP 27. WP_Hook->apply_filters() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-hook.php:312
    [22-Jan-2020 14:37:39 UTC] PHP 28. wp_ob_end_flush_all() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/class-wp-hook.php:288
    [22-Jan-2020 14:37:39 UTC] PHP 29. ob_end_flush() /Users/erik/Local Sites/schweitzer/app/public/wp-includes/functions.php:4552
    `

    Thread Starter eriktdesign

    (@eriktdesign)

    Yes, thank you, that worked.

    Bonus question: Is there a way to enable the discount, but not automatically add the product(s) to the cart? We have some “premiums” that we’d like for users to be able to select — eg, order this product with at > $$, and you can choose a gift.

    @ryankienstra I tried this solution on the site I’m working on. It works properly for displaying the blocks in the frontend. However, when entering a value in the custom class field and then deselecting the block to enter preview mode, I get: “Error loading block: Invalid parameter(s): atrributes”

    Plugin Author eriktdesign

    (@eriktdesign)

    Aaaaaand fixed. That was easier than I thought it was going to be.

    Thread Starter eriktdesign

    (@eriktdesign)

    No, that’s not what I want. I want the notification to go automatically on PUBLISH, but NOT go on UPDATE.

Viewing 15 replies - 1 through 15 (of 19 total)