<?php
|
|
namespace JVBase\integrations\services;
|
use JVBase\integrations\Admin;
|
use JVBase\Instance;
|
use JVBase\integrations\Integrations;
|
use JVBase\integrations\OAuth;
|
use JVBase\integrations\OAuthCredentials;
|
use JVBase\integrations\Requests;
|
use JVBase\integrations\SyncToPost;
|
use JVBase\integrations\UserConnection;
|
use WP_Error;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
/**
|
* Helcim Integration Class
|
*
|
* Handles HelcimPay.js checkout, invoice retrieval, customer/card management,
|
* and bidirectional product sync via API token authentication.
|
*
|
* Helcim is the source of truth for invoices and orders.
|
* Products sync bidirectionally through the standard integration field flow.
|
*
|
* @since 1.0.0
|
*/
|
class Helcim extends Integrations
|
{
|
use Admin, Instance, OAuth, Requests, UserConnection, SyncToPost;
|
|
protected function __construct()
|
{
|
$this->service_name = 'helcim';
|
$this->title = 'Helcim';
|
$this->icon = 'currency-dollar';
|
|
$this->canSync = [
|
'initial' => true,
|
'update' => true,
|
'delete' => true,
|
];
|
|
$this->baseUrl = 'https://api.helcim.com/v2';
|
|
$this->defineFields();
|
$this->defineInstructions();
|
$this->defineActions();
|
|
parent::__construct();
|
}
|
protected function defineFields():void
|
{
|
$api_token = $this->addField(
|
'api_token',
|
'API Token',
|
'text',
|
[$this, 'testUserCanConnect']
|
);
|
$api_token->setSubType('password');
|
$api_token->setRequired();
|
$api_token->setHint('Found in Helcim Dashboard → Settings → API Access');
|
|
$currency = $this->addField(
|
'currency',
|
'Currency',
|
'select',
|
[$this, 'testUserSetup']
|
);
|
$currency->setOptions([
|
'CAD' => 'CAD',
|
'USD' => 'USD'
|
]);
|
$currency->setDefault('CAD');
|
|
$feeSaver = $this->addField(
|
'fee_saver',
|
'Fee Saver',
|
'true_false',
|
[$this, 'testUserSetup']
|
);
|
$feeSaver->setHint('Pass processing fees to customers? (Not compatible with Google Pay)');
|
|
$allowACH = $this->addField(
|
'allow_ach',
|
'Allow ACH/Bank Payments',
|
'true_false',
|
[$this, 'testUserSetup']
|
);
|
$allowACH->setHint('Enable bank account payments alongside credit card');
|
}
|
public function testUserCanConnect():bool
|
{
|
$user = get_current_user_id();
|
return $this->userCanConnect($user);
|
}
|
public function testUserSetup():bool
|
{
|
return $this->isSetUp() && $this->testUserCanConnect() && !empty($this->getApiToken());
|
}
|
|
protected function defineInstructions():void
|
{
|
$this->instructions = [
|
'Go to <a href="https://my.helcim.com" target="_blank">Helcim Dashboard</a>',
|
'Navigate to Settings → API Access',
|
'Create a new API Access Configuration',
|
'Enable permissions: General (Customers, Invoices, Products), Transaction Processing',
|
'Copy the API Token and paste it below',
|
];
|
}
|
|
protected function defineActions():void
|
{
|
$this->addAction(
|
'Initialize Checkout',
|
[$this, 'initializeCheckout'],
|
'initialize_checkout'
|
);
|
}
|
|
protected function initialize(): void
|
{
|
// 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.
|
}
|
|
protected function setContentTypes(): void
|
{
|
// TODO: Implement setContentTypes() method.
|
}
|
|
protected function formatForService(int $itemID, string $type = 'post'): array
|
{
|
// TODO: Implement formatForService() method.
|
}
|
/*************************************************************************
|
* UTILITY
|
*************************************************************************/
|
protected function getApiToken():string|false
|
{
|
return $this->loadCredentials()['api_token']??false;
|
}
|
}
|