SquareTwigRuntime.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Bolt\Extension\Ginger\Squarepay\Twig;
  3. use Silex\Application;
  4. /**
  5. * Twig runtime class that will only be invoked when one of its functions or
  6. * filters are used.
  7. *
  8. * @author Richard Knight <rich@apewave.com>
  9. */
  10. class SquareTwigRuntime
  11. {
  12. private $apiClient;
  13. public function __construct($apiClient, $twig, $config)
  14. {
  15. $this->apiClient = $apiClient;
  16. $this->twig = $twig;
  17. $this->config = $config;
  18. }
  19. public function getCatalog()
  20. {
  21. try {
  22. $catalogApi = new \SquareConnect\Api\CatalogApi($this->apiClient);
  23. $products = $catalogApi->listCatalog();
  24. } catch (Exception $e) {
  25. error_log($e->getMessage());
  26. return 'ERROR: '.$e->getMessage();
  27. }
  28. $response = [];
  29. foreach($products['objects'] as $p) {
  30. if ($p['type'] === 'ITEM') {
  31. array_push($response, $p);
  32. }
  33. }
  34. return $response;
  35. }
  36. public function displayCCForm() {
  37. $context = $this->config + [
  38. 'testmode' => true
  39. ];
  40. return $this->twig->render('@Squarefront/cardentryform.twig', $context);
  41. }
  42. }