News:

Wondering if this will always be free?  See why free is better.

Main Menu

Another paid subscriptions bug?

Started by Krashsite, May 24, 2012, 12:56:41 AM

Previous topic - Next topic

Sir Osis of Liver


Per this thread, looks like there's a problem involving recurring payments.  If recurring payments are enabled, and member checks the option when ordering (it's checked by default), subscription fails because SMF does not recognize the transaction code sent in the IPN.  Did some test subs on a scratch 2.0.2 forum, and non-recurring sub work fine, but recurring payment does not.  Payment is completed but errors are generated and subscription fails.

This is what I have so far - 

In /Sources/Subscriptions-PayPal.php, it appears that the following txn_types are recognized:

  Refunded
  reversal
  subscr_payment
  web_accept

The following, which appear in the error log, are not:

  subscr_cancel
  subscr_eot
  subscr_signup


When I do a test subscription with recurring payment, two 'Unknown transaction type' errors are generated. PayPal executes two transactions to set up the subscription:

1 - Recurring Payment created - txn_type = subscr_payment
   
2 - Recurring Payment completed - txn_type = subscr_signup

The second transaction debits the member's account.  Don't know why the first error is generated, as subscr_payment is a recognized txn_type, but subscr_signup is not, and subscription fails.  If the recurring sub is cancelled by the forum or the member (in their respective PayPal accounts), an IPN is posted to the forum with txn_type = subscr_cancel, which is also not recognized by SMF, and throws the same error.

Unless it's somewhere else in the code, SMF doesn't know what to do with subscr_signup, so there's no way a recurring subscription can work.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

feline

Interesting .. on our system (2.0.2) subsription works without any problem .. also recurring payments

Sir Osis of Liver


Where is subscr_signup in the code?  Can't find it, and if it's not there, recurring payments shouldn't work.  Can't test it on my installs because I have a personal PayPal account, and recurring payments only works on business accounts.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

feline

I don't known which code is received .. I see only the result.
And I have a normal account on paypal .. no business

Wazza

Quote from: feline on May 24, 2012, 03:34:36 PM
Interesting .. on our system (2.0.2) subsription works without any problem .. also recurring payments

Could this be because your forum was "updated" to 2.0.2 and not a "New" install of 2.0.2?

This bug exists in a "New" install of 2.0.2 not recognizing the return_url sent like: "subscr_eot"  As Krash says it seems it's not there? so this is why I ask is yours working in a New install? as maybe this is were the difference may be?


,,,The PayPal account needs to be upgraded to premium or business to except a request from the forum for a recurring payment. This part is not were we have concern with. It is how 2.0.2 handles the return_url sent like: "subscr_eot" as Krash states in the first post.   



feline

Quote from: Wazza on May 25, 2012, 06:05:40 AM
Quote from: feline on May 24, 2012, 03:34:36 PM
Interesting .. on our system (2.0.2) subsription works without any problem .. also recurring payments

Could this be because your forum was "updated" to 2.0.2 and not a "New" install of 2.0.2?
I make anytime updates .. 2.0 -> 2.0.1 -> 2.0.2

edit:
just compare files from my system and a fresh 2.0.2 install archive ... no difference

Sir Osis of Liver


subscriptions.php is the form handler - it receives and processes the IPN, and calls functions from /Sources/Subscriptions-Paypal.php, which includes the PayPal gateway code.  It looks for specific txn_type codes which are hardcoded in the script.  As far as I can tell, they aren't in the database and don't occur anywhere else.  That being the case, if txn_type is subscr_signup, recurring subscription should fail because it's not in the code, which is what's happening on Wazza's forum.  It's a clean 2.0.2 install, new database, no mods or custom edits, basically nothing on it.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Wazza

I did a down load of the older versions of SMF over the weekend to see if I could see the difference too, but couldn't find it? So now really unsure how recurring payments ever worked? or how anyone using notify_url via PayPal has it working?

We have set up a brand new install of 2.0.2 to test and find why it is not working?

As right now in a brand new install this bug presents a major risk to new users, being able to create and receive a recurring payment from a member as the money part works. But then your forum will not recognize the notify_url. Outcome their member will never get what they paid for.  ???

Sir Osis of Liver


Just tried a test subscription on my 2.0 forum using your PayPal address, and got the same result.  Subscription failed, two unknown transaction type errors for subscr_payment and subscr_signup.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Wazza

Just refunded, thank you for testing. Surprised we are the first to find this error?

Sir Osis of Liver

#10
I'm surprised there's no interest in this problem.  If I'm reading the code correctly, recurring subs shouldn't work for anyone, and never could have in 2.0.x.

