11

I have written a simple paypal subscription system, where a user can enter their information, click the button, and start a subscription. Im wondering how I can find out when the user cancels the subscription though? I have seen $txn_type subscr_cancel but I have no idea how to use that, since paypal doesn't call my handler again.

Thanks!

  • I would appreciate an answer that does not require an IPN. Even if I use IPN, I would like to double check the subscription status of a user at the end of the subscription period by calling paypal API end point with the subscription id and see the status. Is that possible? – Michael Feb 25 '20 at 07:50

2 Answers2

26

Are you using IPN if yes then, when a subscription is cancelled paypal returns $_POST['txn_type'] = subscr_cancel along with subscr_date = subscription date, subscr_id = subscription ID, etc now you can process cancel request for the returned subscription id. similarly you get $_POST['txn_type'] = subscr_eot when subscription ends. Once you have setup IPN url in the paypal settings it will always call your ipn handler. use switch case to handle different requests like so,

switch ($_POST['txn_type']) {
    case 'cart':
          //for products without subscription
     break;
    case 'subscr_payment':
        //subscription payment recieved
        break;

    case 'subscr_signup':
        //subscription bought payment pending
        break;

    case 'subscr_eot':
       //subscription end of term
        break;

    case 'subscr_cancel':
        //subscription canceled
        break;
 }
Pragati Sureka
  • 1,412
  • 12
  • 18
  • 1
    Just what I needed tonight! Don't know why they don't make this clear enough in the docs. – Volomike Dec 13 '12 at 06:08
  • Just came across this. This is SUPER helpful (I've been struggling with this for a while). Thanks! – MillerMedia Aug 21 '13 at 20:05
  • 1
    [I think paypal was Loud & Clear](https://www.paypal.com/us/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside) – Sisir Feb 20 '14 at 05:12
8

The IPN with a type of 'subscr_cancel' is sent when the user actually cancels the subscription. This should not be used to cancel the subscription as this can happen anytime during the subscription period.

The IPN with the 'subscr_eot' type should be used to cancel the subscription. This is sent when the user's subscription period has expired.

user4035
  • 22,508
  • 11
  • 59
  • 94
Phil Wallach
  • 3,318
  • 20
  • 19