I've successfully integrated PayPal into my PHP Laravel application. I've implemented the checkout flow and I'm able to receive IPN notifications and store them in my database. Users subscribe to a Premium service via PayPal Express Checkout recurring payments. An initial payment is made and then they're billed monthly. They're given a Premium status on the website which unlocks extra site features. What I'm trying to do now is have my application automatically remove a user's Premium in certain scenarios. Such as: When a user cancels their subscription from their PayPal account When a payment fails too many times I've checked the IPN variable table and have identified the following txn_types that I should be dealing with: recurring_payment_profile_cancel recurring_payment_suspended_due_to_max_failed_payment Are there any txn_types that I'm missing? Will this cover all bases? In my IPN listener function I have code that cancels a user's Premium subscription on my website when the above txn_types are received: public function notify(Request $request)
{
if (!($this->provider instanceof ExpressCheckout))
{
$this->provider = new ExpressCheckout();
}
$post = ['cmd' => '_notify-validate'];
$data = $request->all();
foreach ($data as $key => $value)
{
$post[$key] = $value;
}
$response = (string) $this->provider->verifyIPN($post);
$ipn = new PaypalNotification();
$ipn->payload = json_encode($post);
$ipn->status = $response;
$ipn->save();
if ($response == "VERIFIED")
{
if (($data['txn_type'] == 'recurring_payment_profile_cancel' || $data['txn_type'] == 'recurring_payment_suspended_due_to_max_failed_payment') && !empty($data['recurring_payment_id']))
{
$subscription = PaypalSubscription::where('profile_id', $data['recurring_payment_id'])->first();
if ($subscription != null)
{
$subscription->cancel();
}
}
}
} Am I missing anything?
... View more