WordPress.org

Ready to get started?Download WordPress

Forums

WP Stripe
[resolved] Not Working Most of the Time (8 posts)

  1. wpcdn
    Member
    Posted 2 years ago #

    Hi,

    I'm testing with Stripe in test mode. Sometimes the payment is recorded and the "success" message appears. But most of the time when the payment is submitted, only a "0" appears at the top and no "success" message.

    What could be causing this?

    Thanks,

    Mark

    http://wordpress.org/extend/plugins/wp-stripe/

  2. PaulMorris
    Member
    Posted 2 years ago #

    Hi wpcdn,

    I have been seeing the same thing. I've noticed a pattern: when I'm logged into wordpress it works (usually), and when I'm not logged into wordpress it doesn't work, just the "0" appearing at the top. In my stripe.com logs I see "tokens" messages but not "charges" messages for these failed attempts. I posted previously about this in the "Uses other than donations" thread.

    Can you see if being logged in/out is the pattern for you as well?

    Doing some tests with the code, I found the line that is making the "0" appear at the top. It is in the wp-stripe.js file, line 42:

    $('.wp-stripe-details').prepend(response);

    This is part of the communication with Stripe.com, receiving the token and combining it with the other form data, before it saves the transaction to wordpress.

    The next step looks like it would be the wp_stripe_charge_initiate() function firing in stripe-functions.php But it is not firing in my tests. So looks like there's something breaking down between those two parts?

    -Paul

  3. PaulMorris
    Member
    Posted 2 years ago #

    Forgot to mention, I get this error in Firefox's error console when the submission doesn't work:

    Error: not well-formed
    Source File: https://api.stripe.com/v1/tokens
    Line: 1, Column: 1
    Source Code:
    {

    With a little green arrow pointing up at the space after the "{" bracket.

    This appears in the console at the moment when the stripeResponseHandler function (line 21) fires in wp-stripe.js right after after Stripe.createToken (line 62) fires.

  4. PaulMorris
    Member
    Posted 2 years ago #

    Found a couple of relevant things here:
    http://codex.wordpress.org/AJAX_in_Plugins

    Error Return Values
    If the AJAX request fails when the request url is wp-admin/admin-ajax.php, it will return either -1 or 0 depending on the reason it failed. Additionally, if an AJAX request succeeds, it will return a 0.

    So I think the "0" we're seeing is due to the AJAX request either failing or succeeding (seems like they would use a different number for those two things, right?).

    One reason it may be failing is if it doesn't have an 'action' parameter:
    http://core.trac.wordpress.org/browser/trunk/wp-admin/admin-ajax.php

    Also on http://codex.wordpress.org/AJAX_in_Plugins it talks about different ways of doing AJAX for those who are logged in (admin, back end) and those who are logged out (viewer-facing, front end). Namely, you need both of these things for it to work for both cases:

    add_action('wp_ajax_my_action', 'my_action_callback');
    add_action('wp_ajax_nopriv_my_action', 'my_action_callback');

    WP Stripe only has the first line (in stripe-functions.php line 105), which might be why it's only working for me when I'm logged in.

    (However, I tried adding the second line, and that did not fix things. The "0" did not appear, and the success: function(response)' function did not even fire inwp-stripe.js` line 58, as it does when the "0" appears.)

  5. hmoore71
    Member
    Posted 2 years ago #

    The reason is that you need both of these in stripe-function.php

    add_action('wp_ajax_wp_stripe_charge_initiate', 'wp_stripe_charge_initiate');

    //this is missing

    add_action('wp_ajax_nopriv_wp_stripe_charge_initiate', 'wp_stripe_charge_initiate');

  6. hmoore71
    Member
    Posted 2 years ago #

    Re-reading I see where you had tried the "nopriv." Make sure its exactly like what I've shown else the php ajax response handler does not get called.

    That is how I found the issue because there was no stripe-functions.php breakpoint firing when I was not logged in. Otherwise there was.

    Also I had my doubts about the action parameter too but it is there when looking at "data" in Firebug.

  7. Noel Tock
    Human Made
    Plugin Author

    Posted 2 years ago #

    Was bogged down the last few days. This is fixed now in 1.4.2. Let me know if you still have issues..

  8. PaulMorris
    Member
    Posted 2 years ago #

    1.4.2 working great, thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.