active-campaign-handler.php
3 years ago
forms-captcha.php
3 years ago
getresponse-handler.php
3 years ago
integration-base.php
3 years ago
mailchimp-handler.php
3 years ago
getresponse-handler.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Jet_Form_Builder\Integrations; |
| 4 | |
| 5 | /** |
| 6 | * GetResponse Handler |
| 7 | */ |
| 8 | |
| 9 | // If this file is called directly, abort. |
| 10 | if ( ! defined( 'WPINC' ) ) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Define Getresponse_Handler class |
| 16 | */ |
| 17 | class Getresponse_Handler extends Integration_Base { |
| 18 | |
| 19 | protected $api_base_url = 'https://api.getresponse.com/v3/'; |
| 20 | |
| 21 | /** |
| 22 | * Constructor for the class |
| 23 | * |
| 24 | * @param $api_key |
| 25 | */ |
| 26 | public function __construct( $api_key ) { |
| 27 | |
| 28 | if ( empty( $api_key ) ) { |
| 29 | return new \WP_Error( 'invalid_api_key' ); |
| 30 | } |
| 31 | |
| 32 | $this->api_key = $api_key; |
| 33 | $this->api_request_args = array( |
| 34 | 'headers' => array( |
| 35 | 'X-Auth-Token' => 'api-key ' . $api_key, |
| 36 | 'Content-Type' => 'application/json', |
| 37 | ), |
| 38 | ); |
| 39 | |
| 40 | } |
| 41 | |
| 42 | |
| 43 | public function get_all_data() { |
| 44 | $lists = $this->get_lists(); |
| 45 | $fields = $this->get_fields(); |
| 46 | |
| 47 | return ( empty( $lists ) && empty( $fields ) ) ? array() : array( |
| 48 | 'lists' => $lists, |
| 49 | 'fields' => $fields, |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | public function get_lists() { |
| 54 | $result = array(); |
| 55 | $lists = $this->request( 'campaigns' ); |
| 56 | |
| 57 | if ( ! empty( $lists ) ) { |
| 58 | foreach ( $lists as $list ) { |
| 59 | if ( ! is_array( $list ) ) { |
| 60 | continue; |
| 61 | } |
| 62 | if ( ! isset( $list['campaignId'] ) ) { |
| 63 | return array(); |
| 64 | } |
| 65 | |
| 66 | $result[ $list['campaignId'] ] = $list['name']; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return $result; |
| 71 | } |
| 72 | |
| 73 | public function get_fields() { |
| 74 | $result = array( |
| 75 | 'email' => array( |
| 76 | 'label' => esc_html__( 'Email', 'jet-form-builder' ), |
| 77 | 'required' => true, |
| 78 | ), |
| 79 | 'name' => array( |
| 80 | 'label' => esc_html__( 'Name', 'jet-form-builder' ), |
| 81 | 'required' => false, |
| 82 | ), |
| 83 | ); |
| 84 | |
| 85 | $custom_fields = $this->request( 'custom-fields' ); |
| 86 | |
| 87 | if ( ! empty( $custom_fields ) ) { |
| 88 | foreach ( $custom_fields as $field ) { |
| 89 | if ( ! isset( $field['customFieldId'] ) ) { |
| 90 | return array(); |
| 91 | } |
| 92 | $result[ $field['customFieldId'] ] = array( |
| 93 | 'label' => $field['name'], |
| 94 | 'required' => false, |
| 95 | ); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return $result; |
| 100 | } |
| 101 | } |
| 102 |