This hack may fix it (haven't tried it) -

In /Sources/Subscriptions-Paypal.php find this:



// Is this a subscription?
public function isSubscription()
{
if (substr($_POST['txn_type'], 0, 14) == 'subscr_payment')
return true;
else
return false;
}

// Is this a normal payment?
public function isPayment()
{
if ($_POST['payment_status'] == 'Completed' && $_POST['txn_type'] == 'web_accept')
return true;
else
return false;
}

// How much was paid?
public function getCost()
{
return $_POST['tax'] + $_POST['mc_gross'];
}

// exit.
public function close()
{
global $smcFunc, $subscription_id;

// If it's a subscription record the reference.
if ($_POST['txn_type'] == 'subscr_payment' && !empty($_POST['subscr_id']))



Change to this:



// Is this a subscription?
public function isSubscription()
{
if (substr($_POST['txn_type'], 0, 14) == 'subscr_payment' || substr($_POST['txn_type'], 0, 13) == 'subscr_signup')
return true;
else
return false;
}

// Is this a normal payment?
public function isPayment()
{
if ($_POST['payment_status'] == 'Completed' && $_POST['txn_type'] == 'web_accept')
return true;
else
return false;
}

// How much was paid?
public function getCost()
{
return $_POST['tax'] + $_POST['mc_gross'];
}

// exit.
public function close()
{
global $smcFunc, $subscription_id;

// If it's a subscription record the reference.
if (($_POST['txn_type'] == 'subscr_payment' || $_POST['txn_type'] == 'subscr_signup') && !empty($_POST['subscr_id']))



There's nothing in the database that flags a recurring sub, it's treated the same as a one-time subscription, so this workaround shouldn't affect anything in the forum (if it works).
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Arantor

Well, it definitely has worked for me in the past, so I'm intrigued as to why it hasn't for you.

emanuele

Looking at this:
http://www.paypalobjects.com/en_US/ebook/subscriptions/Appx-ipn_subscription_variables.html
and this:
http://stackoverflow.com/questions/1061683/subscriptions-with-paypal-ipn

If I understand well, signup shouldn't be "so" important, payment should be the answer that says if the payment is valid or not (that's just a guess BTW).

To debug paypal issues I need to be in a very good mood (it has to do with money and I don't want to do something wrong with someone else's money) so...later.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

Note that you can use the sandbox setting so that you don't actually use actual money.

emanuele

Yep, I know, the comment was intended more in the sense that if I do anything wrong here that goes into SMF it means I'm playing with someone else's money.
So (since I'm known to have...ehm...a lot of imagination in create bugs :P), I prefer to take my time and play with paypal when I have plenty of time and a good mood. ;D


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

That's the joy of the sandbox mode, you can test it and test it and test it over and once you're satisfied it can be committed :)

Wazza

Hi Krash,

Injected the code (don't worry I have a back up  :P) into the test 2.0.2 we created.

Came up with this error.

Fatal error: Cannot redeclare paypal_payment::isSubscription() in /home/wazza/public_html/ATown/Sources/Subscriptions-PayPal.php on line 233


...I should point out to the others I agree totally with the extra comments about getting this wrong when its someones money we are working with. However currently left the way it is, this gets it wrong  ???

"Recurring" whilst for me would be great to be working as optioned in SMF, I should say this is not imperative to me that this must work. I looked at this more as a time saver for members not needing to return and renew each month. I can live with out this, if this cannot be made functional. However for me I'm now more concerned for the future ramifications left this way in SMF if others make the same mistake?

I believe we ether need to fix this option or have this option removed  :-\ 

Wazza



Sir Osis of Liver

Quote from: Arantor on May 28, 2012, 02:43:56 PM
Well, it definitely has worked for me in the past, so I'm intrigued as to why it hasn't for you.

Where is the code that recognizes subscr_signup?  That's what has me stumped.

Quote from: emanuele on May 28, 2012, 02:48:15 PM
To debug paypal issues I need to be in a very good mood (it has to do with money and I don't want to do something wrong with someone else's money) so...later.

Don't believe it's a PayPal problem.  They're sending the correct IPN, and it's received by subscriptions.php, but SMF doesn't recognize the txn_type and subscription fails.

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Sir Osis of Liver

Quote from: Wazza on May 28, 2012, 05:17:15 PM
Fatal error: Cannot redeclare paypal_payment::isSubscription() in /home/wazza/public_html/ATown/Sources/Subscriptions-PayPal.php on line 233

Don't see how the hack could cause that error.  Attach your modified Subscriptions-Paypal.php.
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Wazza


Advertisement: