diff --git a/public_html/modules/campaign/removemethod.php b/public_html/modules/campaign/removemethod.php new file mode 100644 index 0000000..0c1072c --- /dev/null +++ b/public_html/modules/campaign/removemethod.php @@ -0,0 +1,45 @@ + $router->uParameters[1]), 30, true); + +} +catch (NotFoundException $e) +{ + throw new RouterException("Campaign does not exist."); +} + +try +{ + $sPaymentMethod = new PaymentMethod($router->uParameters[2]); +} +catch (NotFoundException $e) +{ + throw new RouterException("Payment method does not exist."); +} + +if($sPaymentMethod->sCampaignId !== $sCampaign->sId) +{ + throw new RouterException("Payment method does not belong to campaign."); +} + +/* TODO: Implement object deletion in CPHP */ +$database->CachedQuery("DELETE FROM payment_methods WHERE `Id` = :Id", array(":Id" => $sPaymentMethod->sId)); + +flash_notice("The payment method was successfully removed."); +redirect("/dashboard/{$sCampaign->sUrlName}"); + diff --git a/public_html/rewrite.php b/public_html/rewrite.php index b4063b6..f1a936e 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -34,20 +34,25 @@ $router->routes = array( "^/logout/([a-zA-Z0-9]+)$" => "modules/logout.php", "^/confirm/(.+)/([a-zA-Z0-9]+)$" => "modules/confirm.php", "^/dashboard$" => array( - 'target' => "modules/dashboard.php", - 'authenticator' => "authenticators/user.php", - 'auth_error' => "modules/error/guest.php" - ), + 'target' => "modules/dashboard.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), "^/dashboard/([a-zA-Z0-9-]+)$" => array( - 'target' => "modules/campaign/dashboard.php", - 'authenticator' => "authenticators/user.php", - 'auth_error' => "modules/error/guest.php" - ), + 'target' => "modules/campaign/dashboard.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), "^/dashboard/([a-zA-Z0-9-]+)/add-payment-method$" => array( - 'target' => "modules/campaign/addmethod.php", - 'authenticator' => "authenticators/user.php", - 'auth_error' => "modules/error/guest.php" - ), + 'target' => "modules/campaign/addmethod.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), + "^/dashboard/([a-zA-Z0-9-]+)/remove-payment-method/([0-9]+)$" => array( + 'target' => "modules/campaign/removemethod.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php" )