Checkout process failing on its final stage after paypal has taken $$$

Hi, I've been having some major difficulties with debugging an failure at the final stage of the checkout process after the user's payment has been received by paypal express checkout gateway. The details of the transaction are never stored in the WP marketpress and so my client is having to email the user to ask their mailing address and products ordered...

I've determined through watching the post data that it looks like the initial authorization process that goes to paypal is actually being handled like a payment instead. So when the user returns back to my site they with their transaction token, Marketpress thinks "nope that token has already been used!" FAIL.

Additionally a coworker of mine noticed that switching the theme before the doing the transaction and even during the transaction allows everything to go smoothly.

Any assistance would be appreciated...

More details to come.

  • Aaron
    • CTO

    It sounds like your theme is doing something wierd to run the loop more than once, so it's trying process the return twice, invalidating the token. What theme are you using? If I can look at it I may be able to help debug it, though overall it would be best to change to a properly coded theme.

  • mediumrare
    • WPMU DEV Initiate

    Running the loop more than once? Alright there might be something there but I'll send you the zip of my theme. I hope that will suffice, let me know if you need anything else.

    I also have another paypal plugin running on this site called S2Member which handles our subscription based memberships. I initially thought that this was the culprit but after discovering that everything works with the theme switched but no plugins turned off I figure that it isn't an IPN handling conflict with the S2Member plugin. Does that make sense?

    this is the error i get once I've completed the authorization at paypal and it sends me back to my site:
    "There was a problem finalizing your purchase with PayPal. Please go back and try again.
    10415 - Transaction refused because of an invalid argument. See additional error messages for details. - A successful transaction has already been completed for this token."

    Thanks for your help Aaron

  • Aaron
    • CTO

    Ok, so are you still getting the same error? It's after you click the "Confirm Payment" button right?

    I installed you theme on my test site and I didn't get the error checking out with paypal express. Perhaps because my template does not seem to be loading the right page when on the cart. Do you have a special page template or something for your cart?

  • mediumrare
    • WPMU DEV Initiate

    Hey Aaron, I'm still getting this error.
    I don't have a special template for my cart, no.

    it looks like it might be possible to create my theme on a fresh WP install and see if i can recreate this error. It's strange that i've only been able to replicate this error on the live site. This is exactly the issue i was having earlier in that i this didn't seem to happen when i had the site on my dev server and was using paypal's sandbox mode. I've been thinking about this a lot and I may have a couple tricks up my sleeve for making this work again.

    I'll keep you posted. I'd love if you could let me know if you come up with any developments. Like I said earlier another set of eyes will help for sure.

  • mediumrare
    • WPMU DEV Initiate

    Latest update:
    I've set up a dev server in order to sink my teeth into this a bit more. I've disabled all plugins and started some really thorough error logging. I've discovered a wack load of marketpress PHP NOTICES but not much that should kill the entire process.

    I think I may have found a possible weakness though.

    It looks like in my functions PHP i have a script that listens for whenever a new post is saved and creates a category bearing the same name, it looks like this:

    function create_categories(){
      $adopt_args = array(
        'posts_per_page' => -1,
        'post_type'   => 'orangutans',
        'post_parent' => 0 );
      $adopt_query = get_posts( $adopt_args );
      foreach($adopt_query as $orangutan){
        wp_create_category($orangutan->post_name);
      }
    }
    add_action( 'save_post', 'create_categories' );

    After doing my paypal checkout and returning to my site I get to the "confirm payment" screen. When i click to confirm I was getting the white screen of death. But my errors show a fatal error here:

    "PHP Fatal error: Call to undefined function wp_create_category() in /var/www/vhosts/redapes.org/dev.redapes.org/wp-content/themes/orangutanoutreach/functions.php on line 188"

    It would make sense that when MarketPress saves the transaction details it calls fires the "save_post" action in WP. Thus attempting to create WP categories. Of course the wp_create_category function hasn't been included by PHP so it's looking for a function that doesn't exist.

    I think that's about right. I'm going to look into this a bit more to make sure that I actually have the problem by the root before claiming this thing resolved.

  • mediumrare
    • WPMU DEV Initiate

    Okay this topic can be closed now. I've determined that this function was killing my process before Marketpress was able to save the details to WP. Marketpress would get as far as begin building the transaction record but when the wp_create_category function would throw its fatal error, none of the transaction details would actually get saved. The 10415 transaction error occured when I would refresh the page after the WSOD because the record has already be built. Anyway, lesson learned: php error logging is really useful in debugging these issues. Combine that with SSH access you can use commands like:
    tail -f error.log

    my final solution (not that it'll be relevant to many people, but for those who are curious):

    function create_categories(){
      $adopt_args = array(
        'posts_per_page' => -1,
        'post_type'   => 'orangutans',
        'post_parent' => 0 );
      $adopt_query = get_posts( $adopt_args );
    
      $categories = get_categories();
      $test_cats = array();
      foreach($categories as $cat) {
        $test_cats[] = $cat->slug;
      }
    
      foreach($adopt_query as $orangutan){
        if(!in_array($orangutan->post_name, $test_cats)) {
          wp_create_category($orangutan->post_name);
        }
      }
    }
    add_action( 'save_post', 'create_categories' );

    This way i don't need to run that function at all unless there is a valid reason for it. This should save that wp_create_category function from running several times ever time a post is saved too.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.