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\ConstantContact;

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

use FluentForm\Framework\Helpers\ArrayHelper;

class API
{
    /**
     * Base Constant Contact API URL.
     *
     * @since  1.0
     * @var    string
     * @access protected
     */
    
    protected $api_url = 'https://api.constantcontact.com/v2/';
    protected $appKey = '4jzkpvcfcevnqu72kazejm66';
 
    /**
     * Constant Contact authentication data.
     *
     * @since  1.0
     * @access protected
     * @var    array $access_token Constant Contact authentication data.
     */
    protected $access_token = null;

    /**
     * Initialize Slack API library.
     *
     * @since  1.0
     *
     * @param  array $access_token Authentication token data.
     */
    public function __construct( $access_token = null ) {

        if(defined('FF_CC_APP_KEY')) {
            $this->appKey = FF_CC_APP_KEY;
        }
        $this->access_token = $access_token;

    }

    // To get the authorization url for authorization code
    public function makeAuthorizationUrl()
    {
        return $url = 'https://api.constantcontact.com/mashery/account/'. $this->appKey ;
    }

    public function auth_test()
    {
       return $account = $this->make_request('account/info', [], 'GET');
    }


    private function getApiUrl($resource)
    {
        $parameters = [];
        if ($resource =='contacts') {
            $actionName = 'ACTION_BY_OWNER';
            $actionName = apply_filters_deprecated(
                'ff_integration_constantcontact_action_by',
                [
                    $actionName
                ],
                FLUENTFORM_FRAMEWORK_UPGRADE,
                'fluentform/integration_constantcontact_action_by',
                'Use fluentform/integration_constantcontact_action_by instead of ff_integration_constantcontact_action_by.'
            );
            $parameters['action_by'] = apply_filters('fluentform/integration_constantcontact_action_by', $actionName);
        }
     
        $parameters['api_key']   = $this->appKey;
        
        $paramString = http_build_query($parameters);

        return $this->api_url . $resource . '?' . $paramString;
    }

    public function make_request($resource, $data, $method = 'GET')
    {
        $requestApi = $this->getApiUrl($resource, $data);
        
        $args =  array(
            'headers' => array(
                'Accept'        => 'application/json',
                'Content-Type'  => 'application/json',
                'Authorization' => 'Bearer'. ' ' .  $this->access_token
            ),
            'body'    => json_encode($data)
        );

       
        if ($method == 'GET') {
            unset($args['body']);
            $response = wp_remote_get($requestApi, $args);
        } else if ($method == 'POST') {
            $args['headers']['action_by'] = 'ACTION_BY_OWNER';
            $response = wp_remote_post($requestApi, $args);
        } else {
            return (new \WP_Error(423, 'Request method could not be found'));
        }

        /* If WP_Error, die. Otherwise, return decoded JSON. */
        if (is_wp_error($response)) {
            return (new \WP_Error(423, $response->get_error_message()));
        }

        return json_decode($response['body'], true);
    }
    
    public function get_lists(){
        return $this->make_request('lists', [], 'GET');
    }
    
    public function subscribeToList($data){
        return $this->make_request('contacts', $data, 'POST');
    }
    
    

}
© 2026 GrazzMean