Page 1 of 1

Replacement Codes in Custom Return URL on Success - [s2mPro]

PostPosted: May 6th, 2011, 3:55 pm
by toddz88
Hi. On s2member Pro, I'm using a Custom Return URL on success, to redirect the user to my Thank You page. But I am have trouble with the Replacement Codes in the url.

SHORTCODE ON MY PAYMENT FORM PAGE
Code: Select all
success="thank-you/?subscr_id=%%subscr_id%%&item_name=%%item_name%%&regular=%%regular%%&recurring=%%recurring%%&initial_term=%%initial_term%%&regular_term=%%regular_term%%&full_name=%%full_name%%"



RESULTING URL
Note the strange "#038;" between var, after each "&". I think that's the problem.
Code: Select all
https://www.mysite.com/signup/thank-you/?subscr_id=I-00JAFFJFJT1N&s2p-v=1304711482-cf65722cd2a942183f328a64c53fa1b6#038;item_name=Individual+membership%3A+%241+USD+%2F+Month+%28+recurring+charge%2C+for+ongoing+access+%29&regular=1.00&recurring=1.00&initial_term=7+D&regular_term=1+M&full_name=Brian+Westbrook



THANK-YOU PAGE TEMPLATE FILE PHP
Each replacement-code / url-var that i'm expecting is handled like this:
Code: Select all
$thanks['subscr_id'] = htmlentities($_GET['subscr_id']);
$thanks['item_name'] = htmlentities($_GET['item_name']);

Then echo'd out to the page with
Code: Select all
<p>Subscription ID, subscr_id: <?php echo $thanks['subscr_id']; ?></p>
<p>item_name: <?php echo $thanks['item_name']; ?></p>



THE PROBLEM
Only the subscr_id is working, the other vars fail to show up in the $_GET array. Here's my debug:
Code: Select all
[_GET] => Array
        (
            [subscr_id] => I-00JAFFJFJT1N
            [s2p-v] => 1304711482-cf65722cd2a942183f328a64c53fa1b6
        )

[thanks] => Array
        (
            [subscr_id] => I-00JAFFJFJT1N
            [item_name] =>
            [regular] =>
            [recurring] =>
            [initial_term] =>
            [regular_term] =>
            [full_name] =>
        )


Since the $_GET seems to break after the "s2p-v" variable (whatever that is), and the next character in the returned url is a "#" ... it seems like that is the start of the problem, breaking the other vars.

Any idea what's going on here? What the "#038;" is, and how to remove it?
Thanks!
Todd

Re: Replacement Codes in Custom Return URL on Success - [s2m

PostPosted: May 6th, 2011, 8:09 pm
by Cristián Lávaque
The #038; appears to be another code for the ampersand, similar to &amp; and WP converts them in URLs. Not sure how it's used there, though. I'm sending Jason an email asking him about it.

Re: Replacement Codes in Custom Return URL on Success - [s2m

PostPosted: May 7th, 2011, 12:26 am
by toddz88
Hi Cristián. I googled further and found:
http://stackoverflow.com/questions/5605 ... nge-to-038
which says that a wp function called wptexturize() is responsible for the "#038;" .. though I am not familiar with that kind of url encoding. I have only seen the Percent sign, like "%20" .

The suggestions on that stackoverflow page involve hacking wordpress.. obviously a no-no. But it inspired me to write this simple function in my functions.php, to remove the "#038;"

Code: Select all
add_filter('the_content', 'fix_ampersands');
function fix_ampersands($content) {
  $content = str_replace('#038;' , '' , $content);
  return $content;
}


Interestingly, this also caused the (mysterious) "s2p-v" var to move to the LAST position in the url. No idea why.

Anyway, I guess i'm all set with this. But it seems to me that this is a problem in s2member Pro that should be addressed for all users who are doing Custom Return URL on Success, with Replacement Codes. Or maybe Jason has more info on this.. i'd still love to hear.

Thanks,
Todd

Re: Replacement Codes in Custom Return URL on Success - [s2m

PostPosted: May 7th, 2011, 12:44 am
by Cristián Lávaque
I'm glad it solved it for you.

I had found that page too, but I didn't share it precisely because it talks about hacking WP, but I did get from it that it represents an ampersand.

I searched s2Member Pro's code for that variable and found this in /wp-content/plugins/s2member-pro/includes/classes/gateways/paypal/paypal-utilities.inc.php (same in the Authorize.Net equivalent):

function paypal_s2p_v_generate wrote:This function adds the s2p-v variable onto the end of a custom URL for success. This can be used for verifying the integrity of variables in a success query string.


I sent Jason an email earlier, he may leave a comment when he sees it.

Re: Replacement Codes in Custom Return URL on Success - [s2m

PostPosted: May 7th, 2011, 12:49 pm
by Jason Caldwell
Thanks for reporting this important issue.
~ and thanks for bringing this to my attention Cristián.

Yes, I can see where this might happen. I'll classify this as a bug, and we'll include a fix for this in the next release. Until then, you can add this patch if you like.

Please open /s2member-pro/includes/classes/gateways/paypal-form-in.inc.php,
at line #53 add this line:
Code: Select all
$attr["success"] = preg_replace ("/(&#038;|&amp;)/", "&", $attr["success"]); /* Convert ampersands. */