Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Last active September 25, 2019 14:18
Show Gist options
  • Save cgi-caesar/88636882738a81569e983ffd934679d8 to your computer and use it in GitHub Desktop.
Save cgi-caesar/88636882738a81569e983ffd934679d8 to your computer and use it in GitHub Desktop.
Redirect User to custom URL after recurring subscription cancelation
<?php
if (($u = Am_Di::getInstance()->auth->getUser()) &&
($url = Am_Di::getInstance()->store->get("cancel-redirect.{$u->pk()}"))) {
Am_Di::getInstance()->store->set("cancel-redirect.{$u->pk()}", null);
Am_Mvc_Response::redirectLocation($url);
}
Am_Di::getInstance()->hook->add(Am_Event::INVOICE_AFTER_CANCEL, function(Am_Event $e) {
$invoice = $e->getInvoice();
if ($e->getDi()->auth->getUserId() == $invoice->user_id) {
$e->getDi()->store->set("cancel-redirect.{$invoice->user_id}", '/some/url', '+ 5 minute');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment