Skip to content

Commit

Permalink
! Hopefully handle one previously unhandled IPN txn_type as per Simpl…
Browse files Browse the repository at this point in the history
…eMachines#1169

Signed-off-by: Peter Spicer <[email protected]>
  • Loading branch information
Arantor committed Jan 18, 2014
1 parent a656936 commit f44147f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
26 changes: 26 additions & 0 deletions Sources/Subscriptions-PayPal.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,32 @@ public function isPayment()
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?
*
Expand Down
13 changes: 8 additions & 5 deletions subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,18 @@
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
Expand Down

0 comments on commit f44147f

Please sign in to comment.