Jake Vanderwerf
2026-08-25 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a
inc/rest/routes/IntegrationsHelcimRoutes.php
@@ -1,6 +1,9 @@
<?php
namespace JVBase\rest\routes;
use JVBase\base\Site;
use JVBase\Instance;
use JVBase\integrations\services\Helcim;
use JVBase\rest\Rest;
use JVBase\rest\Route;
use WP_REST_Request;
@@ -13,6 +16,7 @@
class IntegrationsHelcimRoutes extends Rest
{
   use Instance;
   public function registerRoutes(): void
   {
      Route::for('helcim/initialize-checkout')
@@ -56,6 +60,9 @@
   {
      $data    = $request->get_json_params();
      $user_id = get_current_user_id();
      if (!Site::hasIntegration('helcim')) {
         return $this->validationError(['message' => 'Helcim not setup']);
      }
      if (!$user_id) {
         return $this->unauthorized();
      }
@@ -65,7 +72,12 @@
      }
      try {
         $helcim = JVB()->connect('helcim');
         $helcim = Helcim::getInstance();
         if (!method_exists($helcim, 'resolveCustomerId') ||
            !method_exists($helcim, 'initializeCheckout')
         ) {
            return $this->validationError(['message' => 'Helcim not complete']);
         }
         // Auto-resolve customer ID from logged-in user
         if (empty($data['customerId']) && $user_id) {
@@ -96,9 +108,16 @@
      if (!$user_id) {
         return $this->validationError(['message' => 'Not logged in']);
      }
      if (!Site::hasIntegration('helcim')) {
         return $this->validationError(['message' => 'Helcim not setup']);
      }
      try {
         $helcim    = JVB()->connect('helcim');
         $helcim    = Helcim::getInstance();
         if (!method_exists($helcim, 'handleGetInvoices')) {
            return $this->validationError(['message' => 'Helcim not complete']);
         }
         $user      = get_userdata($user_id);
         $result    = $helcim->handleGetInvoices([
            'email' => $user->user_email,
@@ -122,8 +141,15 @@
         return $this->validationError(['message' => 'Invoice ID required']);
      }
      if (!Site::hasIntegration('helcim')) {
         return $this->validationError(['message' => 'Helcim not setup']);
      }
      try {
         $helcim = JVB()->connect('helcim');
         $helcim = Helcim::getInstance();
         if (!method_exists($helcim, 'handleGetInvoice')) {
            return $this->validationError(['message' => 'Helcim not complete']);
         }
         $result = $helcim->handleGetInvoice(['invoiceId' => $invoiceId]);
         return $this->success($result);
@@ -143,9 +169,15 @@
      if (!$user_id) {
         return $this->validationError(['message' => 'Not logged in']);
      }
      if (!Site::hasIntegration('helcim')) {
         return $this->validationError(['message' => 'Helcim not setup']);
      }
      try {
         $helcim = JVB()->connect('helcim');
         $helcim = Helcim::getInstance();
         if (!method_exists($helcim, 'handleGetCustomerCards')) {
            return $this->validationError(['message' => 'Helcim not complete']);
         }
         $result = $helcim->handleGetCustomerCards([
            'email' => get_userdata($user_id)->user_email,
         ]);
@@ -171,9 +203,15 @@
      if (empty($data['secretToken']) || empty($data['transactionData'])) {
         return $this->validationError(['message' => 'Missing secretToken or transactionData']);
      }
      if (!Site::hasIntegration('helcim')) {
         return $this->validationError(['message' => 'Helcim not setup']);
      }
      try {
         $helcim = JVB()->connect('helcim');
         $helcim = Helcim::getInstance();
         if (!method_exists($helcim, 'validateTransaction')) {
            return $this->validationError(['message' => 'Helcim not complete']);
         }
         $valid  = $helcim->validateTransaction(
            $data['secretToken'],
            $data['transactionData']