Browse Source

Beginning Square Extension - basic config and routing now set up

Richard Knight 6 years ago
parent
commit
41a9ddfab7
3 changed files with 107 additions and 0 deletions
  1. 8 0
      config/config.yml.dist
  2. 41 0
      src/Controller/SquareController.php
  3. 58 0
      src/SquarepayExtension.php

+ 8 - 0
config/config.yml.dist

@@ -0,0 +1,8 @@
+sq_domain: connect.squareup.com
+sq_auth_url: /oauth2/authorize
+
+sq_app_id: sq0idp-E62fjwNzSQG08kHHzOhc7w
+sq_app_secret: sq0csp-w3zX86p5tbHb5kKlCyL2CM0zP7ldpRXZRHDbHFiAPi4
+
+sq_sandbox_add_id: sandbox-sq0idp-E62fjwNzSQG08kHHzOhc7w
+sq_sandbox_token: sandbox-sq0atb-pDGW0n945W5jLLIA4eUhpQ

+ 41 - 0
src/Controller/SquareController.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace Bolt\Extension\Ginger\Squarepay\Controller;
+
+use Bolt\Controller\Base;
+use Silex\Application;
+use Silex\ControllerCollection;
+use Silex\ControllerProviderInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * The controller for Square backend routes.
+ *
+ * @author Richard Knight <rich@apewave.com>
+ */
+class SquareController extends Base
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function addRoutes(ControllerCollection $c)
+    {
+        $c->match('/oauth/{type}', [$this, 'oauthHandler']);
+        return $c;
+    }
+
+    /**
+     * @param Request $request
+     * @param string  $type
+     *
+     * @return Response
+     */
+    public function oauthHandler(Request $request, $type)
+    {
+        if ($type === 'dropbear') {
+            return new Response('Drop bear sighted!', Response::HTTP_OK);
+        }
+        return new Response('Koala in a tree!', Response::HTTP_OK);
+    }
+}

+ 58 - 0
src/SquarepayExtension.php

@@ -3,6 +3,11 @@
 namespace Bolt\Extension\Ginger\Squarepay;
 
 use Bolt\Extension\SimpleExtension;
+use Bolt\Menu\MenuEntry;
+use Silex\Application;
+use Silex\ControllerCollection;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
 
 /**
  * Squarepay extension class.
@@ -11,8 +16,61 @@ use Bolt\Extension\SimpleExtension;
  */
 class SquarepayExtension extends SimpleExtension
 {
+    protected function registerAssets() {
+		// $config = $this->getConfig();
+	}
+
+	protected function registerFrontendRoutes(ControllerCollection $collection)
+	{
+        $collection->match('/checkout', [$this, 'checkoutPaymentForm']);
+	}
+	
+	protected function registerBackendRoutes(ControllerCollection $collection)
+	{
+        $collection->match('/extensions/square-authorisation', [$this, 'squareAuthorisation']);
+        $collection->match('/extensions/square-authorisation-result', [$this, 'squareAuthorisationHandleResult']);
+	}
+
+	protected function registerBackendControllers()
+	{
+		return [
+			'/extensions/square' => new Controller\SquareController()
+		];
+	}
+
+	protected function registerMenuEntries()
+	{
+        $menu = MenuEntry::create('square-menu', 'square')
+            ->setLabel('Square Payments')
+            ->setIcon('fa:credit-card-alt')
+            ->setPermission('settings')
+			// ->setRoute('square')
+			;
+
+        return [
+            $menu
+        ];
+	}
 	
+	protected function registerTwigFunctions() {
+		return [
+			'waggawoo' => ['waggawooFunction', ['is_safe' => ['html']]]
+		];
+	}
+
+	public function waggawooFunction() {
+		return '<h1>WAGGA WAGGA WOO!</h1>';
+	}
 
+	function checkoutPaymentForm() {
+        return new Response('Display Payment Form', Response::HTTP_OK);
+	}
 
+	function squareAuthorisation() {
+        return new Response('Square Authorisation', Response::HTTP_OK);
+	}
 
+	function squareAuthorisationHandleResult() {
+        return new Response('Square Authorisation Result', Response::HTTP_OK);
+	}
 }