Uname: Linux p3plzcpnl499967.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
Software: Apache
PHP version: 8.2.30 [ PHP INFO ] PHP os: Linux
Server Ip: 208.109.40.231
Your Ip: 216.73.216.26
User: nayff91c5tsx (10005085) | Group: nayff91c5tsx (10005085)
Safe Mode: OFF
Disable Function:
NONE

name : API.php
<?php

namespace FluentFormPro\Integrations\Salesflare;

if (!defined('ABSPATH')) {
    exit;
}

class API
{
    protected $apiUrl = 'https://api.salesflare.com/';
    
    protected $apiKey = '';
    
    protected $optionKey = '_fluentform_salesflare_settings';
    
    public function __construct($apiKey)
    {
        $this->apiKey = $apiKey;
    }
    
    public function make_request($action, $options, $method = 'GET', $headers = "")
    {
        $endpointUrl = $this->apiUrl . $action;
        
        if ($headers) {
            $args = [
                'headers' => $headers
            ];
        }
        
        if ($options) {
            $args['body'] = $options;
        }
        /* Execute request based on method. */
        switch ($method) {
            case 'POST':
                $response = wp_remote_post($endpointUrl, $args);
                break;
            
            case 'GET':
                $response = wp_remote_get($endpointUrl, $args);
                break;
        }
        if (is_wp_error($response)) {
            return [
                'error' => 'API_Error',
                'message' => $response->get_error_message()
            ];
        } elseif ($response['response']['code'] == 200) {
            return json_decode($response['body'], true);
        }
        
        $body = json_decode(wp_remote_retrieve_body($response), true);
        
        if (!empty($body['error'])) {
            $error = 'Unknown Error';
            if (isset($body['message'])) {
                $error = $body['message'];
            } elseif (!empty($body['error']['message'])) {
                $error = $body['error']['message'];
            }
            
            return new \WP_Error(423, $error);
        }
        
        return $body;
    }
    
    public function ping()
    {
        $headers = [
            'Authorization' => 'Bearer ' . $this->apiKey
        ];
        
        return $this->make_request('accounts', '', 'GET', $headers);
    }
    
    public function customFields()
    {
        $headers = [
            'Authorization' => 'Bearer ' . $this->apiKey
        ];
        
        return $this->make_request('customfields/contacts', '', 'GET', $headers);
    }
    
    public function createContact($addData)
    {
        $headers = [
            'Authorization' => 'Bearer ' . $this->apiKey,
            'Content-Type' => 'application/json'
        ];
        
        return $this->make_request('contacts', json_encode($addData), 'POST', $headers);
    }
    
    
}
© 2026 GrazzMean