From 29735c60bb3bc1244bb74f3bd65976dd1a87cdf2 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Thu, 7 Jun 2018 15:40:52 +0000 Subject: [PATCH] Major changes - Ready app for initial testings --- public/index.php | 23 +++++++++- public/sourcetest.php | 0 source/defs/Hookmanager/Hookmanager.php | 59 +++++++++++++++++++++++-- 3 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 public/sourcetest.php diff --git a/public/index.php b/public/index.php index a0a6dca..dd06fd3 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,25 @@ + [ + "displayErrorDetails" => true + ] + ]); + -$App->post("/api/paddle/{authkey}/hook"); \ No newline at end of file + +$App->post + ( + "/api/paddle/{authkey}/detectIntent", + Hookmanager::class, ':detectPayloadIntent' + ); + +$App->post + ( + "/api/paddle/{authkey}/hook", + Hookmanager::class, ':EventSubscriptionCreatead' + + ); \ No newline at end of file diff --git a/public/sourcetest.php b/public/sourcetest.php new file mode 100644 index 0000000..e69de29 diff --git a/source/defs/Hookmanager/Hookmanager.php b/source/defs/Hookmanager/Hookmanager.php index ae4c23d..2c6f425 100644 --- a/source/defs/Hookmanager/Hookmanager.php +++ b/source/defs/Hookmanager/Hookmanager.php @@ -19,6 +19,20 @@ class Hookmanager private $Mailer; + // Can be overloaded by child classes in order to add new features.W + protected $alertTypes = + [ + "subscription_created", + "subscription_updated", + "subscription_cancelled", + "subscription_payment_succeeded", + "subscription_payment_failed", + "subscription_payment_refunded", + "payment_refunded", + + ] + + public function __construct() { @@ -48,13 +62,50 @@ class Hookmanager } - public function EventSubscriptionCreated(Request $request, Response $response) + private function keyValidate($keyFromURI) { - // Create customer with data from Paddle - // Send email with customer information + // FIXME: Theoretically, this method does not work. + // TODO: Devise a new way to validate keys without user ID + if($this->APITools->keysMatch($keyFromURI)) + { + return true; + } + else + { + return false; + } + } + + public function detectPayloadIntent(Request $request, Response $response, $args) + { + if ($this->keyValidate($keyFromURI)) + { + + $data = $this->getStructuredVariableList($Request); + + foreach ($this->alertTypes as $types => $value) + { + if ($types == $data['alert_name']) + { + $sVal = $value; + } + } + + // TODO: Redirect request to approriate route. + // Use translator helper method to translate developer name to readable route name for redirect + + + } + + throw new LogicException("Illegal API key"); - + } + + public function EventSubscriptionCreated(Request $request, Response $response, $args) + { + + return $response->write($this->getStructuredVariableList($Request))->withStatus(200); }