Jake Vanderwerf
2026-09-18 a6413da67a4579866f0fd0323ddb23a7b6b9654a
inc/integrations/services/Helcim.php
@@ -28,10 +28,11 @@
 */
class Helcim extends Integrations
{
   use Admin, Instance, OAuth, Requests, UserConnection, SyncToPost;
   use Admin, Instance, Requests, UserConnection, SyncToPost;
   protected function __construct()
   {
      $this->canTest = true;
      $this->service_name = 'helcim';
      $this->title = 'Helcim';
      $this->icon = 'currency-dollar';
@@ -42,11 +43,11 @@
         'delete' => true,
      ];
      $this->baseUrl = 'https://api.helcim.com/v2';
      $this->apiVersion = 'v2';
      $this->baseUrl = sprintf('https://api.helcim.com/%s/', $this->apiVersion);
      $this->defineFields();
      $this->defineInstructions();
      $this->defineActions();
      parent::__construct();
   }
@@ -61,6 +62,9 @@
            $api_token->setSubType('password');
            $api_token->setRequired();
            $api_token->setHint('Found in Helcim Dashboard → Settings → API Access');
            $api_token->makeSetupField();
            $api_token->setHideStored();
            $this->updateField('api_token', $api_token);
         $currency = $this->addField(
            'currency',
@@ -73,6 +77,7 @@
               'USD' => 'USD'
            ]);
            $currency->setDefault('CAD');
            $currency->makeAdditionalField();
         $feeSaver = $this->addField(
            'fee_saver',
@@ -81,6 +86,7 @@
            [$this, 'testUserSetup']
         );
            $feeSaver->setHint('Pass processing fees to customers? (Not compatible with Google Pay)');
            $feeSaver->makeAdditionalField();
         $allowACH = $this->addField(
            'allow_ach',
@@ -89,6 +95,7 @@
            [$this, 'testUserSetup']
         );
            $allowACH->setHint('Enable bank account payments alongside credit card');
            $allowACH->makeAdditionalField();
      }
         public function testUserCanConnect():bool
         {
@@ -113,11 +120,21 @@
      protected function defineActions():void
      {
         $this->addAction(
            'Initialize Checkout',
            [$this, 'initializeCheckout'],
            'initialize_checkout'
         );
         if ($this->isSetUp()) {
            $this->addAction(
               'Sync to Helcim',
               [$this, 'syncToHelcim'],
               'sync_to_helcim',
               'upload-simple'
            );
            $this->addAction(
               'Sync to Site',
               [$this, 'syncToSite'],
               'sync_to_site',
               'download-simple'
            );
         }
      }
   protected function initialize(): void
@@ -125,30 +142,84 @@
      // TODO: Implement initialize() method.
   }
   protected function refreshAccessToken(OAuthCredentials $credentials): array
   {
      // TODO: Implement refreshAccessToken() method.
   }
   protected function getRequestHeaders(): array
   {
      // TODO: Implement getRequestHeaders() method.
   }
   protected function handleResponse(WP_Error|array $response, string $method, string $endpoint): array
   {
      // TODO: Implement handleResponse() method.
      return empty($this->getApiToken()) ? [] : [
         'api-token'    => $this->getApiToken(),
         'Accept'    => 'application/json',
      ];
   }
   protected function setContentTypes(): void
   {
      // TODO: Implement setContentTypes() method.
      $this->contentTypes = [
         'recurring' => $this->buildRecurringPaymentFields(),
         'product'   => $this->buildPaymentFields(),
         'customer'  => $this->buildCustomerFields(),
         'invoice'   => $this->buildInvoiceFields(),
      ];
   }
      protected function buildRecurringPaymentFields(): array
      {
         return [];
      }
      protected function buildPaymentFields(): array
      {
         return [];
      }
      protected function buildCustomerFields():array
      {
         return [];
      }
      protected function buildInvoiceFields():array
      {
         return [];
      }
   protected function formatForService(int $itemID, string $type = 'post'): array
   {
      return [];
      // TODO: Implement formatForService() method.
   }
   public function initializeCheckout():void
   {
   }
   public function syncToHelcim():void
   {
   }
   public function syncToSite():void
   {
   }
   /*************************************************************************
    * REQUESTS
   *************************************************************************/
   protected function handleResponse(WP_Error|array $response, string $method, string $endpoint): array
   {
      if (is_wp_error($response) && $response->get_error_message() === 'rate_limit_exceeded') {
         return $this->response(false, 'Rate limit exceeded');
      }
      return match ($endpoint) {
         'connection-test' => $this->response(true,'Connection successful', $response),
         default => $this->response(false, 'Unhandled response for '.$endpoint),
      };
   }
   protected function performConnectionTest(): bool
   {
      $response = $this->getRequest(
         'connection-test'
      );
      error_log('Helcim connection test: '.print_r($response, true));
      return $response['success']??false;
   }
   /*************************************************************************
    * UTILITY
   *************************************************************************/