| | |
| | | <?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; |
| | |
| | | |
| | | class IntegrationsHelcimRoutes extends Rest |
| | | { |
| | | use Instance; |
| | | public function registerRoutes(): void |
| | | { |
| | | Route::for('helcim/initialize-checkout') |
| | |
| | | { |
| | | $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(); |
| | | } |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | 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, |
| | |
| | | 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); |
| | |
| | | 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, |
| | | ]); |
| | |
| | | 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'] |