|
@@ -2,10 +2,14 @@
|
|
|
|
|
|
namespace Bolt\Extension\Ginger\Squarepay;
|
|
|
|
|
|
+use Bolt\Extension\Ginger\Squarepay\Api;
|
|
|
+use Bolt\Extension\Ginger\Squarepay\Twig;
|
|
|
use Bolt\Extension\SimpleExtension;
|
|
|
use Bolt\Menu\MenuEntry;
|
|
|
use Silex\Application;
|
|
|
+
|
|
|
use Silex\ControllerCollection;
|
|
|
+
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
@@ -16,61 +20,89 @@ use Symfony\Component\HttpFoundation\Response;
|
|
|
*/
|
|
|
class SquarepayExtension extends SimpleExtension
|
|
|
{
|
|
|
- protected function registerAssets() {
|
|
|
- // $config = $this->getConfig();
|
|
|
+ private $apiClient = null;
|
|
|
+
|
|
|
+ protected function registerServices(Application $app)
|
|
|
+ {
|
|
|
+ $app['square.apiClient'] = $app->share(function($app) {
|
|
|
+
|
|
|
+ // Create and configure a new Square API client using the OAuth token
|
|
|
+ $manager = $app['filesystem'];
|
|
|
+ if (!$manager->hasFilesystem('extensions_config')) {
|
|
|
+ throw new Exception('Could not find filesystem extensions_config');
|
|
|
+ }
|
|
|
+ $filesystem = $manager->getFilesystem('extensions_config');
|
|
|
+ $path = '.sqoatoken';
|
|
|
+ $file = $filesystem->getFile($path);
|
|
|
+ if (!$file->exists($path)) {
|
|
|
+ throw new Exception('Could not find '.$path);
|
|
|
+ }
|
|
|
+ $oauthToken = $file->read($path);
|
|
|
+
|
|
|
+ $apiConfig = new \SquareConnect\Configuration();
|
|
|
+ $apiConfig->setAccessToken($oauthToken);
|
|
|
+ $apiClient = new \SquareConnect\ApiClient($apiConfig);
|
|
|
+ return new \SquareConnect\ApiClient($apiConfig);
|
|
|
+ });
|
|
|
+
|
|
|
+ $app['twig.runtime.square'] = $app->share(function ($app) {
|
|
|
+ return new Twig\SquareTwigRuntime($app['square.apiClient']);
|
|
|
+ });
|
|
|
+
|
|
|
+ $app['twig.runtimes'] = $app->extend(
|
|
|
+ 'twig.runtimes',
|
|
|
+ function (array $runtimes) {
|
|
|
+ // You must append your array to the passed in $runtimes array and return it
|
|
|
+ return $runtimes + [
|
|
|
+ Twig\SquareTwigRuntime::class => 'twig.runtime.square',
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
protected function registerFrontendRoutes(ControllerCollection $collection)
|
|
|
{
|
|
|
- $collection->match('/checkout', [$this, 'checkoutPaymentForm']);
|
|
|
+ $collection->match('/process-square', [$this, 'processSquarePaymentResponse']);
|
|
|
}
|
|
|
|
|
|
- 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()
|
|
|
+ '/extensions/square' => new Controller\SquareBackendController($this->getConfig())
|
|
|
];
|
|
|
}
|
|
|
|
|
|
protected function registerMenuEntries()
|
|
|
{
|
|
|
- $menu = MenuEntry::create('square-menu', 'square')
|
|
|
- ->setLabel('Square Payments')
|
|
|
- ->setIcon('fa:credit-card-alt')
|
|
|
- ->setPermission('settings')
|
|
|
- // ->setRoute('square')
|
|
|
+ $menu = MenuEntry::create('square-menu', 'square')
|
|
|
+ ->setLabel('Square')
|
|
|
+ ->setIcon('fa:credit-card')
|
|
|
+ ->setPermission('settings')
|
|
|
+ // ->setRoute('SquarepayExtension')
|
|
|
;
|
|
|
+ return [$menu];
|
|
|
+ }
|
|
|
|
|
|
- return [
|
|
|
- $menu
|
|
|
+ protected function registerTwigPaths()
|
|
|
+ {
|
|
|
+ // Register Twig namespace to use in controllers
|
|
|
+ return [
|
|
|
+ 'templates/backend' => ['namespace' => 'Squareback'],
|
|
|
+ 'templates/frontend' => ['namespace' => 'Squarefront']
|
|
|
];
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
protected function registerTwigFunctions() {
|
|
|
+ $getCatalog = [Twig\SquareTwigRuntime::class, 'getCatalog'];
|
|
|
+ $displayCCForm = [Twig\SquareTwigRuntime::class, 'displayCCForm'];
|
|
|
return [
|
|
|
- 'waggawoo' => ['waggawooFunction', ['is_safe' => ['html']]]
|
|
|
+ 'getcatalog' => [ $getCatalog ],
|
|
|
+ 'ccform' => [ $displayCCForm, ['is_safe' => ['html']] ]
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public function waggawooFunction() {
|
|
|
- return '<h1>WAGGA WAGGA WOO!</h1>';
|
|
|
+ public function processSquarePaymentResponse() {
|
|
|
+ // TODO
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
}
|