1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace Bolt\Extension\Ginger\Squarepay\Twig;
- use Silex\Application;
- /**
- * Twig runtime class that will only be invoked when one of its functions or
- * filters are used.
- *
- * @author Richard Knight <rich@apewave.com>
- */
- class SquareTwigRuntime
- {
- private $apiClient;
- public function __construct($apiClient, $twig, $config)
- {
- $this->apiClient = $apiClient;
- $this->twig = $twig;
- $this->config = $config;
- }
- public function getCatalog()
- {
- try {
- $catalogApi = new \SquareConnect\Api\CatalogApi($this->apiClient);
- $products = $catalogApi->listCatalog();
- } catch (Exception $e) {
- error_log($e->getMessage());
- return 'ERROR: '.$e->getMessage();
- }
- $response = [];
- foreach($products['objects'] as $p) {
- if ($p['type'] === 'ITEM') {
- array_push($response, $p);
- }
- }
- return $response;
- }
-
- public function displayCCForm() {
- $context = $this->config + [
- 'testmode' => true
- ];
- return $this->twig->render('@Squarefront/cardentryform.twig', $context);
- }
- }
|