Browse Source

! Hopefully handle one previously unhandled IPN txn_type as per #1169

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
f44147f370
2 changed files with 34 additions and 5 deletions
  1. 26 0
      Sources/Subscriptions-PayPal.php
  2. 8 5
      subscriptions.php

+ 26 - 0
Sources/Subscriptions-PayPal.php

@@ -311,6 +311,32 @@ class paypal_payment
 			return false;
 	}
 
+	/**
+	 * Is this a cancellation?
+	 *
+	 * @return boolean
+	 */
+	public function isCancellation()
+	{
+		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel')
+			return true;
+		else
+			return false;
+	}
+
+	/**
+	 * Things to do in the event of a cancellation
+	 *
+	 * @return void
+	 */
+	public function performCancel($subscription_id, $member_id, $subscription_info)
+	{
+		// PayPal doesn't require SMF to notify it every time the subscription is up for renewal.
+		// A cancellation should not cause the user to be immediately dropped from their subscription, but
+		// let it expire normally. Some systems require taking action in the database to deal with this, but
+		// PayPal does not, so we actually just do nothing. But this is a nice prototype/example just in case.
+	}
+
 	/**
 	 * How much was paid?
 	 *

+ 8 - 5
subscriptions.php

@@ -265,15 +265,18 @@ elseif ($gatewayClass->isPayment() || $gatewayClass->isSubscription())
 		emailAdmins('paid_subscription_new', $replacements, $notify_users);
 	}
 }
+// Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example.
+elseif ($gatewayClass->isCancellation())
+{
+	if (method_exists($gatewayClass, 'performCancel'))
+		$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
+}
 else
 {
 	// Some other "valid" transaction such as:
 	//
-	// subscr_cancel: This IPN response (txn_type) is sent only when the subscriber cancels his/her
-	// current subscription or the merchant cancels the subscribers subscription. In this event according
-	// to Paypal rules the subscr_eot (End of Term) IPN response is NEVER sent, and it is up to you to
-	// keep the subscription of the subscriber active for remaining days of subscription should they cancel
-	// their subscription in the middle of the subscription period.
+	// subscr_eot: End of term - sent when a subscription ends at a given term date. Normally should not occur because either
+	// a paid sub is a one-off payment, or it's recurring without a fixed term.
 	//
 	// subscr_signup: This IPN response (txn_type) is sent only the first time the user signs up for a subscription.
 	// It then does not fire in any event later. This response is received somewhere before or after the first payment of