Plugin Directory

Changeset 3211366


Ignore:
Timestamp:
12/21/2024 04:43:52 AM (12 months ago)
Author:
anthonyeden
Message:

Version 2.5.0

Location:
profiler-donations-gravityforms
Files:
9 edited
23 copied

Legend:

Unmodified
Added
Removed
  • profiler-donations-gravityforms/tags/2.5.0/README.md

    r2698068 r3211366  
    1515*   [Gravity Forms](http://www.gravityforms.com)
    1616*   Payment Gateway integration with Gravity Forms (must be pre-existing and use standard Gravity Forms payment hooks and database fields)
    17   * For Australian non-profits, we recommend the official Gravity Forms Stripe plugin
     17  * We recommend the official Gravity Forms Stripe plugin
    1818*   Full administrative access to Profiler
    1919*   CURL and XML Enabled on Web Server
  • profiler-donations-gravityforms/tags/2.5.0/class-profilercommon.php

    r3136560 r3211366  
    77    protected $_title = "Profiler / Gravity Forms - Integration Feed";
    88
     9    protected $api_type = "form"; // form or json
     10    protected $api_domain = "profilersystem.com";
    911    protected $apifield_apikey = "apikey";
    1012    protected $apifield_apipass = "apipass";
     
    2729        add_filter('gform_stripe_charge_description',       array($this, 'stripe_payment_description'), 10, 5);
    2830        add_filter('gform_stripe_payment_element_initial_payment_information', array($this, 'stripe_elements_setup'), 10, 3);
    29     }
     31
     32        // Metabox for Profiler Logs
     33        add_filter('gform_entry_detail_meta_boxes',         array($this, 'meta_box_entry'), 10, 3);
     34    }
     35
     36    public function get_menu_icon() {
     37        //return 'dashicons-admin-generic';
     38        return plugins_url('icon-profiler.png', __FILE__);
     39    }
    3040
    3141    public function feed_settings_fields() {
     
    6575            "name" => "profiler".$this->gffield_legacyname."_instancedomainname",
    6676            "required" => true,
    67             "tooltip" => "Your Instance Domain Name can be found in your login URL: e.g. 'https://instance.profiler.net.au/' is 'instance.profiler.net.au'",
    68         );
    69        
    70         $fields[] = array(
    71             "label" => 'Profiler Database Name',
    72             "type" => "text",
    73             "name" => "profiler".$this->gffield_legacyname."_dbname",
    74             "required" => true,
    75         );
     77            "tooltip" => "Your Instance Domain Name can be found in your login URL: e.g. 'https://instance.profilersystem.com/' is 'instance.profilesystem.com'",
     78        );
     79       
     80        if($this->api_type !== 'json') {
     81            $fields[] = array(
     82                "label" => 'Profiler Database Name',
     83                "type" => "text",
     84                "name" => "profiler".$this->gffield_legacyname."_dbname",
     85                "required" => true,
     86            );
     87        }
    7688       
    7789        $fields[] = array(
     
    138150                    // Loop over mailing list fields
    139151   
     152                    if($this->api_type !== 'json') {
     153                        $fields[] = array(
     154                            "label" => 'Mailing List #'.$i.': UDF',
     155                            "type" => "select",
     156                            "name" => "profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf",
     157                            "required" => false,
     158                            "tooltip" => "Pick the Profiler User Defined Field you wish to use for this mailing",
     159                            "choices" => $userdefinedfields,
     160                        );
     161                    }
     162
    140163                    $fields[] = array(
    141                         "label" => 'Mailing List #'.$i.': UDF',
    142                         "type" => "select",
    143                         "name" => "profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf",
    144                         "required" => false,
    145                         "tooltip" => "Pick the Profiler User Defined Field you wish to use for this mailing",
    146                         "choices" => $userdefinedfields,
    147                     );
    148    
    149                     $fields[] = array(
    150                         "label" => 'Mailing List #'.$i.': UDF Text',
     164                        "label" => ($this->api_type == 'json' ? 'Mailing List #'.$i.': Mailing Type Code' : 'Mailing List #'.$i.': UDF Text'),
    151165                        "type" => "text",
    152166                        "name" => "profiler".$this->gffield_legacyname."_mailinglist_".$i."_udftext",
    153167                        "required" => false,
    154                         "tooltip" => "Enter the string Profiler is expecting in this UDF",
     168                        "tooltip" => ($this->api_type == 'json' ? "Enter the Profiler Mailing Type Code" : "Enter the string Profiler is expecting in this UDF") . ". This field also accept post meta merge fields in this format: {postmeta:meta_field_name}",
    155169                    );
    156    
     170
    157171                    $fields[] = array(
    158172                        "label" => 'Mailing List #'.$i.': Field',
     
    161175                        "tooltip" => 'Link it to a checkbox field - when checked, the mailing will be sent',
    162176                        "required" => false,
    163                         "choices" => $checkboxFields
     177                        "choices" => array_merge($checkboxRadioFields, array(array("value" => "always", "label" => "Always Subscribe"))),
    164178                    );
    165179                }
     
    203217
    204218        $fields[] = array(
    205             "label" => 'Profiler Logs',
    206             "type" => "select",
    207             "name" => "profiler".$this->gffield_legacyname."_logs",
    208             "tooltip" => 'Link it to a Hidden field that will hold Profiler Response Logs',
    209             "required" => false,
    210             "choices" => $hiddenFields
    211         );
    212        
    213         $fields[] = array(
    214219            "label" => 'SSL Mode',
    215220            "type" => "select",
     
    259264        $postData = array();
    260265
    261         $postData['DB'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_dbname'];
     266        if($this->api_type !== 'json') {
     267            $postData['DB'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_dbname'];
     268        }
    262269        $postData[$this->apifield_apikey] = $feed['meta']['profiler'.$this->gffield_legacyname.'_apikey'];
    263270        $postData[$this->apifield_apipass] = $feed['meta']['profiler'.$this->gffield_legacyname.'_apipass'];
     
    265272        if(empty($feed['meta']['profiler'.$this->gffield_legacyname.'_instancedomainname']) && !empty($feed['meta']['profiler'.$this->gffield_legacyname.'_instancename'])) {
    266273            // Respect the setting from when we only accepted the first part of the domain name
    267             $feed['meta']['profiler'.$this->gffield_legacyname.'_instancedomainname'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_instancename'] . ".profiler.net.au";
     274            $feed['meta']['profiler'.$this->gffield_legacyname.'_instancedomainname'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_instancename'] . ".profilersystem.com";
    268275        }
    269276
     
    282289            if(isset($field['pf_apifield']) && $this->get_field_value($form, $entry, $feed['meta'][$field['name']]) != '') {
    283290                $postData[$field['pf_apifield']] = trim($this->get_field_value($form, $entry, $feed['meta'][$field['name']]));
     291
     292                // Auto formatting for phone fields
     293                if(isset($field['auto_format']) && $field['auto_format'] == "phone") {
     294                    $postData[$field['pf_apifield']] = $this->auto_format_phone($postData[$field['pf_apifield']]);
     295                }
    284296            }
    285297        }
     
    301313        if($this->apifield_formurl === true && !empty($feed['meta']['profiler'.$this->gffield_legacyname.'_userdefined_formurl'])) {
    302314            $postData['userdefined' . $feed['meta']['profiler'.$this->gffield_legacyname.'_userdefined_formurl']] = $entry['source_url'];
     315        } else if($this->apifield_formurl !== false) {
     316            $postData[$this->apifield_formurl] = $entry['source_url'];
    303317        }
    304318
     
    322336            }
    323337
    324             if($feed['meta']['profilerdonation_userdefined_gatewaycustomerid'] !== "" && isset($payment_intent)) {
     338            if(isset($payment_intent)) {
    325339                // Gateway Customer ID
    326                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaycustomerid']] = $payment_intent->customer;
    327             }
    328 
    329             if($feed['meta']['profilerdonation_userdefined_gatewaycardtoken'] !== "" && isset($payment_intent)) {
     340                $postData['paymentGatewayCustomerId'] = $payment_intent->customer;
     341            }
     342
     343            if(isset($payment_intent)) {
    330344                // Gateway Card Token
    331345                try {
    332                     $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaycardtoken']] = $payment_intent->charges->data[0]->payment_method;
     346                    $postData['gatewayCardToken'] = $payment_intent->charges->data[0]->payment_method;
    333347                } catch(Exception $e) {
    334348                    error_log("STRIPE/PROFILER CARD TOKEN ERROR: " . print_r($e, true));
     
    338352
    339353        // PayFURL-supplied Gateway Token
    340         if($feed['meta']['profilerdonation_userdefined_gatewaycardtoken'] !== "" && isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_payment_method_id_provider'])) {
     354        if(isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_payment_method_id_provider'])) {
    341355            $payfurl_provider_token = $_POST['payfurl_payment_details']['captured_payment']['payfurl_payment_method_id_provider'];
    342            
     356
    343357            if(!empty($payfurl_provider_token)) {
    344                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaycardtoken']] = $payfurl_provider_token;
     358                $postData['gatewayCardToken'] = $payfurl_provider_token;
    345359            }
    346360        }
     
    349363        if($this->supports_custom_fields === true && !empty($feed['meta']['profiler_customfields_count'])) {
    350364            for($i = 1; $i <= $feed['meta']['profiler_customfields_count']; $i++) {
    351                 $postData["userdefined" . $feed['meta']["profiler_customfield_".$i."_pffield"]] = trim($this->get_field_value($form, $entry, $feed['meta']["profiler_customfield_".$i."_gffield"]));
     365
     366                $value = trim($this->get_field_value($form, $entry, $feed['meta']["profiler_customfield_".$i."_gffield"]));
     367
     368                if($this->api_type == 'json') {
     369                    if(!isset($postData['userDefinedFields'])) {
     370                        $postData['userDefinedFields'] = array();
     371                    }
     372
     373                    $postData['userDefinedFields']["userDefined" . $feed['meta']["profiler_customfield_".$i."_pffield"]] = $value;
     374
     375                } else {
     376                    $postData["userdefined" . $feed['meta']["profiler_customfield_".$i."_pffield"]] = $value;
     377                }
     378
     379               
    352380            }
    353381        }
     
    358386                // Loop over mailing list fields
    359387                $mailingFieldValue = $this->get_field_value($form, $entry, $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_field"]);
    360                 $udf = $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf"];
    361388                $udfText = $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_udftext"];
    362389
    363                 if(!empty($udf) && !empty($udfText) && !empty($mailingFieldValue)) {
    364                     $postData['userdefined' . $udf] = $udfText;
    365                 }
    366 
     390                // Allow merging post meta fields into $udfText
     391                if(isset($entry['post_id']) && !empty($entry['post_id'])) {
     392                    $post_id = $entry['post_id'];
     393                } else {
     394                    global $post;
     395                    if(isset($post)) {
     396                        $post_id = $post->ID;
     397                    }
     398                }
     399
     400                if(isset($post_id)) {
     401                    preg_match_all("/{postmeta:(.*?)}/", $udfText, $matches);
     402
     403                    if(is_array($matches) && isset($matches[1])) {
     404                        foreach($matches[1] as $match) {
     405                            $post_meta = get_post_meta($post_id, $match, true);
     406                            $udfText = str_replace("{postmeta:".$match."}", $post_meta, $udfText);
     407                        }
     408                    }
     409                }
     410
     411                if($this->api_type == 'json') {
     412
     413                    if(!isset($postData['mailingList'])) {
     414                        $postData['mailingList'] = '';
     415                    }
     416
     417                    if(!empty($udfText) && (!empty($mailingFieldValue) || $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_field"] == 'always')) {
     418                        $postData['mailingList'] .= (!empty($postData['mailingList']) ? ',' : '') . $udfText;
     419                    }
     420
     421                } else {
     422                    $udf = $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf"];
     423
     424                    if(!empty($udf) && !empty($udfText) && (!empty($mailingFieldValue) || $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_field"] == 'always')) {
     425                        $postData['userdefined' . $udf] = $udfText;
     426                    }
     427                }
    367428            }
    368429        }
     
    386447        $postData = apply_filters('profiler_integration_api_request_data', $postData, $form, $entry, $this->apifield_endpoint);
    387448
     449        // Update URL for newer APIs
     450        if($this->api_domain !== 'profilersystem.com') {
     451            $API_URL = str_replace(".profilersystem.com", "." . $this->api_domain, $API_URL);
     452        }
     453
    388454        // Send data to Profiler
    389455        $pfResponse = $this->sendDataToProfiler($API_URL, $postData, $feed['meta']['profiler'.$this->gffield_legacyname.'_sslmode']);
     
    391457        if($fromValidatorProcessPFGateway === false) {
    392458            // Save Profiler response data back to the form entry
    393             $logsToStore = json_encode($pfResponse);
     459            $logsToStore = json_encode($pfResponse, JSON_PRETTY_PRINT);
    394460            $logsToStore = str_replace($postData['cardnumber'], "--REDACTED--", $logsToStore);
    395461            $logsToStore = str_replace($postData[$this->apifield_apikey], "--REDACTED--", $logsToStore);
    396462            $logsToStore = str_replace($postData[$this->apifield_apipass], "--REDACTED--", $logsToStore);
    397             $entry[$feed['meta']['profiler'.$this->gffield_legacyname.'_logs']] = htmlentities($logsToStore);
    398             GFAPI::update_entry($entry);
     463            gform_add_meta($entry["id"], "profiler_logs", $logsToStore, $form['id']);
    399464
    400465            if(method_exists($this, 'process_feed_success')) {
    401466                $this->process_feed_success($feed, $entry, $form, $pfResponse, $postData);
    402             }   
     467            }
     468
    403469        } else {
    404470            return $pfResponse;
     
    651717        }
    652718
     719        if(isset($profiler_query['DB'])) {
     720            $url .= '?' . http_build_query(array("DB" => $profiler_query['DB'], "Call" => 'submit'));
     721        }
     722
    653723        $ch = curl_init();
    654         curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query(array("DB" => $profiler_query['DB'], "Call" => 'submit')));
     724        curl_setopt($ch, CURLOPT_URL, $url);
     725        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    655726        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    656         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen(http_build_query($profiler_query))));
    657         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($profiler_query));
    658         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    659        
     727
    660728        if($ssl_mode == "bundled_ca") {
    661729            // Use the CA Cert bundled with this plugin
     
    669737        }
    670738
     739        if($this->api_type === 'json') {
     740            // JSON POST
     741            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($profiler_query));
     742            curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
     743
     744        } else {
     745            // FORM POST
     746            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen(http_build_query($profiler_query))));
     747            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($profiler_query));
     748        }
     749
    671750        $result = curl_exec($ch);
    672751        $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    673        
     752
    674753        if(curl_error($ch)) {
    675754            $cURL_error = curl_error($ch);
     
    677756            $cURL_error = null;
    678757        }
    679        
     758
    680759        curl_close($ch);
    681        
     760
     761        if($this->api_type === 'json') {
     762            $data_decoded = json_decode($result, true);
     763        } else {
     764            $data_decoded = json_decode(json_encode((array)simplexml_load_string($result)), true);
     765        }
     766
    682767        return array(
    683768            "httpstatus" => $status_code,
     769            "url" => $url,
    684770            "dataSent" => $profiler_query,
    685771            "data" => $result,
    686             "dataXML" => simplexml_load_string($result),
    687             "dataArray" => json_decode(json_encode((array)simplexml_load_string($result)), 1),
     772            "dataArray" => $data_decoded,
    688773            "cURLError" => $cURL_error,
    689774            "cURL_SSL_Mode" => $ssl_mode,
     775            "api_type" => $this->api_type,
    690776        );
    691777    }
     
    707793
    708794        foreach($pfResponse['dataSent'] as $key => $val) {
    709             if($key == "apikey" || $key == "apipass" || $key == "cardnumber" || $key == "api_user" || $key == "api_pass" || $key == $this->apifield_apikey || $key == $this->apifield_apipass) {
     795            if($key == "apikey" || $key == "apipass" || $key == "apipassword" || $key == "cardnumber" || $key == "api_user" || $key == "api_pass" || $key == $this->apifield_apikey || $key == $this->apifield_apipass) {
    710796                $val = "--REDACTED--";
    711797            }
     
    10231109
    10241110    }
     1111
     1112    public function meta_box_entry($meta_boxes, $entry, $form) {
     1113        // Custom Metabox
     1114
     1115        if($this->get_active_feeds($form['id'])) {
     1116
     1117            $profiler_logs_meta = gform_get_meta($entry['id'], 'profiler_logs');
     1118
     1119            if(!empty($profiler_logs_meta)) {
     1120                $meta_boxes[$this->_slug] = array(
     1121                    'title'    => 'Profiler API',
     1122                    'callback' => array($this, 'meta_box_entry_render'),
     1123                    'context'  => 'side',
     1124                    'callback_args' => array($entry, $form),
     1125                );
     1126            }
     1127        }
     1128
     1129        return $meta_boxes;
     1130    }
     1131
     1132    public function meta_box_entry_render($data) {
     1133        // Render the Custom Metabox
     1134        $html = '';
     1135
     1136        $meta_fields = array(
     1137            "profiler_integrationid" => "Integration ID",
     1138            "profiler_integration_guid" => "Integration GUID",
     1139            "profiler_logs" => "Profiler API Logs",
     1140        );
     1141
     1142        foreach($meta_fields as $field_name => $field_title) {
     1143
     1144            $meta_value = gform_get_meta($data['entry']['id'], $field_name);
     1145
     1146            if(!empty($meta_value)) {
     1147                $html .= '<p><strong>'.$field_title.'</strong>:<br /><pre style="width: 100%; overflow-x: scroll;">'.esc_html($meta_value).'</pre></p>';
     1148            }
     1149        }
     1150
     1151        echo $html;
     1152    }
     1153
     1154    private function auto_format_phone($phone_number_original) {
     1155        // This function auto-formats a phone number into an Australian format (0000 000 000 or 00 0000 0000)
     1156
     1157        // Remove certain characters
     1158        $phone_number = str_replace(array(" ", "-", "(", ")"), array("", "", "", ""), $phone_number_original);
     1159
     1160        // Remove +61 prefix
     1161        if(substr($phone_number, 0, 3) == "+61") {
     1162            $phone_number = substr($phone_number, 3);
     1163
     1164            if(strlen($phone_number) === 9) {
     1165                $phone_number = "0" . $phone_number;
     1166            }
     1167        }
     1168
     1169        // International number. Return as-is
     1170        if(substr($phone_number, 0, 1) == "+") {
     1171            return $phone_number;
     1172        }
     1173
     1174        // Probably an Australian number
     1175        if(strlen($phone_number) == 10) {
     1176            // 0000 000 000
     1177            if(substr($phone_number, 0, 2) == "04") {
     1178                $phone_number = substr($phone_number, 0, 4) . " " . substr($phone_number, 4, 3) . " " . substr($phone_number, 7);
     1179                return $phone_number;
     1180            }
     1181
     1182            // 00 0000 0000
     1183            $phone_number = substr($phone_number, 0, 2) . " " . substr($phone_number, 2, 4) . " " . substr($phone_number, 6);
     1184            return $phone_number;
     1185        }
     1186
     1187        // Probably Australian landline with no area prefix
     1188        if(strlen($phone_number) == 8) {
     1189            // Adjust to 0000 0000 format
     1190            $phone_number = substr($phone_number, 0, 4) . " " . substr($phone_number, 4);
     1191        }
     1192
     1193        return $phone_number;
     1194    }
    10251195}
    10261196
  • profiler-donations-gravityforms/tags/2.5.0/class-profilerdonate-gfaddon.php

    r3136560 r3211366  
    1010    protected static $_instance = null;
    1111
    12     protected $apifield_endpoint = "/ProfilerAPI/Legacy/";
    13     protected $apifield_apikey = "apikey";
    14     protected $apifield_apipass = "apipass";
    15     protected $apifield_ipaddress = 'udf';
    16     protected $apifield_formurl = true;
     12    protected $api_type = "json";
     13    protected $api_domain = "profilersoftware.com";
     14    protected $apifield_endpoint = "/ProfilerAPI/RapidEndpoint/";
     15    protected $apifield_apikey = "apiuser";
     16    protected $apifield_apipass = "apipassword";
     17    protected $apifield_ipaddress = 'requestIPAddress';
     18    protected $apifield_formurl = 'pageURL';
    1719    protected $gffield_legacyname = "donation";
    1820    protected $supports_custom_fields = true;
     
    129131            "required" => false,
    130132            "choices" => $field_settings,
    131             "tooltip" => "The value of this field must be set to 'monthly' or 'yearly'. This field will be used if 'Donation Type' is set to 'regular'."
     133            "tooltip" => "The value of this field must be set to 'weekly', 'monthly' or 'yearly'. This field will be used if 'Donation Type' is set to 'regular'."
    132134        );
    133135       
     
    139141            "choices" => $product_field_settings,
    140142            "tooltip" => "This amount field will be used if Donation Type is set to 'regular'.",
    141         );
    142 
    143         $fields[] = array(
    144             "label" => 'UDF: Pledge Type ID',
    145             "type" => "select",
    146             "name" => "profilerdonation_userdefined_pledgetypeid",
    147             "required" => false,
    148             "tooltip" => "Pick the Profiler User Defined Field you wish the Pledge Type ID to be sent to",
    149             "choices" => $userdefinedfields,
    150143        );
    151144
     
    182175            "required" => false,
    183176            "choices" => $field_settings,
    184             "pf_apifield" => "firstname",
     177            "pf_apifield" => "firstName",
    185178        );
    186179       
     
    193186            "pf_apifield" => "surname",
    194187        );
     188
     189        $fields[] = array(
     190            "label" => 'Client: Gender',
     191            "type" => "select",
     192            "name" => "profilerdonation_clientgender",
     193            "required" => false,
     194            "choices" => $field_settings,
     195            "pf_apifield" => "clientGender",
     196            "tooltip" => "Gender values are defined in Profiler in Setup > Client > Gender.",
     197        );
    195198       
    196199        $fields[] = array(
     
    263266            "required" => false,
    264267            "choices" => $field_settings,
    265             "pf_apifield" => "phoneah",
    266         );
    267        
     268            "pf_apifield" => "phoneAH",
     269        );
     270
    268271        $fields[] = array(
    269272            "label" => 'Client: Business Phone',
     
    272275            "required" => false,
    273276            "choices" => $field_settings,
    274             "pf_apifield" => "phonebus",
    275         );
    276        
     277            "pf_apifield" => "phoneBus",
     278            "auto_format" => "phone",
     279        );
     280
    277281        $fields[] = array(
    278282            "label" => 'Client: Mobile Phone',
     
    281285            "required" => false,
    282286            "choices" => $field_settings,
    283             "pf_apifield" => "phonemobile",
    284         );
    285        
     287            "pf_apifield" => "phoneMobile",
     288            "auto_format" => "phone",
     289        );
     290
     291        $fields[] = array(
     292            "label" => 'Client: Phone',
     293            "type" => "select",
     294            "name" => "profilerdonation_clientphonemobile",
     295            "required" => false,
     296            "choices" => $field_settings,
     297            "pf_apifield" => "phoneMobile",
     298            "auto_format" => "phone",
     299        );
     300
    286301        $fields[] = array(
    287302            "label" => 'Client: Website',
     
    323338            "required" => false,
    324339            "choices" => $field_settings,
    325             "pf_apifield" => "comments",
    326         );
    327 
    328         $fields[] = array(
    329             "label" => 'UDF: Receipt Name',
    330             "type" => "select",
    331             "name" => "profilerdonation_userdefined_receiptname",
    332             "required" => false,
    333             "tooltip" => "Pick the Profiler User Defined Field you wish the donation receipt name to be sent to",
    334             "choices" => $userdefinedfields,
     340        );
     341
     342        $fields[] = array(
     343            "label" => 'Extra Comments Text',
     344            "type" => "textarea",
     345            "name" => "profilerdonation_commentsextra",
     346            "required" => false,
     347            "class" => "merge-tag-support",
     348            "tooltip" => "This is extra text to be sent to Profiler in the Comments field. Youc an include Gravity Forms Merge Fields in this textarea to accept additional user input.",
     349        );
     350
     351        $fields[] = array(
     352            "label" => 'Interaction: Type',
     353            "type" => "select",
     354            "name" => "profilerdonation_interaction_type",
     355            "required" => false,
     356            "choices" => $field_settings,
     357            "pf_apifield" => "interactionType",
     358            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Type here, and your Interaction Text below. This is separate to the 'Comments' field above.",
     359        );
     360
     361        $fields[] = array(
     362            "label" => 'Interaction: Text',
     363            "type" => "select",
     364            "name" => "profilerdonation_interaction_text",
     365            "required" => false,
     366            "choices" => $field_settings,
     367            "pf_apifield" => "interactionText",
     368            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Text here, and your Interaction Type above. This is separate to the 'Comments' field above.",
     369        );
     370
     371        $fields[] = array(
     372            "label" => 'Interaction: Tag',
     373            "type" => "select",
     374            "name" => "profilerdonation_interaction_tag",
     375            "required" => false,
     376            "choices" => $field_settings,
     377            "pf_apifield" => "interactionTag",
     378            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Text and Interaction Type above, and your Interaction Tag here. This is separate to the 'Comments' field above.",
     379        );
     380
     381        $fields[] = array(
     382            "label" => 'Interaction: Sub-Tag',
     383            "type" => "select",
     384            "name" => "profilerdonation_interaction_subtag",
     385            "required" => false,
     386            "choices" => $field_settings,
     387            "pf_apifield" => "interactionSubTag",
     388            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Text and Interaction Type above, and your Interaction Sub-Tag here. This is separate to the 'Comments' field above.",
     389        );
     390
     391        $fields[] = array(
     392            "label" => 'Role: Add Role By Role Name',
     393            "type" => "select",
     394            "name" => "profilerdonation_role_name",
     395            "required" => false,
     396            "choices" => $field_settings,
     397            "pf_apifield" => "roleName",
     398            "tooltip" => "If you wish to add a Role to a Client by Role Name, enter the Role Name here.",
     399        );
     400
     401        $fields[] = array(
     402            "label" => 'Role: Add Role By Role ID',
     403            "type" => "select",
     404            "name" => "profilerdonation_role_id",
     405            "required" => false,
     406            "choices" => $field_settings,
     407            "pf_apifield" => "roleId",
     408            "tooltip" => "If you wish to add a Role to a Client by Role ID, enter the Role ID here.",
    335409        );
    336410
     
    341415            "required" => false,
    342416            "choices" => $field_settings,
    343         );
    344        
    345         $fields[] = array(
    346             "label" => 'UDF: Donation Source Code',
    347             "type" => "select",
    348             "name" => "profilerdonation_userdefined_sourcecode",
    349             "required" => false,
    350             "tooltip" => "Pick the Profiler User Defined Field you wish the donation source code to be sent to",
    351             "choices" => $userdefinedfields,
    352         );
    353        
     417            "pf_apifield" => "receiptName",
     418        );
     419
    354420        $fields[] = array(
    355421            "label" => 'Donation Source Code - Default Value',
     
    374440                + self::$_instance->formFields("Form Field: "),
    375441        );
    376        
    377         $fields[] = array(
    378             "label" => 'UDF: Pledge Source Code',
    379             "type" => "select",
    380             "name" => "profilerdonation_userdefined_pledgesourcecode",
    381             "required" => false,
    382             "tooltip" => "Pick the Profiler User Defined Field you wish the pledge source code to be sent to",
    383             "choices" => $userdefinedfields,
    384         );
    385        
     442
    386443        $fields[] = array(
    387444            "label" => 'Pledge Source Code - Default Value',
     
    406463                + self::$_instance->formFields("Form Field: "),
    407464        );
    408        
    409         $fields[] = array(
    410             "label" => 'UDF: Pledge Acquisition Code',
    411             "type" => "select",
    412             "name" => "profilerdonation_userdefined_pledgeacquisitioncode",
    413             "required" => false,
    414             "tooltip" => "Pick the Profiler User Defined Field you wish the pledge acquisition code to be sent to",
    415             "choices" => $userdefinedfields,
    416         );
    417        
     465
    418466        $fields[] = array(
    419467            "label" => 'Pledge Acquisition Code - Default Value',
     
    425473
    426474        $fields[] = array(
    427             "label" => 'UDF: Client Acquisition',
    428             "type" => "select",
    429             "name" => "profilerdonation_userdefined_clientacquisitioncode",
    430             "required" => false,
    431             "tooltip" => "Pick the Profiler User Defined Field you wish the client acquisition code to be sent to.",
    432             "choices" => $userdefinedfields,
    433         );
    434 
    435         $fields[] = array(
    436475            "label" => 'Client Acquisition Field',
    437476            "type" => "select",
     
    441480            "choices" => $field_settings
    442481        );
    443 
    444         $fields[] = array(
    445             "label" => 'UDF: Donation Purpose',
    446             "type" => "select",
    447             "name" => "profilerdonation_userdefined_donationpurposecode",
    448             "required" => false,
    449             "tooltip" => "Pick the Profiler User Defined Field you wish the donation's purpose code to be sent to",
    450             "choices" => $userdefinedfields,
    451         );
    452482       
    453483        $fields[] = array(
     
    461491
    462492        $fields[] = array(
    463             "label" => 'UDF: Donation Tag',
    464             "type" => "select",
    465             "name" => "profilerdonation_userdefined_donationtagcode",
    466             "required" => false,
    467             "tooltip" => "Pick the Profiler User Defined Field you wish the donation's tag code to be sent to. Do not set this up if you use Tag Automation within Profiler.",
    468             "choices" => $userdefinedfields,
    469         );
    470 
    471         $fields[] = array(
    472493            "label" => 'Donation Tag Field',
    473494            "type" => "select",
     
    479500
    480501        $fields[] = array(
    481             "label" => 'UDF: Client Preferred Contact Method',
    482             "type" => "select",
    483             "name" => "profilerdonation_userdefined_clientpreferredcontactmethod",
    484             "required" => false,
    485             "tooltip" => "Pick the Profiler User Defined Field you wish the client's preferred contact method to be sent to",
    486             "choices" => $userdefinedfields,
    487         );
    488        
     502            "label" => 'Interaction: Membership/Regular Mapping Text',
     503            "type" => "select",
     504            "name" => "profilerdonation_membership_mapping_text",
     505            "required" => false,
     506            "choices" => $field_settings,
     507            "pf_apifield" => "membershipMappingText",
     508            "tooltip" => "If you configure a 'Membership/Regular Type Map' in Profiler, you can use this field to perform the Mapping.",
     509        );
     510
     511        $fields[] = array(
     512            "label" => 'Payment Split-Out Text',
     513            "type" => "select",
     514            "name" => "profilerdonation_payment_split_out_text",
     515            "required" => false,
     516            "choices" => $field_settings,
     517            "pf_apifield" => "splitOutText",
     518            "tooltip" => "In Profiler, you can setup a text mapping for a Split / Breakdown Payment. If configured, it uses the text in this field to perform the split. For example, a Payment comes in for 100 and split is setup in Profiler for word POSTAGE, the payment recorded in Profiler will have separate amounts for two source codes.",
     519        );
     520
    489521        $fields[] = array(
    490522            "label" => 'Client Preferred Contact Method Field',
     
    497529
    498530        $fields[] = array(
    499             "label" => 'UDF: Client Privacy Preference',
    500             "type" => "select",
    501             "name" => "profilerdonation_userdefined_clientprivacypreference",
    502             "required" => false,
    503             "tooltip" => "Pick the Profiler User Defined Field you wish the client's privacy preference (true/false) to be sent to",
    504             "choices" => $userdefinedfields,
    505         );
    506 
    507         $fields[] = array(
    508531            "label" => 'Client Privacy Preference Field',
    509532            "type" => "select",
     
    512535            "tooltip" => "If this checkbox is true, this client will be marked as 'private'.",
    513536            "choices" => $checkboxFields
    514         );
    515 
    516         $fields[] = array(
    517             "label" => 'UDF: Client IP Address',
    518             "type" => "select",
    519             "name" => "profilerdonation_userdefined_clientip",
    520             "required" => false,
    521             "tooltip" => "Pick the Profiler User Defined Field you wish the client's IP address to be sent to",
    522             "choices" => $userdefinedfields,
    523         );
    524        
    525         $fields[] = array(
    526             "label" => 'UDF: Gateway Transaction ID / Gateway Response',
    527             "type" => "select",
    528             "name" => "profilerdonation_userdefined_gatewaytransactionid",
    529             "required" => false,
    530             "tooltip" => "Pick the Profiler User Defined Field you wish the gateway transaction ID to be sent to (certain gateways only)",
    531             "choices" => $userdefinedfields,
    532         );
    533 
    534         $fields[] = array(
    535             "label" => 'UDF: Payment Gateway ID Used',
    536             "type" => "select",
    537             "name" => "profilerdonation_userdefined_paymentgatewayidused",
    538             "required" => false,
    539             "tooltip" => "Pick the Profiler User Defined Field you wish the payment gateway ID to be sent to",
    540             "choices" => $userdefinedfields,
    541537        );
    542538
     
    558554            "choices" => $field_settings
    559555        );
    560 
    561         if(function_exists('gf_stripe') || class_exists('GF_PayFURL')) {
    562             // Stripe & PayFURL only fields
    563             $fields[] = array(
    564                 "label" => 'UDF: Payment Gateway Card Token',
    565                 "type" => "select",
    566                 "name" => "profilerdonation_userdefined_gatewaycardtoken",
    567                 "required" => false,
    568                 "tooltip" => "Pick the Profiler User Defined Field you wish to send the payment gateway Card Token to",
    569                 "choices" => $userdefinedfields,
    570             );
    571         }
    572    
    573         if(function_exists('gf_stripe')) {
    574             // Stripe only fields
    575             $fields[] = array(
    576                 "label" => 'UDF: Payment Gateway Customer ID',
    577                 "type" => "select",
    578                 "name" => "profilerdonation_userdefined_gatewaycustomerid",
    579                 "required" => false,
    580                 "tooltip" => "Pick the Profiler User Defined Field you wish to send the payment gateway Customer ID to",
    581                 "choices" => $userdefinedfields,
    582             );
    583         }
    584556
    585557
     
    620592        } else {
    621593            // Profiler will just record integration data
    622             $postData['method'] = "integration.send";
    623             $postData['datatype'] = "OLDON";
     594            $postData['dataType'] = "OLDON";
    624595        }
    625596
     
    634605            $postData['pledgeamount'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_amount']);
    635606        }
    636 
    637         $postData['clientname'] = $postData['firstname'] . ' ' . $postData['surname'];
    638607
    639608        // Credit card fields:
     
    645614        $postData['ccv'] = $cardDetails['ccv'];
    646615
    647         if($feed['meta']['profilerdonation_userdefined_receiptname'] !== "") {
    648             // Receipt Name
    649             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_receiptname']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_receiptname']);
    650         }
    651 
    652         if($feed['meta']['profilerdonation_userdefined_paymentgatewayidused'] !== "") {
    653             // Payment Gateway ID Used
    654             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_paymentgatewayidused']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_paymentgatewayidused']);
    655 
    656             if(empty($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_paymentgatewayidused']])) {
    657                 // Use default value
    658                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_paymentgatewayidused']] = $feed['meta']['profilerdonation_paymentgatewayidused_default'];
    659             }
    660         }
    661 
     616        // Payment Gateway ID Used
     617        $postData['paymentGatewayIdUsed'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_paymentgatewayidused']);
     618
     619        if(empty($postData['paymentGatewayIdUsed'])) {
     620            // Use default value
     621            $postData['paymentGatewayIdUsed'] = $feed['meta']['profilerdonation_paymentgatewayidused_default'];
     622        }
    662623
    663624        // Source codes
     
    671632        }
    672633
    673         $postData['sourcecode'] = $donationSourceCode;
    674 
    675         if($feed['meta']['profilerdonation_userdefined_sourcecode'] !== "") {
    676             // Donation Source Code
    677             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_sourcecode']] = $donationSourceCode;
    678         }
    679        
    680         if($feed['meta']['profilerdonation_userdefined_pledgesourcecode'] !== "") {
    681             // Pledge Source Code
    682 
    683             if(isset($feed['meta']['profilerdonation_pledgesourcecodemode']) && $feed['meta']['profilerdonation_pledgesourcecodemode'] !== "normal") {
    684                 // The source code is a value of a specified field
    685                 $pledgeSourceCode = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgesourcecodemode']);
    686 
    687             } else {
    688                 // Regular behaviour
    689                 $pledgeSourceCode = $this->getDonationCode($feed, 'pledgesourcecode', $form);
    690             }
    691 
    692             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgesourcecode']] = $pledgeSourceCode;
    693         }
    694        
    695         if($feed['meta']['profilerdonation_userdefined_pledgeacquisitioncode'] !== "") {
    696             // Pledge Acqusition code
    697             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgeacquisitioncode']] = $this->getDonationCode($feed, 'pledgeacquisitioncode', $form);
    698         }
    699 
    700         if($feed['meta']['profilerdonation_userdefined_pledgetypeid'] !== "") {
    701             // Pledge Type ID
    702             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgetypeid']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgetypeid']);
    703 
    704             if(empty($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgetypeid']])) {
    705                 // Default value if above field is empty
    706                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgetypeid']] = $feed['meta']['profilerdonation_pledgetypeid_default'];
    707             }
    708         }
    709 
    710         if($feed['meta']['profilerdonation_userdefined_clientacquisitioncode'] !== "" && $feed['meta']['profilerdonation_clientacquisitioncode'] !== "") {
     634        $postData['donationSourceCode'] = $donationSourceCode;
     635       
     636        // Pledge Source Code
     637
     638        if(isset($feed['meta']['profilerdonation_pledgesourcecodemode']) && $feed['meta']['profilerdonation_pledgesourcecodemode'] !== "normal") {
     639            // The source code is a value of a specified field
     640            $pledgeSourceCode = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgesourcecodemode']);
     641
     642        } else {
     643            // Regular behaviour
     644            $pledgeSourceCode = $this->getDonationCode($feed, 'pledgesourcecode', $form);
     645        }
     646
     647        $postData['regularSourceCode'] = $pledgeSourceCode;
     648
     649        // Pledge Acqusition code
     650        $postData['regularAcquiredReason'] = $this->getDonationCode($feed, 'pledgeacquisitioncode', $form);
     651
     652        // Pledge Type ID
     653        $postData['regularType'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgetypeid']);
     654
     655        if(empty($postData['regularType'])) {
     656            // Default value if above field is empty
     657            $postData['regularType'] = $feed['meta']['profilerdonation_pledgetypeid_default'];
     658        }
     659
     660        if($feed['meta']['profilerdonation_clientacquisitioncode'] !== "") {
    711661            // Client Acqusition code
    712             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientacquisitioncode']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientacquisitioncode']);
    713 
    714         } else if ($feed['meta']['profilerdonation_userdefined_clientacquisitioncode'] !== "") {
    715             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientacquisitioncode']] = $this->getDonationCode($feed, 'clientacquisitioncode', $form);
    716         }
    717        
    718         if($feed['meta']['profilerdonation_userdefined_donationpurposecode'] !== "" && $feed['meta']['profilerdonation_donationpurposecode'] !== "") {
    719             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_donationpurposecode']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationpurposecode']);
    720         }
    721 
    722         if($feed['meta']['profilerdonation_userdefined_donationtagcode'] !== "" && $feed['meta']['profilerdonation_donationtagcode'] !== "") {
    723             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_donationtagcode']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationtagcode']);
    724         }
    725 
    726         if($feed['meta']['profilerdonation_userdefined_gatewaytransactionid'] !== "" && isset($entry['transaction_id'])) {
     662            $postData['clientAcquiredReason'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientacquisitioncode']);
     663
     664        } else {
     665            $postData['clientAcquiredReason'] = $this->getDonationCode($feed, 'clientacquisitioncode', $form);
     666        }
     667       
     668        if($feed['meta']['profilerdonation_donationpurposecode'] !== "") {
     669            $postData['paymentPupose'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationpurposecode']);
     670        }
     671
     672        if($feed['meta']['profilerdonation_donationtagcode'] !== "") {
     673            $postData['paymentTag'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationtagcode']);
     674        }
     675
     676        if(isset($entry['transaction_id'])) {
    727677            // Gateway transaction id
    728             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaytransactionid']] = $entry['transaction_id'];
    729         }
    730 
    731         if($feed['meta']['profilerdonation_userdefined_gatewaytransactionid'] !== "" && isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_transaction_id'])) {
     678            $postData['gatewayResponseId'] = $entry['transaction_id'];
     679        }
     680
     681        if(isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_transaction_id'])) {
    732682            // PayFURL-supplied Gateway Response
    733683            $payfurl_gateway_response = $_POST['payfurl_payment_details']['captured_payment']['payfurl_transaction_id'];
    734684
    735685            if(!empty($payfurl_gateway_response)) {
    736                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaytransactionid']] = $payfurl_gateway_response;
     686                $postData['gatewayResponseId'] = $payfurl_gateway_response;
    737687            }
    738688        }
     
    743693        }
    744694
    745         if($feed['meta']['profilerdonation_userdefined_clientpreferredcontactmethod'] !== "") {
    746             // Client Preferred Contact Method
    747             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientpreferredcontactmethod']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientpreferredcontactmethod']);
    748         }
    749 
    750         if($feed['meta']['profilerdonation_userdefined_clientprivacypreference'] !== "") {
    751             // Client Privacy Preference
    752 
    753             $privacy_field_value = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientprivacypreference']);
    754 
    755             if(!empty($privacy_field_value)) {
    756                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientprivacypreference']] = 'true';
    757             }
    758         }
     695        // Client Preferred Contact Method
     696        $postData['clientPreferredContactMethod'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientpreferredcontactmethod']);
     697
     698        // Client Privacy Preference
     699        $privacy_field_value = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientprivacypreference']);
     700        if(!empty($privacy_field_value)) {
     701            $postData['clientPrivacyPreference'] = 'true';
     702        }
     703
     704        // Comments field
     705        $comments = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_comments']);
     706
     707        if(!empty($feed['meta']['profilerdonation_commentsextra'])) {
     708            // Extra text to append to comments field
     709            $comments .= GFCommon::replace_variables($feed['meta']['profilerdonation_commentsextra'], $form, $entry, false, true, false, 'text');
     710        }
     711
     712        $comments = html_entity_decode($comments);
     713
     714        // Only allow ASCII printable characters.
     715        // This is a work-around to the API endpoint not allowing some characters
     716        $comments = preg_replace('/[^\x20-\x7E]/','', $comments);
     717
     718        // Comments
     719        $postData['comments'] = $comments;
    759720
    760721        if($this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationtype']) == "regular") {
    761722            // Recurring donation
    762             $postData['datatype'] = "PLG";
    763             $postData['pledgetype'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgefreq']);
    764 
    765             if(empty($postData['pledgetype'])) {
     723            $postData['dataType'] = "PLG";
     724            $postData['pledgeType'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgefreq']);
     725
     726            if(empty($postData['pledgeType'])) {
    766727                // We assume a monthly pledge if no frequency is specified
    767                 $postData['pledgetype'] = "monthly";
     728                $postData['pledgeType'] = "monthly";
    768729            }
    769730
    770             if($feed['meta']['profilerdonation_userdefined_sourcecode'] !== "") {
    771                 // If it's recurring, the donation gets the pledge source code instead of the donation code
    772                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_sourcecode']] = $this->getDonationCode($feed, 'pledgesourcecode', $form);
    773             }
     731            // If it's recurring, the donation gets the pledge source code instead of the donation code
     732            $postData['donationSourceCode'] = $this->getDonationCode($feed, 'pledgesourcecode', $form);
    774733
    775734            // Store the donation type
    776             gform_add_meta($entry["id"], "profiler_type", "regular", $form_id);
     735            gform_add_meta($entry["id"], "profiler_type", "regular", $form['id']);
    777736
    778737        } elseif($useAsGateway == false) {
     
    786745
    787746            unset($postData['pledgeamount']);
    788             unset($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgeacquisitioncode']]);
    789             unset($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgesourcecode']]);
     747            unset($postData['regularAcquiredReason']);
     748            unset($postData['regularSourceCode']);
    790749
    791750        } else {
     
    810769            unset($postData['cardexpiry']);
    811770
    812             $postData['bankaccountname'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountname"]);
    813             $postData['bankbsb'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_bsb"]);
    814             $postData['bankaccountnumber'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountnumber"]);
     771            $postData['bsbAccName'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountname"]);
     772            $postData['bsb'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_bsb"]);
     773            $postData['bsbAccNum'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountnumber"]);
    815774           
    816775        } elseif($this->get_field_value($form, $entry, $feed['meta']['profilerdonation_paymentmethod']) == "paypal") {
     
    829788    public function process_feed_success($feed, $entry, $form, $pfResponse, $postData) {
    830789
    831         if(!isset($pfResponse['dataArray']['status']) || $pfResponse['dataArray']['status'] != "Pass") {
     790        if(isset($pfResponse['dataArray']['success']) && $pfResponse['dataArray']['success'] === true) {
     791            // Store the Integration ID as meta so we can use it later
     792            if(isset($pfResponse['dataArray']['integrationId'])) {
     793                gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['integrationId'], $form['id']);
     794                gform_add_meta($entry["id"], "profiler_integration_guid", $pfResponse['dataArray']['integrationGuid'], $form['id']);
     795                gform_add_meta($entry["id"], "profiler_sourcecode", $postData['donationSourceCode'], $form['id']);
     796            }
     797        } else {
    832798            // Profiler failed. Send the failure email.
    833             $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']['profiler_erroremailaddress']);
    834 
    835         } else {
    836             // Store the Integration ID as meta so we can use it later
    837             if(isset($pfResponse['dataArray']['id'])) {
    838                 gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['id'], $form['id']);
    839                 gform_add_meta($entry["id"], "profiler_sourcecode", $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_sourcecode']], $form['id']);
    840             }
    841         }
    842 
     799            $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']["profiler".$this->gffield_legacyname."_erroremailaddress"]);
     800        }
    843801    }
    844802
  • profiler-donations-gravityforms/tags/2.5.0/class-profilermembership-gfaddon.php

    r2750662 r3211366  
    1010    protected static $_instance = null;
    1111
    12     protected $apifield_endpoint = "/ProfilerAPI/Legacy/";
    13     protected $apifield_apikey = "apikey";
    14     protected $apifield_apipass = "apipass";
    15     protected $apifield_ipaddress = 'udf';
    16     protected $apifield_formurl = true;
     12    protected $api_type = "json";
     13    protected $api_domain = "profilersoftware.com";
     14    protected $apifield_endpoint = "/ProfilerAPI/RapidEndpoint/";
     15    protected $apifield_apikey = "apiuser";
     16    protected $apifield_apipass = "apipassword";
     17    protected $apifield_ipaddress = 'requestIPAddress';
     18    protected $apifield_formurl = 'pageURL';
    1719    protected $gffield_legacyname = "membership";
    1820
     
    4345        $fields = parent::feed_settings_fields_custom();
    4446
    45         foreach($fields as $fieldKey => $fieldVal) {
    46             if($fieldVal['label'] == "Use Profiler As A Gateway?") {
    47                 $fields[$fieldKey]['choices'][] = array(
    48                     'label'         => 'Manual - Profiler will Process Payments, manually later on via a Pledge',
    49                     'value'         => 'manual',
    50                 );
     47        if(apply_filters('profiler_integration_allow_profiler_gateway', true) == true) {
     48            // This filter allows us to disable the Profiler Gateway feature on a site
     49
     50            foreach($fields as $fieldKey => $fieldVal) {
     51                if($fieldVal['label'] == "Use Profiler As A Gateway?") {
     52                    $fields[$fieldKey]['choices'][] = array(
     53                        'label'         => 'Manual - Profiler will Process Payments, manually later on via a Pledge',
     54                        'value'         => 'manual',
     55                    );
     56                }
    5157            }
     58
     59            $fields[] = array(
     60                "label" => 'UDF: Stored Card Number',
     61                "type" => "select",
     62                "name" => "profilerdonation_userdefined_storedcard_number",
     63                "required" => false,
     64                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card number in",
     65                "choices" => $userdefinedfields,
     66            );
     67
     68            $fields[] = array(
     69                "label" => 'UDF: Stored Card Expiry',
     70                "type" => "select",
     71                "name" => "profilerdonation_userdefined_storedcard_expiry",
     72                "required" => false,
     73                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card expiry in",
     74                "choices" => $userdefinedfields,
     75            );
     76
     77            $fields[] = array(
     78                "label" => 'UDF: Stored Card CCV',
     79                "type" => "select",
     80                "name" => "profilerdonation_userdefined_storedcard_ccv",
     81                "required" => false,
     82                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card CCV in",
     83                "choices" => $userdefinedfields,
     84            );
     85
     86            $fields[] = array(
     87                "label" => 'UDF: Stored Card Name',
     88                "type" => "select",
     89                "name" => "profilerdonation_userdefined_storedcard_name",
     90                "required" => false,
     91                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card name in",
     92                "choices" => $userdefinedfields,
     93            );
     94
    5295        }
    53 
    54         $fields[] = array(
    55             "label" => 'UDF: Stored Card Number',
    56             "type" => "select",
    57             "name" => "profilerdonation_userdefined_storedcard_number",
    58             "required" => false,
    59             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card number in",
    60             "choices" => $userdefinedfields,
    61         );
    62 
    63         $fields[] = array(
    64             "label" => 'UDF: Stored Card Expiry',
    65             "type" => "select",
    66             "name" => "profilerdonation_userdefined_storedcard_expiry",
    67             "required" => false,
    68             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card expiry in",
    69             "choices" => $userdefinedfields,
    70         );
    71 
    72         $fields[] = array(
    73             "label" => 'UDF: Stored Card CCV',
    74             "type" => "select",
    75             "name" => "profilerdonation_userdefined_storedcard_ccv",
    76             "required" => false,
    77             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card CCV in",
    78             "choices" => $userdefinedfields,
    79         );
    80 
    81         $fields[] = array(
    82             "label" => 'UDF: Stored Card Name',
    83             "type" => "select",
    84             "name" => "profilerdonation_userdefined_storedcard_name",
    85             "required" => false,
    86             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card name in",
    87             "choices" => $userdefinedfields,
    88         );
    8996
    9097        return $fields;
  • profiler-donations-gravityforms/tags/2.5.0/class-profilerpostdonate-gfaddon.php

    r2750662 r3211366  
    1010    protected static $_instance = null;
    1111
    12     protected $apifield_endpoint = "/ProfilerAPI/LegacyPost/";
    13     protected $apifield_apikey = "api_user";
    14     protected $apifield_apipass = "api_pass";
    15     protected $apifield_ipaddress = 'udf';
    16     protected $apifield_formurl = true;
     12    protected $api_type = "json";
     13    protected $api_domain = "profilersoftware.com";
     14    protected $apifield_endpoint = "/ProfilerAPI/RapidEndpoint/";
     15    protected $apifield_apikey = "apiuser";
     16    protected $apifield_apipass = "apipassword";
     17    protected $apifield_ipaddress = 'requestIPAddress';
     18    protected $apifield_formurl = 'pageURL';
    1719    protected $gffield_legacyname = "donation";
    1820    protected $supports_custom_fields = true;
     
    5961
    6062        $fields[] = array(
    61             "label" => 'UDF: Comments',
    62             "type" => "select",
    63             "name" => "profilerdonation_userdefined_comments",
    64             "required" => false,
    65             "tooltip" => "Pick the Profiler User Defined Field you wish to use for the Comments field",
    66             "choices" => $userdefinedfields,
    67         );
    68 
    69         $fields[] = array(
    7063            "label" => 'Extra Comments Text',
    7164            "type" => "textarea",
    7265            "name" => "profilerdonation_commentsextra",
    73             "required" => true,
     66            "required" => false,
    7467            "class" => "merge-tag-support",
    7568            "tooltip" => "This is extra text to be sent to Profiler as an Interaction. Protip: Include Gravity Forms Merge Fields in this textarea to accept user input.",
     
    109102    public function process_feed_custom($feed, $entry, $form, $postData, $fromValidatorProcessPFGateway = false) {
    110103
    111         $postData['method'] = "integration.send";
    112104        $postData['datatype'] = "OLDON";
    113105
     
    123115        // Comments
    124116        $postData['comments'] = $comments;
    125         $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_comments']] = $comments;
    126        
     117
    127118        $gfEntryId = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_gfentryid']);
    128119        $pfIntegrationId = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_profilerid']);
     
    147138
    148139        // This is the ID of the actual donation entry
    149         $postData['HoldingID'] = $pfIntegrationId;
     140        $postData['holdingId'] = $pfIntegrationId;
    150141
    151142        return $postData;
     
    154145    public function process_feed_success($feed, $entry, $form, $pfResponse, $postData) {
    155146
    156         if(!isset($pfResponse['dataArray']['status']) || $pfResponse['dataArray']['status'] != "Pass") {
     147        if(isset($pfResponse['dataArray']['success']) && $pfResponse['dataArray']['success'] === true) {
     148            // Store the Integration ID as meta so we can use it later
     149            if(isset($pfResponse['dataArray']['integrationId'])) {
     150                gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['integrationId'], $form['id']);
     151                gform_add_meta($entry["id"], "profiler_integration_guid", $pfResponse['dataArray']['integrationGuid'], $form['id']);
     152            }
     153        } else {
    157154            // Profiler failed. Send the failure email.
    158             $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']['profiler_erroremailaddress']);
    159 
    160         } else {
    161             // Store the Integration ID as meta so we can use it later
    162             if(isset($pfResponse['dataArray']['id']))
    163                 gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['id'], $form['id']);
     155            $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']["profiler".$this->gffield_legacyname."_erroremailaddress"]);
    164156        }
    165 
    166157    }
    167158
  • profiler-donations-gravityforms/tags/2.5.0/index.php

    r3136560 r3211366  
    11<?php
    22/*
    3 Plugin Name: Profiler Donations - Gravity Forms Add-On
     3Plugin Name: Gravity Forms + Profiler Add-On
    44Plugin URI: https://mediarealm.com.au/
    55Description: Integrates Gravity Forms with Profiler, enabling donation data and more to be sent directly to Profiler.
    6 Version: 2.4.3
     6Version: 2.5.0
    77
    88Author: Media Realm
     
    6666        //GFAddOn::register('GFProfilerEvents');
    6767
     68        // This is a settings screen to list all Profiler feeds in the system
     69        require_once('class-feedlist-gfaddon.php');
     70        GFAddOn::register('GF_Profiler_FeedList');
     71
    6872        // Include some random helper functions
    6973        require_once(plugin_dir_path(__FILE__) . '/shortcodes.php');
  • profiler-donations-gravityforms/tags/2.5.0/readme.txt

    r3136560 r3211366  
    2222
    2323== Changelog ==
     24
     25= 2.5.0 =
     26
     27This is a substantial update. Please backup your site before upgrading, and test all your integrations thoroughly after upgrading this plugin.
     28
     29* Use the new Profiler Core API for Donations/payments. This removes the UDF field config and automates it within Profiler.
     30* Create 'Profiler Feed List' setting screen, for quick access to all configured feeds on your site
     31* Remove Profiler Logs fields, and move these to an entry metabox.
     32* Donation Feed: Add Extra Comments field
     33* Donation Feed: Automatic formatting of Australian phone numbers
     34* Add Profiler icon to all Feeds
     35* Donation Feed: Add new fields for gender, interactions, roles, membership mapping and payment split text.
     36* Membership Feed: Hide manual payment fields if Profiler-driven payments have been disabled
    2437
    2538= 2.4.3 =
  • profiler-donations-gravityforms/tags/2.5.0/sync_users.php

    r2750662 r3211366  
    232232
    233233        if(empty($options['auth_apikey']) || empty($options['auth_apipass']) || empty($options['pf_database']) || empty($options['pf_domain'])) {
    234             $this->log("Profiler Users not configured correctly");
    235234            return;
    236235        }
  • profiler-donations-gravityforms/tags/2.5.0/woocommerce/integration.php

    r2984822 r3211366  
    2323        $this->dbname                      = $this->get_option( 'dbname' );
    2424        $this->apikey                      = $this->get_option( 'apikey' );
     25
     26        // Upgrade config to new domain
     27        $this->instancedomainname = str_replace(".profilersystem.com", ".profilersoftware.com", $this->instancedomainname);
    2528
    2629        // Actions.
     
    5457                'title'             => 'Profiler Instance Domain Name',
    5558                'type'              => 'text',
    56                 'description'       => 'e.g. example.profilersystem.com',
     59                'description'       => 'e.g. example.profilersoftware.com',
    5760                'desc_tip'          => true,
    5861                'default'           => '',
     
    8588                'desc_tip'          => true,
    8689                'default'           => ''
    87             ),
    88             'udf_sourcecode' => array(
    89                 'title'             => 'UDF: Donation Source Code',
    90                 'type'              => 'select',
    91                 'description'       => '',
    92                 'desc_tip'          => true,
    93                 'default'           => '',
    94                 'options'           => $this->options_udf(),
    95             ),
    96             'udf_clientip' => array(
    97                 'title'             => 'UDF: Client IP Address',
    98                 'type'              => 'select',
    99                 'description'       => '',
    100                 'desc_tip'          => true,
    101                 'default'           => '',
    102                 'options'           => $this->options_udf(),
    103             ),
    104             'udf_transactionid' => array(
    105                 'title'             => 'UDF: Gateway Transaction ID',
    106                 'type'              => 'select',
    107                 'description'       => '',
    108                 'desc_tip'          => true,
    109                 'default'           => '',
    110                 'options'           => $this->options_udf(),
    11190            ),
    11291        );
     
    204183
    205184        // Build API payload
    206         $url = 'https://' . $this->instancedomainname . '/ProfilerAPI/Legacy/';
     185        $url = 'https://' . $this->instancedomainname . '/ProfilerAPI/RapidEndpoint/';
    207186        $profiler_data = array(
    208             'DB' => $this->dbname,
    209             'apikey' => $this->apikey,
    210             'apipass' => $this->get_option('apipass'),
    211             'method' => 'integration.send',
     187            'apiuser' => $this->apikey,
     188            'apipassword' => $this->get_option('apipass'),
    212189            'datatype' => 'OLDON',
    213190
    214191            'amount' => $total,
    215             'donationamount' => $total,
    216             'sourcecode' => $this->get_option('sourcecode'),
     192            'donationAmount' => $total,
     193            'donationSourceCode' => $this->get_option('sourcecode'),
    217194            'status' => 'Approved',
    218195
    219196            'clientname' => $first_name . ' ' . $last_name,
    220             'firstname' => $first_name,
     197            'firstName' => $first_name,
    221198            'surname' => $last_name,
    222199
     
    233210        );
    234211
    235         if($this->get_option('udf_sourcecode') != '') {
    236             // Source code as a UDF
    237             $profiler_data['userdefined' . $this->get_option('udf_sourcecode')] = $this->get_option('sourcecode');
    238         }
     212        // Source code as a UDF
     213        $profiler_data['donationSourceCode'] = $this->get_option('sourcecode');
    239214
    240215        if($order->needs_payment()) {
     
    243218        }
    244219
    245         if($this->get_option('udf_clientip') != '') {
    246             // Client IP Address
    247             $profiler_data['userdefined' . $this->get_option('udf_clientip')] = $this->get_client_ip_address();
    248         }
    249 
    250         if($this->get_option('udf_transactionid') != '') {
    251             // Payment Gateway Transaction ID
    252             $profiler_data['userdefined' . $this->get_option('udf_transactionid')] = $order->get_transaction_id();
    253         }
     220        // Client IP Address
     221        $profiler_data['requestIPAddress'] = $this->get_client_ip_address();
     222
     223        // Payment Gateway Transaction ID
     224        $profiler_data['gatewayResponseId'] = $order->get_transaction_id();
    254225
    255226        // Push data to Profiler
     
    350321
    351322        $ch = curl_init();
    352         curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query(array("DB" => $profiler_query['DB'], "Call" => 'submit')));
     323        curl_setopt($ch, CURLOPT_URL, $url);
    353324        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    354         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen(http_build_query($profiler_query))));
    355         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($profiler_query));
     325        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($profiler_query));
     326        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    356327        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    357328
     
    386357            "dataSent" => $profiler_query,
    387358            "data" => $result,
    388             "dataXML" => simplexml_load_string($result),
    389             "dataArray" => json_decode(json_encode((array)simplexml_load_string($result)), 1),
     359            "dataArray" => json_decode($result, true),
    390360            "cURLError" => $cURL_error,
    391361            "cURL_SSL_Mode" => $ssl_mode,
    392362        );
    393     }
    394 
    395     private function options_udf() {
    396         $fields = array("0" => "");
    397 
    398         for($i = 1; $i <= 99; $i++) {
    399             $fields[$i] = "User Defined Field " . $i;
    400         }
    401 
    402         return $fields;
    403363    }
    404364
  • profiler-donations-gravityforms/trunk/README.md

    r2698068 r3211366  
    1515*   [Gravity Forms](http://www.gravityforms.com)
    1616*   Payment Gateway integration with Gravity Forms (must be pre-existing and use standard Gravity Forms payment hooks and database fields)
    17   * For Australian non-profits, we recommend the official Gravity Forms Stripe plugin
     17  * We recommend the official Gravity Forms Stripe plugin
    1818*   Full administrative access to Profiler
    1919*   CURL and XML Enabled on Web Server
  • profiler-donations-gravityforms/trunk/class-profilercommon.php

    r3136560 r3211366  
    77    protected $_title = "Profiler / Gravity Forms - Integration Feed";
    88
     9    protected $api_type = "form"; // form or json
     10    protected $api_domain = "profilersystem.com";
    911    protected $apifield_apikey = "apikey";
    1012    protected $apifield_apipass = "apipass";
     
    2729        add_filter('gform_stripe_charge_description',       array($this, 'stripe_payment_description'), 10, 5);
    2830        add_filter('gform_stripe_payment_element_initial_payment_information', array($this, 'stripe_elements_setup'), 10, 3);
    29     }
     31
     32        // Metabox for Profiler Logs
     33        add_filter('gform_entry_detail_meta_boxes',         array($this, 'meta_box_entry'), 10, 3);
     34    }
     35
     36    public function get_menu_icon() {
     37        //return 'dashicons-admin-generic';
     38        return plugins_url('icon-profiler.png', __FILE__);
     39    }
    3040
    3141    public function feed_settings_fields() {
     
    6575            "name" => "profiler".$this->gffield_legacyname."_instancedomainname",
    6676            "required" => true,
    67             "tooltip" => "Your Instance Domain Name can be found in your login URL: e.g. 'https://instance.profiler.net.au/' is 'instance.profiler.net.au'",
    68         );
    69        
    70         $fields[] = array(
    71             "label" => 'Profiler Database Name',
    72             "type" => "text",
    73             "name" => "profiler".$this->gffield_legacyname."_dbname",
    74             "required" => true,
    75         );
     77            "tooltip" => "Your Instance Domain Name can be found in your login URL: e.g. 'https://instance.profilersystem.com/' is 'instance.profilesystem.com'",
     78        );
     79       
     80        if($this->api_type !== 'json') {
     81            $fields[] = array(
     82                "label" => 'Profiler Database Name',
     83                "type" => "text",
     84                "name" => "profiler".$this->gffield_legacyname."_dbname",
     85                "required" => true,
     86            );
     87        }
    7688       
    7789        $fields[] = array(
     
    138150                    // Loop over mailing list fields
    139151   
     152                    if($this->api_type !== 'json') {
     153                        $fields[] = array(
     154                            "label" => 'Mailing List #'.$i.': UDF',
     155                            "type" => "select",
     156                            "name" => "profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf",
     157                            "required" => false,
     158                            "tooltip" => "Pick the Profiler User Defined Field you wish to use for this mailing",
     159                            "choices" => $userdefinedfields,
     160                        );
     161                    }
     162
    140163                    $fields[] = array(
    141                         "label" => 'Mailing List #'.$i.': UDF',
    142                         "type" => "select",
    143                         "name" => "profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf",
    144                         "required" => false,
    145                         "tooltip" => "Pick the Profiler User Defined Field you wish to use for this mailing",
    146                         "choices" => $userdefinedfields,
    147                     );
    148    
    149                     $fields[] = array(
    150                         "label" => 'Mailing List #'.$i.': UDF Text',
     164                        "label" => ($this->api_type == 'json' ? 'Mailing List #'.$i.': Mailing Type Code' : 'Mailing List #'.$i.': UDF Text'),
    151165                        "type" => "text",
    152166                        "name" => "profiler".$this->gffield_legacyname."_mailinglist_".$i."_udftext",
    153167                        "required" => false,
    154                         "tooltip" => "Enter the string Profiler is expecting in this UDF",
     168                        "tooltip" => ($this->api_type == 'json' ? "Enter the Profiler Mailing Type Code" : "Enter the string Profiler is expecting in this UDF") . ". This field also accept post meta merge fields in this format: {postmeta:meta_field_name}",
    155169                    );
    156    
     170
    157171                    $fields[] = array(
    158172                        "label" => 'Mailing List #'.$i.': Field',
     
    161175                        "tooltip" => 'Link it to a checkbox field - when checked, the mailing will be sent',
    162176                        "required" => false,
    163                         "choices" => $checkboxFields
     177                        "choices" => array_merge($checkboxRadioFields, array(array("value" => "always", "label" => "Always Subscribe"))),
    164178                    );
    165179                }
     
    203217
    204218        $fields[] = array(
    205             "label" => 'Profiler Logs',
    206             "type" => "select",
    207             "name" => "profiler".$this->gffield_legacyname."_logs",
    208             "tooltip" => 'Link it to a Hidden field that will hold Profiler Response Logs',
    209             "required" => false,
    210             "choices" => $hiddenFields
    211         );
    212        
    213         $fields[] = array(
    214219            "label" => 'SSL Mode',
    215220            "type" => "select",
     
    259264        $postData = array();
    260265
    261         $postData['DB'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_dbname'];
     266        if($this->api_type !== 'json') {
     267            $postData['DB'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_dbname'];
     268        }
    262269        $postData[$this->apifield_apikey] = $feed['meta']['profiler'.$this->gffield_legacyname.'_apikey'];
    263270        $postData[$this->apifield_apipass] = $feed['meta']['profiler'.$this->gffield_legacyname.'_apipass'];
     
    265272        if(empty($feed['meta']['profiler'.$this->gffield_legacyname.'_instancedomainname']) && !empty($feed['meta']['profiler'.$this->gffield_legacyname.'_instancename'])) {
    266273            // Respect the setting from when we only accepted the first part of the domain name
    267             $feed['meta']['profiler'.$this->gffield_legacyname.'_instancedomainname'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_instancename'] . ".profiler.net.au";
     274            $feed['meta']['profiler'.$this->gffield_legacyname.'_instancedomainname'] = $feed['meta']['profiler'.$this->gffield_legacyname.'_instancename'] . ".profilersystem.com";
    268275        }
    269276
     
    282289            if(isset($field['pf_apifield']) && $this->get_field_value($form, $entry, $feed['meta'][$field['name']]) != '') {
    283290                $postData[$field['pf_apifield']] = trim($this->get_field_value($form, $entry, $feed['meta'][$field['name']]));
     291
     292                // Auto formatting for phone fields
     293                if(isset($field['auto_format']) && $field['auto_format'] == "phone") {
     294                    $postData[$field['pf_apifield']] = $this->auto_format_phone($postData[$field['pf_apifield']]);
     295                }
    284296            }
    285297        }
     
    301313        if($this->apifield_formurl === true && !empty($feed['meta']['profiler'.$this->gffield_legacyname.'_userdefined_formurl'])) {
    302314            $postData['userdefined' . $feed['meta']['profiler'.$this->gffield_legacyname.'_userdefined_formurl']] = $entry['source_url'];
     315        } else if($this->apifield_formurl !== false) {
     316            $postData[$this->apifield_formurl] = $entry['source_url'];
    303317        }
    304318
     
    322336            }
    323337
    324             if($feed['meta']['profilerdonation_userdefined_gatewaycustomerid'] !== "" && isset($payment_intent)) {
     338            if(isset($payment_intent)) {
    325339                // Gateway Customer ID
    326                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaycustomerid']] = $payment_intent->customer;
    327             }
    328 
    329             if($feed['meta']['profilerdonation_userdefined_gatewaycardtoken'] !== "" && isset($payment_intent)) {
     340                $postData['paymentGatewayCustomerId'] = $payment_intent->customer;
     341            }
     342
     343            if(isset($payment_intent)) {
    330344                // Gateway Card Token
    331345                try {
    332                     $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaycardtoken']] = $payment_intent->charges->data[0]->payment_method;
     346                    $postData['gatewayCardToken'] = $payment_intent->charges->data[0]->payment_method;
    333347                } catch(Exception $e) {
    334348                    error_log("STRIPE/PROFILER CARD TOKEN ERROR: " . print_r($e, true));
     
    338352
    339353        // PayFURL-supplied Gateway Token
    340         if($feed['meta']['profilerdonation_userdefined_gatewaycardtoken'] !== "" && isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_payment_method_id_provider'])) {
     354        if(isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_payment_method_id_provider'])) {
    341355            $payfurl_provider_token = $_POST['payfurl_payment_details']['captured_payment']['payfurl_payment_method_id_provider'];
    342            
     356
    343357            if(!empty($payfurl_provider_token)) {
    344                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaycardtoken']] = $payfurl_provider_token;
     358                $postData['gatewayCardToken'] = $payfurl_provider_token;
    345359            }
    346360        }
     
    349363        if($this->supports_custom_fields === true && !empty($feed['meta']['profiler_customfields_count'])) {
    350364            for($i = 1; $i <= $feed['meta']['profiler_customfields_count']; $i++) {
    351                 $postData["userdefined" . $feed['meta']["profiler_customfield_".$i."_pffield"]] = trim($this->get_field_value($form, $entry, $feed['meta']["profiler_customfield_".$i."_gffield"]));
     365
     366                $value = trim($this->get_field_value($form, $entry, $feed['meta']["profiler_customfield_".$i."_gffield"]));
     367
     368                if($this->api_type == 'json') {
     369                    if(!isset($postData['userDefinedFields'])) {
     370                        $postData['userDefinedFields'] = array();
     371                    }
     372
     373                    $postData['userDefinedFields']["userDefined" . $feed['meta']["profiler_customfield_".$i."_pffield"]] = $value;
     374
     375                } else {
     376                    $postData["userdefined" . $feed['meta']["profiler_customfield_".$i."_pffield"]] = $value;
     377                }
     378
     379               
    352380            }
    353381        }
     
    358386                // Loop over mailing list fields
    359387                $mailingFieldValue = $this->get_field_value($form, $entry, $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_field"]);
    360                 $udf = $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf"];
    361388                $udfText = $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_udftext"];
    362389
    363                 if(!empty($udf) && !empty($udfText) && !empty($mailingFieldValue)) {
    364                     $postData['userdefined' . $udf] = $udfText;
    365                 }
    366 
     390                // Allow merging post meta fields into $udfText
     391                if(isset($entry['post_id']) && !empty($entry['post_id'])) {
     392                    $post_id = $entry['post_id'];
     393                } else {
     394                    global $post;
     395                    if(isset($post)) {
     396                        $post_id = $post->ID;
     397                    }
     398                }
     399
     400                if(isset($post_id)) {
     401                    preg_match_all("/{postmeta:(.*?)}/", $udfText, $matches);
     402
     403                    if(is_array($matches) && isset($matches[1])) {
     404                        foreach($matches[1] as $match) {
     405                            $post_meta = get_post_meta($post_id, $match, true);
     406                            $udfText = str_replace("{postmeta:".$match."}", $post_meta, $udfText);
     407                        }
     408                    }
     409                }
     410
     411                if($this->api_type == 'json') {
     412
     413                    if(!isset($postData['mailingList'])) {
     414                        $postData['mailingList'] = '';
     415                    }
     416
     417                    if(!empty($udfText) && (!empty($mailingFieldValue) || $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_field"] == 'always')) {
     418                        $postData['mailingList'] .= (!empty($postData['mailingList']) ? ',' : '') . $udfText;
     419                    }
     420
     421                } else {
     422                    $udf = $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_udf"];
     423
     424                    if(!empty($udf) && !empty($udfText) && (!empty($mailingFieldValue) || $feed['meta']["profiler".$this->gffield_legacyname."_mailinglist_".$i."_field"] == 'always')) {
     425                        $postData['userdefined' . $udf] = $udfText;
     426                    }
     427                }
    367428            }
    368429        }
     
    386447        $postData = apply_filters('profiler_integration_api_request_data', $postData, $form, $entry, $this->apifield_endpoint);
    387448
     449        // Update URL for newer APIs
     450        if($this->api_domain !== 'profilersystem.com') {
     451            $API_URL = str_replace(".profilersystem.com", "." . $this->api_domain, $API_URL);
     452        }
     453
    388454        // Send data to Profiler
    389455        $pfResponse = $this->sendDataToProfiler($API_URL, $postData, $feed['meta']['profiler'.$this->gffield_legacyname.'_sslmode']);
     
    391457        if($fromValidatorProcessPFGateway === false) {
    392458            // Save Profiler response data back to the form entry
    393             $logsToStore = json_encode($pfResponse);
     459            $logsToStore = json_encode($pfResponse, JSON_PRETTY_PRINT);
    394460            $logsToStore = str_replace($postData['cardnumber'], "--REDACTED--", $logsToStore);
    395461            $logsToStore = str_replace($postData[$this->apifield_apikey], "--REDACTED--", $logsToStore);
    396462            $logsToStore = str_replace($postData[$this->apifield_apipass], "--REDACTED--", $logsToStore);
    397             $entry[$feed['meta']['profiler'.$this->gffield_legacyname.'_logs']] = htmlentities($logsToStore);
    398             GFAPI::update_entry($entry);
     463            gform_add_meta($entry["id"], "profiler_logs", $logsToStore, $form['id']);
    399464
    400465            if(method_exists($this, 'process_feed_success')) {
    401466                $this->process_feed_success($feed, $entry, $form, $pfResponse, $postData);
    402             }   
     467            }
     468
    403469        } else {
    404470            return $pfResponse;
     
    651717        }
    652718
     719        if(isset($profiler_query['DB'])) {
     720            $url .= '?' . http_build_query(array("DB" => $profiler_query['DB'], "Call" => 'submit'));
     721        }
     722
    653723        $ch = curl_init();
    654         curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query(array("DB" => $profiler_query['DB'], "Call" => 'submit')));
     724        curl_setopt($ch, CURLOPT_URL, $url);
     725        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    655726        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    656         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen(http_build_query($profiler_query))));
    657         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($profiler_query));
    658         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    659        
     727
    660728        if($ssl_mode == "bundled_ca") {
    661729            // Use the CA Cert bundled with this plugin
     
    669737        }
    670738
     739        if($this->api_type === 'json') {
     740            // JSON POST
     741            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($profiler_query));
     742            curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
     743
     744        } else {
     745            // FORM POST
     746            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen(http_build_query($profiler_query))));
     747            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($profiler_query));
     748        }
     749
    671750        $result = curl_exec($ch);
    672751        $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    673        
     752
    674753        if(curl_error($ch)) {
    675754            $cURL_error = curl_error($ch);
     
    677756            $cURL_error = null;
    678757        }
    679        
     758
    680759        curl_close($ch);
    681        
     760
     761        if($this->api_type === 'json') {
     762            $data_decoded = json_decode($result, true);
     763        } else {
     764            $data_decoded = json_decode(json_encode((array)simplexml_load_string($result)), true);
     765        }
     766
    682767        return array(
    683768            "httpstatus" => $status_code,
     769            "url" => $url,
    684770            "dataSent" => $profiler_query,
    685771            "data" => $result,
    686             "dataXML" => simplexml_load_string($result),
    687             "dataArray" => json_decode(json_encode((array)simplexml_load_string($result)), 1),
     772            "dataArray" => $data_decoded,
    688773            "cURLError" => $cURL_error,
    689774            "cURL_SSL_Mode" => $ssl_mode,
     775            "api_type" => $this->api_type,
    690776        );
    691777    }
     
    707793
    708794        foreach($pfResponse['dataSent'] as $key => $val) {
    709             if($key == "apikey" || $key == "apipass" || $key == "cardnumber" || $key == "api_user" || $key == "api_pass" || $key == $this->apifield_apikey || $key == $this->apifield_apipass) {
     795            if($key == "apikey" || $key == "apipass" || $key == "apipassword" || $key == "cardnumber" || $key == "api_user" || $key == "api_pass" || $key == $this->apifield_apikey || $key == $this->apifield_apipass) {
    710796                $val = "--REDACTED--";
    711797            }
     
    10231109
    10241110    }
     1111
     1112    public function meta_box_entry($meta_boxes, $entry, $form) {
     1113        // Custom Metabox
     1114
     1115        if($this->get_active_feeds($form['id'])) {
     1116
     1117            $profiler_logs_meta = gform_get_meta($entry['id'], 'profiler_logs');
     1118
     1119            if(!empty($profiler_logs_meta)) {
     1120                $meta_boxes[$this->_slug] = array(
     1121                    'title'    => 'Profiler API',
     1122                    'callback' => array($this, 'meta_box_entry_render'),
     1123                    'context'  => 'side',
     1124                    'callback_args' => array($entry, $form),
     1125                );
     1126            }
     1127        }
     1128
     1129        return $meta_boxes;
     1130    }
     1131
     1132    public function meta_box_entry_render($data) {
     1133        // Render the Custom Metabox
     1134        $html = '';
     1135
     1136        $meta_fields = array(
     1137            "profiler_integrationid" => "Integration ID",
     1138            "profiler_integration_guid" => "Integration GUID",
     1139            "profiler_logs" => "Profiler API Logs",
     1140        );
     1141
     1142        foreach($meta_fields as $field_name => $field_title) {
     1143
     1144            $meta_value = gform_get_meta($data['entry']['id'], $field_name);
     1145
     1146            if(!empty($meta_value)) {
     1147                $html .= '<p><strong>'.$field_title.'</strong>:<br /><pre style="width: 100%; overflow-x: scroll;">'.esc_html($meta_value).'</pre></p>';
     1148            }
     1149        }
     1150
     1151        echo $html;
     1152    }
     1153
     1154    private function auto_format_phone($phone_number_original) {
     1155        // This function auto-formats a phone number into an Australian format (0000 000 000 or 00 0000 0000)
     1156
     1157        // Remove certain characters
     1158        $phone_number = str_replace(array(" ", "-", "(", ")"), array("", "", "", ""), $phone_number_original);
     1159
     1160        // Remove +61 prefix
     1161        if(substr($phone_number, 0, 3) == "+61") {
     1162            $phone_number = substr($phone_number, 3);
     1163
     1164            if(strlen($phone_number) === 9) {
     1165                $phone_number = "0" . $phone_number;
     1166            }
     1167        }
     1168
     1169        // International number. Return as-is
     1170        if(substr($phone_number, 0, 1) == "+") {
     1171            return $phone_number;
     1172        }
     1173
     1174        // Probably an Australian number
     1175        if(strlen($phone_number) == 10) {
     1176            // 0000 000 000
     1177            if(substr($phone_number, 0, 2) == "04") {
     1178                $phone_number = substr($phone_number, 0, 4) . " " . substr($phone_number, 4, 3) . " " . substr($phone_number, 7);
     1179                return $phone_number;
     1180            }
     1181
     1182            // 00 0000 0000
     1183            $phone_number = substr($phone_number, 0, 2) . " " . substr($phone_number, 2, 4) . " " . substr($phone_number, 6);
     1184            return $phone_number;
     1185        }
     1186
     1187        // Probably Australian landline with no area prefix
     1188        if(strlen($phone_number) == 8) {
     1189            // Adjust to 0000 0000 format
     1190            $phone_number = substr($phone_number, 0, 4) . " " . substr($phone_number, 4);
     1191        }
     1192
     1193        return $phone_number;
     1194    }
    10251195}
    10261196
  • profiler-donations-gravityforms/trunk/class-profilerdonate-gfaddon.php

    r3136560 r3211366  
    1010    protected static $_instance = null;
    1111
    12     protected $apifield_endpoint = "/ProfilerAPI/Legacy/";
    13     protected $apifield_apikey = "apikey";
    14     protected $apifield_apipass = "apipass";
    15     protected $apifield_ipaddress = 'udf';
    16     protected $apifield_formurl = true;
     12    protected $api_type = "json";
     13    protected $api_domain = "profilersoftware.com";
     14    protected $apifield_endpoint = "/ProfilerAPI/RapidEndpoint/";
     15    protected $apifield_apikey = "apiuser";
     16    protected $apifield_apipass = "apipassword";
     17    protected $apifield_ipaddress = 'requestIPAddress';
     18    protected $apifield_formurl = 'pageURL';
    1719    protected $gffield_legacyname = "donation";
    1820    protected $supports_custom_fields = true;
     
    129131            "required" => false,
    130132            "choices" => $field_settings,
    131             "tooltip" => "The value of this field must be set to 'monthly' or 'yearly'. This field will be used if 'Donation Type' is set to 'regular'."
     133            "tooltip" => "The value of this field must be set to 'weekly', 'monthly' or 'yearly'. This field will be used if 'Donation Type' is set to 'regular'."
    132134        );
    133135       
     
    139141            "choices" => $product_field_settings,
    140142            "tooltip" => "This amount field will be used if Donation Type is set to 'regular'.",
    141         );
    142 
    143         $fields[] = array(
    144             "label" => 'UDF: Pledge Type ID',
    145             "type" => "select",
    146             "name" => "profilerdonation_userdefined_pledgetypeid",
    147             "required" => false,
    148             "tooltip" => "Pick the Profiler User Defined Field you wish the Pledge Type ID to be sent to",
    149             "choices" => $userdefinedfields,
    150143        );
    151144
     
    182175            "required" => false,
    183176            "choices" => $field_settings,
    184             "pf_apifield" => "firstname",
     177            "pf_apifield" => "firstName",
    185178        );
    186179       
     
    193186            "pf_apifield" => "surname",
    194187        );
     188
     189        $fields[] = array(
     190            "label" => 'Client: Gender',
     191            "type" => "select",
     192            "name" => "profilerdonation_clientgender",
     193            "required" => false,
     194            "choices" => $field_settings,
     195            "pf_apifield" => "clientGender",
     196            "tooltip" => "Gender values are defined in Profiler in Setup > Client > Gender.",
     197        );
    195198       
    196199        $fields[] = array(
     
    263266            "required" => false,
    264267            "choices" => $field_settings,
    265             "pf_apifield" => "phoneah",
    266         );
    267        
     268            "pf_apifield" => "phoneAH",
     269        );
     270
    268271        $fields[] = array(
    269272            "label" => 'Client: Business Phone',
     
    272275            "required" => false,
    273276            "choices" => $field_settings,
    274             "pf_apifield" => "phonebus",
    275         );
    276        
     277            "pf_apifield" => "phoneBus",
     278            "auto_format" => "phone",
     279        );
     280
    277281        $fields[] = array(
    278282            "label" => 'Client: Mobile Phone',
     
    281285            "required" => false,
    282286            "choices" => $field_settings,
    283             "pf_apifield" => "phonemobile",
    284         );
    285        
     287            "pf_apifield" => "phoneMobile",
     288            "auto_format" => "phone",
     289        );
     290
     291        $fields[] = array(
     292            "label" => 'Client: Phone',
     293            "type" => "select",
     294            "name" => "profilerdonation_clientphonemobile",
     295            "required" => false,
     296            "choices" => $field_settings,
     297            "pf_apifield" => "phoneMobile",
     298            "auto_format" => "phone",
     299        );
     300
    286301        $fields[] = array(
    287302            "label" => 'Client: Website',
     
    323338            "required" => false,
    324339            "choices" => $field_settings,
    325             "pf_apifield" => "comments",
    326         );
    327 
    328         $fields[] = array(
    329             "label" => 'UDF: Receipt Name',
    330             "type" => "select",
    331             "name" => "profilerdonation_userdefined_receiptname",
    332             "required" => false,
    333             "tooltip" => "Pick the Profiler User Defined Field you wish the donation receipt name to be sent to",
    334             "choices" => $userdefinedfields,
     340        );
     341
     342        $fields[] = array(
     343            "label" => 'Extra Comments Text',
     344            "type" => "textarea",
     345            "name" => "profilerdonation_commentsextra",
     346            "required" => false,
     347            "class" => "merge-tag-support",
     348            "tooltip" => "This is extra text to be sent to Profiler in the Comments field. Youc an include Gravity Forms Merge Fields in this textarea to accept additional user input.",
     349        );
     350
     351        $fields[] = array(
     352            "label" => 'Interaction: Type',
     353            "type" => "select",
     354            "name" => "profilerdonation_interaction_type",
     355            "required" => false,
     356            "choices" => $field_settings,
     357            "pf_apifield" => "interactionType",
     358            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Type here, and your Interaction Text below. This is separate to the 'Comments' field above.",
     359        );
     360
     361        $fields[] = array(
     362            "label" => 'Interaction: Text',
     363            "type" => "select",
     364            "name" => "profilerdonation_interaction_text",
     365            "required" => false,
     366            "choices" => $field_settings,
     367            "pf_apifield" => "interactionText",
     368            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Text here, and your Interaction Type above. This is separate to the 'Comments' field above.",
     369        );
     370
     371        $fields[] = array(
     372            "label" => 'Interaction: Tag',
     373            "type" => "select",
     374            "name" => "profilerdonation_interaction_tag",
     375            "required" => false,
     376            "choices" => $field_settings,
     377            "pf_apifield" => "interactionTag",
     378            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Text and Interaction Type above, and your Interaction Tag here. This is separate to the 'Comments' field above.",
     379        );
     380
     381        $fields[] = array(
     382            "label" => 'Interaction: Sub-Tag',
     383            "type" => "select",
     384            "name" => "profilerdonation_interaction_subtag",
     385            "required" => false,
     386            "choices" => $field_settings,
     387            "pf_apifield" => "interactionSubTag",
     388            "tooltip" => "If you wish to setup an Interaction, specify your Interaction Text and Interaction Type above, and your Interaction Sub-Tag here. This is separate to the 'Comments' field above.",
     389        );
     390
     391        $fields[] = array(
     392            "label" => 'Role: Add Role By Role Name',
     393            "type" => "select",
     394            "name" => "profilerdonation_role_name",
     395            "required" => false,
     396            "choices" => $field_settings,
     397            "pf_apifield" => "roleName",
     398            "tooltip" => "If you wish to add a Role to a Client by Role Name, enter the Role Name here.",
     399        );
     400
     401        $fields[] = array(
     402            "label" => 'Role: Add Role By Role ID',
     403            "type" => "select",
     404            "name" => "profilerdonation_role_id",
     405            "required" => false,
     406            "choices" => $field_settings,
     407            "pf_apifield" => "roleId",
     408            "tooltip" => "If you wish to add a Role to a Client by Role ID, enter the Role ID here.",
    335409        );
    336410
     
    341415            "required" => false,
    342416            "choices" => $field_settings,
    343         );
    344        
    345         $fields[] = array(
    346             "label" => 'UDF: Donation Source Code',
    347             "type" => "select",
    348             "name" => "profilerdonation_userdefined_sourcecode",
    349             "required" => false,
    350             "tooltip" => "Pick the Profiler User Defined Field you wish the donation source code to be sent to",
    351             "choices" => $userdefinedfields,
    352         );
    353        
     417            "pf_apifield" => "receiptName",
     418        );
     419
    354420        $fields[] = array(
    355421            "label" => 'Donation Source Code - Default Value',
     
    374440                + self::$_instance->formFields("Form Field: "),
    375441        );
    376        
    377         $fields[] = array(
    378             "label" => 'UDF: Pledge Source Code',
    379             "type" => "select",
    380             "name" => "profilerdonation_userdefined_pledgesourcecode",
    381             "required" => false,
    382             "tooltip" => "Pick the Profiler User Defined Field you wish the pledge source code to be sent to",
    383             "choices" => $userdefinedfields,
    384         );
    385        
     442
    386443        $fields[] = array(
    387444            "label" => 'Pledge Source Code - Default Value',
     
    406463                + self::$_instance->formFields("Form Field: "),
    407464        );
    408        
    409         $fields[] = array(
    410             "label" => 'UDF: Pledge Acquisition Code',
    411             "type" => "select",
    412             "name" => "profilerdonation_userdefined_pledgeacquisitioncode",
    413             "required" => false,
    414             "tooltip" => "Pick the Profiler User Defined Field you wish the pledge acquisition code to be sent to",
    415             "choices" => $userdefinedfields,
    416         );
    417        
     465
    418466        $fields[] = array(
    419467            "label" => 'Pledge Acquisition Code - Default Value',
     
    425473
    426474        $fields[] = array(
    427             "label" => 'UDF: Client Acquisition',
    428             "type" => "select",
    429             "name" => "profilerdonation_userdefined_clientacquisitioncode",
    430             "required" => false,
    431             "tooltip" => "Pick the Profiler User Defined Field you wish the client acquisition code to be sent to.",
    432             "choices" => $userdefinedfields,
    433         );
    434 
    435         $fields[] = array(
    436475            "label" => 'Client Acquisition Field',
    437476            "type" => "select",
     
    441480            "choices" => $field_settings
    442481        );
    443 
    444         $fields[] = array(
    445             "label" => 'UDF: Donation Purpose',
    446             "type" => "select",
    447             "name" => "profilerdonation_userdefined_donationpurposecode",
    448             "required" => false,
    449             "tooltip" => "Pick the Profiler User Defined Field you wish the donation's purpose code to be sent to",
    450             "choices" => $userdefinedfields,
    451         );
    452482       
    453483        $fields[] = array(
     
    461491
    462492        $fields[] = array(
    463             "label" => 'UDF: Donation Tag',
    464             "type" => "select",
    465             "name" => "profilerdonation_userdefined_donationtagcode",
    466             "required" => false,
    467             "tooltip" => "Pick the Profiler User Defined Field you wish the donation's tag code to be sent to. Do not set this up if you use Tag Automation within Profiler.",
    468             "choices" => $userdefinedfields,
    469         );
    470 
    471         $fields[] = array(
    472493            "label" => 'Donation Tag Field',
    473494            "type" => "select",
     
    479500
    480501        $fields[] = array(
    481             "label" => 'UDF: Client Preferred Contact Method',
    482             "type" => "select",
    483             "name" => "profilerdonation_userdefined_clientpreferredcontactmethod",
    484             "required" => false,
    485             "tooltip" => "Pick the Profiler User Defined Field you wish the client's preferred contact method to be sent to",
    486             "choices" => $userdefinedfields,
    487         );
    488        
     502            "label" => 'Interaction: Membership/Regular Mapping Text',
     503            "type" => "select",
     504            "name" => "profilerdonation_membership_mapping_text",
     505            "required" => false,
     506            "choices" => $field_settings,
     507            "pf_apifield" => "membershipMappingText",
     508            "tooltip" => "If you configure a 'Membership/Regular Type Map' in Profiler, you can use this field to perform the Mapping.",
     509        );
     510
     511        $fields[] = array(
     512            "label" => 'Payment Split-Out Text',
     513            "type" => "select",
     514            "name" => "profilerdonation_payment_split_out_text",
     515            "required" => false,
     516            "choices" => $field_settings,
     517            "pf_apifield" => "splitOutText",
     518            "tooltip" => "In Profiler, you can setup a text mapping for a Split / Breakdown Payment. If configured, it uses the text in this field to perform the split. For example, a Payment comes in for 100 and split is setup in Profiler for word POSTAGE, the payment recorded in Profiler will have separate amounts for two source codes.",
     519        );
     520
    489521        $fields[] = array(
    490522            "label" => 'Client Preferred Contact Method Field',
     
    497529
    498530        $fields[] = array(
    499             "label" => 'UDF: Client Privacy Preference',
    500             "type" => "select",
    501             "name" => "profilerdonation_userdefined_clientprivacypreference",
    502             "required" => false,
    503             "tooltip" => "Pick the Profiler User Defined Field you wish the client's privacy preference (true/false) to be sent to",
    504             "choices" => $userdefinedfields,
    505         );
    506 
    507         $fields[] = array(
    508531            "label" => 'Client Privacy Preference Field',
    509532            "type" => "select",
     
    512535            "tooltip" => "If this checkbox is true, this client will be marked as 'private'.",
    513536            "choices" => $checkboxFields
    514         );
    515 
    516         $fields[] = array(
    517             "label" => 'UDF: Client IP Address',
    518             "type" => "select",
    519             "name" => "profilerdonation_userdefined_clientip",
    520             "required" => false,
    521             "tooltip" => "Pick the Profiler User Defined Field you wish the client's IP address to be sent to",
    522             "choices" => $userdefinedfields,
    523         );
    524        
    525         $fields[] = array(
    526             "label" => 'UDF: Gateway Transaction ID / Gateway Response',
    527             "type" => "select",
    528             "name" => "profilerdonation_userdefined_gatewaytransactionid",
    529             "required" => false,
    530             "tooltip" => "Pick the Profiler User Defined Field you wish the gateway transaction ID to be sent to (certain gateways only)",
    531             "choices" => $userdefinedfields,
    532         );
    533 
    534         $fields[] = array(
    535             "label" => 'UDF: Payment Gateway ID Used',
    536             "type" => "select",
    537             "name" => "profilerdonation_userdefined_paymentgatewayidused",
    538             "required" => false,
    539             "tooltip" => "Pick the Profiler User Defined Field you wish the payment gateway ID to be sent to",
    540             "choices" => $userdefinedfields,
    541537        );
    542538
     
    558554            "choices" => $field_settings
    559555        );
    560 
    561         if(function_exists('gf_stripe') || class_exists('GF_PayFURL')) {
    562             // Stripe & PayFURL only fields
    563             $fields[] = array(
    564                 "label" => 'UDF: Payment Gateway Card Token',
    565                 "type" => "select",
    566                 "name" => "profilerdonation_userdefined_gatewaycardtoken",
    567                 "required" => false,
    568                 "tooltip" => "Pick the Profiler User Defined Field you wish to send the payment gateway Card Token to",
    569                 "choices" => $userdefinedfields,
    570             );
    571         }
    572    
    573         if(function_exists('gf_stripe')) {
    574             // Stripe only fields
    575             $fields[] = array(
    576                 "label" => 'UDF: Payment Gateway Customer ID',
    577                 "type" => "select",
    578                 "name" => "profilerdonation_userdefined_gatewaycustomerid",
    579                 "required" => false,
    580                 "tooltip" => "Pick the Profiler User Defined Field you wish to send the payment gateway Customer ID to",
    581                 "choices" => $userdefinedfields,
    582             );
    583         }
    584556
    585557
     
    620592        } else {
    621593            // Profiler will just record integration data
    622             $postData['method'] = "integration.send";
    623             $postData['datatype'] = "OLDON";
     594            $postData['dataType'] = "OLDON";
    624595        }
    625596
     
    634605            $postData['pledgeamount'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_amount']);
    635606        }
    636 
    637         $postData['clientname'] = $postData['firstname'] . ' ' . $postData['surname'];
    638607
    639608        // Credit card fields:
     
    645614        $postData['ccv'] = $cardDetails['ccv'];
    646615
    647         if($feed['meta']['profilerdonation_userdefined_receiptname'] !== "") {
    648             // Receipt Name
    649             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_receiptname']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_receiptname']);
    650         }
    651 
    652         if($feed['meta']['profilerdonation_userdefined_paymentgatewayidused'] !== "") {
    653             // Payment Gateway ID Used
    654             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_paymentgatewayidused']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_paymentgatewayidused']);
    655 
    656             if(empty($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_paymentgatewayidused']])) {
    657                 // Use default value
    658                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_paymentgatewayidused']] = $feed['meta']['profilerdonation_paymentgatewayidused_default'];
    659             }
    660         }
    661 
     616        // Payment Gateway ID Used
     617        $postData['paymentGatewayIdUsed'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_paymentgatewayidused']);
     618
     619        if(empty($postData['paymentGatewayIdUsed'])) {
     620            // Use default value
     621            $postData['paymentGatewayIdUsed'] = $feed['meta']['profilerdonation_paymentgatewayidused_default'];
     622        }
    662623
    663624        // Source codes
     
    671632        }
    672633
    673         $postData['sourcecode'] = $donationSourceCode;
    674 
    675         if($feed['meta']['profilerdonation_userdefined_sourcecode'] !== "") {
    676             // Donation Source Code
    677             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_sourcecode']] = $donationSourceCode;
    678         }
    679        
    680         if($feed['meta']['profilerdonation_userdefined_pledgesourcecode'] !== "") {
    681             // Pledge Source Code
    682 
    683             if(isset($feed['meta']['profilerdonation_pledgesourcecodemode']) && $feed['meta']['profilerdonation_pledgesourcecodemode'] !== "normal") {
    684                 // The source code is a value of a specified field
    685                 $pledgeSourceCode = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgesourcecodemode']);
    686 
    687             } else {
    688                 // Regular behaviour
    689                 $pledgeSourceCode = $this->getDonationCode($feed, 'pledgesourcecode', $form);
    690             }
    691 
    692             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgesourcecode']] = $pledgeSourceCode;
    693         }
    694        
    695         if($feed['meta']['profilerdonation_userdefined_pledgeacquisitioncode'] !== "") {
    696             // Pledge Acqusition code
    697             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgeacquisitioncode']] = $this->getDonationCode($feed, 'pledgeacquisitioncode', $form);
    698         }
    699 
    700         if($feed['meta']['profilerdonation_userdefined_pledgetypeid'] !== "") {
    701             // Pledge Type ID
    702             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgetypeid']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgetypeid']);
    703 
    704             if(empty($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgetypeid']])) {
    705                 // Default value if above field is empty
    706                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgetypeid']] = $feed['meta']['profilerdonation_pledgetypeid_default'];
    707             }
    708         }
    709 
    710         if($feed['meta']['profilerdonation_userdefined_clientacquisitioncode'] !== "" && $feed['meta']['profilerdonation_clientacquisitioncode'] !== "") {
     634        $postData['donationSourceCode'] = $donationSourceCode;
     635       
     636        // Pledge Source Code
     637
     638        if(isset($feed['meta']['profilerdonation_pledgesourcecodemode']) && $feed['meta']['profilerdonation_pledgesourcecodemode'] !== "normal") {
     639            // The source code is a value of a specified field
     640            $pledgeSourceCode = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgesourcecodemode']);
     641
     642        } else {
     643            // Regular behaviour
     644            $pledgeSourceCode = $this->getDonationCode($feed, 'pledgesourcecode', $form);
     645        }
     646
     647        $postData['regularSourceCode'] = $pledgeSourceCode;
     648
     649        // Pledge Acqusition code
     650        $postData['regularAcquiredReason'] = $this->getDonationCode($feed, 'pledgeacquisitioncode', $form);
     651
     652        // Pledge Type ID
     653        $postData['regularType'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgetypeid']);
     654
     655        if(empty($postData['regularType'])) {
     656            // Default value if above field is empty
     657            $postData['regularType'] = $feed['meta']['profilerdonation_pledgetypeid_default'];
     658        }
     659
     660        if($feed['meta']['profilerdonation_clientacquisitioncode'] !== "") {
    711661            // Client Acqusition code
    712             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientacquisitioncode']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientacquisitioncode']);
    713 
    714         } else if ($feed['meta']['profilerdonation_userdefined_clientacquisitioncode'] !== "") {
    715             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientacquisitioncode']] = $this->getDonationCode($feed, 'clientacquisitioncode', $form);
    716         }
    717        
    718         if($feed['meta']['profilerdonation_userdefined_donationpurposecode'] !== "" && $feed['meta']['profilerdonation_donationpurposecode'] !== "") {
    719             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_donationpurposecode']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationpurposecode']);
    720         }
    721 
    722         if($feed['meta']['profilerdonation_userdefined_donationtagcode'] !== "" && $feed['meta']['profilerdonation_donationtagcode'] !== "") {
    723             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_donationtagcode']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationtagcode']);
    724         }
    725 
    726         if($feed['meta']['profilerdonation_userdefined_gatewaytransactionid'] !== "" && isset($entry['transaction_id'])) {
     662            $postData['clientAcquiredReason'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientacquisitioncode']);
     663
     664        } else {
     665            $postData['clientAcquiredReason'] = $this->getDonationCode($feed, 'clientacquisitioncode', $form);
     666        }
     667       
     668        if($feed['meta']['profilerdonation_donationpurposecode'] !== "") {
     669            $postData['paymentPupose'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationpurposecode']);
     670        }
     671
     672        if($feed['meta']['profilerdonation_donationtagcode'] !== "") {
     673            $postData['paymentTag'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationtagcode']);
     674        }
     675
     676        if(isset($entry['transaction_id'])) {
    727677            // Gateway transaction id
    728             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaytransactionid']] = $entry['transaction_id'];
    729         }
    730 
    731         if($feed['meta']['profilerdonation_userdefined_gatewaytransactionid'] !== "" && isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_transaction_id'])) {
     678            $postData['gatewayResponseId'] = $entry['transaction_id'];
     679        }
     680
     681        if(isset($_POST['payfurl_payment_details']['captured_payment']['payfurl_transaction_id'])) {
    732682            // PayFURL-supplied Gateway Response
    733683            $payfurl_gateway_response = $_POST['payfurl_payment_details']['captured_payment']['payfurl_transaction_id'];
    734684
    735685            if(!empty($payfurl_gateway_response)) {
    736                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_gatewaytransactionid']] = $payfurl_gateway_response;
     686                $postData['gatewayResponseId'] = $payfurl_gateway_response;
    737687            }
    738688        }
     
    743693        }
    744694
    745         if($feed['meta']['profilerdonation_userdefined_clientpreferredcontactmethod'] !== "") {
    746             // Client Preferred Contact Method
    747             $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientpreferredcontactmethod']] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientpreferredcontactmethod']);
    748         }
    749 
    750         if($feed['meta']['profilerdonation_userdefined_clientprivacypreference'] !== "") {
    751             // Client Privacy Preference
    752 
    753             $privacy_field_value = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientprivacypreference']);
    754 
    755             if(!empty($privacy_field_value)) {
    756                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_clientprivacypreference']] = 'true';
    757             }
    758         }
     695        // Client Preferred Contact Method
     696        $postData['clientPreferredContactMethod'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientpreferredcontactmethod']);
     697
     698        // Client Privacy Preference
     699        $privacy_field_value = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_clientprivacypreference']);
     700        if(!empty($privacy_field_value)) {
     701            $postData['clientPrivacyPreference'] = 'true';
     702        }
     703
     704        // Comments field
     705        $comments = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_comments']);
     706
     707        if(!empty($feed['meta']['profilerdonation_commentsextra'])) {
     708            // Extra text to append to comments field
     709            $comments .= GFCommon::replace_variables($feed['meta']['profilerdonation_commentsextra'], $form, $entry, false, true, false, 'text');
     710        }
     711
     712        $comments = html_entity_decode($comments);
     713
     714        // Only allow ASCII printable characters.
     715        // This is a work-around to the API endpoint not allowing some characters
     716        $comments = preg_replace('/[^\x20-\x7E]/','', $comments);
     717
     718        // Comments
     719        $postData['comments'] = $comments;
    759720
    760721        if($this->get_field_value($form, $entry, $feed['meta']['profilerdonation_donationtype']) == "regular") {
    761722            // Recurring donation
    762             $postData['datatype'] = "PLG";
    763             $postData['pledgetype'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgefreq']);
    764 
    765             if(empty($postData['pledgetype'])) {
     723            $postData['dataType'] = "PLG";
     724            $postData['pledgeType'] = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_pledgefreq']);
     725
     726            if(empty($postData['pledgeType'])) {
    766727                // We assume a monthly pledge if no frequency is specified
    767                 $postData['pledgetype'] = "monthly";
     728                $postData['pledgeType'] = "monthly";
    768729            }
    769730
    770             if($feed['meta']['profilerdonation_userdefined_sourcecode'] !== "") {
    771                 // If it's recurring, the donation gets the pledge source code instead of the donation code
    772                 $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_sourcecode']] = $this->getDonationCode($feed, 'pledgesourcecode', $form);
    773             }
     731            // If it's recurring, the donation gets the pledge source code instead of the donation code
     732            $postData['donationSourceCode'] = $this->getDonationCode($feed, 'pledgesourcecode', $form);
    774733
    775734            // Store the donation type
    776             gform_add_meta($entry["id"], "profiler_type", "regular", $form_id);
     735            gform_add_meta($entry["id"], "profiler_type", "regular", $form['id']);
    777736
    778737        } elseif($useAsGateway == false) {
     
    786745
    787746            unset($postData['pledgeamount']);
    788             unset($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgeacquisitioncode']]);
    789             unset($postData['userdefined' . $feed['meta']['profilerdonation_userdefined_pledgesourcecode']]);
     747            unset($postData['regularAcquiredReason']);
     748            unset($postData['regularSourceCode']);
    790749
    791750        } else {
     
    810769            unset($postData['cardexpiry']);
    811770
    812             $postData['bankaccountname'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountname"]);
    813             $postData['bankbsb'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_bsb"]);
    814             $postData['bankaccountnumber'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountnumber"]);
     771            $postData['bsbAccName'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountname"]);
     772            $postData['bsb'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_bsb"]);
     773            $postData['bsbAccNum'] = $this->get_field_value($form, $entry, $feed['meta']["profilerdonation_bankdebit_accountnumber"]);
    815774           
    816775        } elseif($this->get_field_value($form, $entry, $feed['meta']['profilerdonation_paymentmethod']) == "paypal") {
     
    829788    public function process_feed_success($feed, $entry, $form, $pfResponse, $postData) {
    830789
    831         if(!isset($pfResponse['dataArray']['status']) || $pfResponse['dataArray']['status'] != "Pass") {
     790        if(isset($pfResponse['dataArray']['success']) && $pfResponse['dataArray']['success'] === true) {
     791            // Store the Integration ID as meta so we can use it later
     792            if(isset($pfResponse['dataArray']['integrationId'])) {
     793                gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['integrationId'], $form['id']);
     794                gform_add_meta($entry["id"], "profiler_integration_guid", $pfResponse['dataArray']['integrationGuid'], $form['id']);
     795                gform_add_meta($entry["id"], "profiler_sourcecode", $postData['donationSourceCode'], $form['id']);
     796            }
     797        } else {
    832798            // Profiler failed. Send the failure email.
    833             $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']['profiler_erroremailaddress']);
    834 
    835         } else {
    836             // Store the Integration ID as meta so we can use it later
    837             if(isset($pfResponse['dataArray']['id'])) {
    838                 gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['id'], $form['id']);
    839                 gform_add_meta($entry["id"], "profiler_sourcecode", $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_sourcecode']], $form['id']);
    840             }
    841         }
    842 
     799            $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']["profiler".$this->gffield_legacyname."_erroremailaddress"]);
     800        }
    843801    }
    844802
  • profiler-donations-gravityforms/trunk/class-profilermembership-gfaddon.php

    r2750662 r3211366  
    1010    protected static $_instance = null;
    1111
    12     protected $apifield_endpoint = "/ProfilerAPI/Legacy/";
    13     protected $apifield_apikey = "apikey";
    14     protected $apifield_apipass = "apipass";
    15     protected $apifield_ipaddress = 'udf';
    16     protected $apifield_formurl = true;
     12    protected $api_type = "json";
     13    protected $api_domain = "profilersoftware.com";
     14    protected $apifield_endpoint = "/ProfilerAPI/RapidEndpoint/";
     15    protected $apifield_apikey = "apiuser";
     16    protected $apifield_apipass = "apipassword";
     17    protected $apifield_ipaddress = 'requestIPAddress';
     18    protected $apifield_formurl = 'pageURL';
    1719    protected $gffield_legacyname = "membership";
    1820
     
    4345        $fields = parent::feed_settings_fields_custom();
    4446
    45         foreach($fields as $fieldKey => $fieldVal) {
    46             if($fieldVal['label'] == "Use Profiler As A Gateway?") {
    47                 $fields[$fieldKey]['choices'][] = array(
    48                     'label'         => 'Manual - Profiler will Process Payments, manually later on via a Pledge',
    49                     'value'         => 'manual',
    50                 );
     47        if(apply_filters('profiler_integration_allow_profiler_gateway', true) == true) {
     48            // This filter allows us to disable the Profiler Gateway feature on a site
     49
     50            foreach($fields as $fieldKey => $fieldVal) {
     51                if($fieldVal['label'] == "Use Profiler As A Gateway?") {
     52                    $fields[$fieldKey]['choices'][] = array(
     53                        'label'         => 'Manual - Profiler will Process Payments, manually later on via a Pledge',
     54                        'value'         => 'manual',
     55                    );
     56                }
    5157            }
     58
     59            $fields[] = array(
     60                "label" => 'UDF: Stored Card Number',
     61                "type" => "select",
     62                "name" => "profilerdonation_userdefined_storedcard_number",
     63                "required" => false,
     64                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card number in",
     65                "choices" => $userdefinedfields,
     66            );
     67
     68            $fields[] = array(
     69                "label" => 'UDF: Stored Card Expiry',
     70                "type" => "select",
     71                "name" => "profilerdonation_userdefined_storedcard_expiry",
     72                "required" => false,
     73                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card expiry in",
     74                "choices" => $userdefinedfields,
     75            );
     76
     77            $fields[] = array(
     78                "label" => 'UDF: Stored Card CCV',
     79                "type" => "select",
     80                "name" => "profilerdonation_userdefined_storedcard_ccv",
     81                "required" => false,
     82                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card CCV in",
     83                "choices" => $userdefinedfields,
     84            );
     85
     86            $fields[] = array(
     87                "label" => 'UDF: Stored Card Name',
     88                "type" => "select",
     89                "name" => "profilerdonation_userdefined_storedcard_name",
     90                "required" => false,
     91                "tooltip" => "Pick the Profiler User Defined Field you wish to store the card name in",
     92                "choices" => $userdefinedfields,
     93            );
     94
    5295        }
    53 
    54         $fields[] = array(
    55             "label" => 'UDF: Stored Card Number',
    56             "type" => "select",
    57             "name" => "profilerdonation_userdefined_storedcard_number",
    58             "required" => false,
    59             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card number in",
    60             "choices" => $userdefinedfields,
    61         );
    62 
    63         $fields[] = array(
    64             "label" => 'UDF: Stored Card Expiry',
    65             "type" => "select",
    66             "name" => "profilerdonation_userdefined_storedcard_expiry",
    67             "required" => false,
    68             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card expiry in",
    69             "choices" => $userdefinedfields,
    70         );
    71 
    72         $fields[] = array(
    73             "label" => 'UDF: Stored Card CCV',
    74             "type" => "select",
    75             "name" => "profilerdonation_userdefined_storedcard_ccv",
    76             "required" => false,
    77             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card CCV in",
    78             "choices" => $userdefinedfields,
    79         );
    80 
    81         $fields[] = array(
    82             "label" => 'UDF: Stored Card Name',
    83             "type" => "select",
    84             "name" => "profilerdonation_userdefined_storedcard_name",
    85             "required" => false,
    86             "tooltip" => "Pick the Profiler User Defined Field you wish to store the card name in",
    87             "choices" => $userdefinedfields,
    88         );
    8996
    9097        return $fields;
  • profiler-donations-gravityforms/trunk/class-profilerpostdonate-gfaddon.php

    r2750662 r3211366  
    1010    protected static $_instance = null;
    1111
    12     protected $apifield_endpoint = "/ProfilerAPI/LegacyPost/";
    13     protected $apifield_apikey = "api_user";
    14     protected $apifield_apipass = "api_pass";
    15     protected $apifield_ipaddress = 'udf';
    16     protected $apifield_formurl = true;
     12    protected $api_type = "json";
     13    protected $api_domain = "profilersoftware.com";
     14    protected $apifield_endpoint = "/ProfilerAPI/RapidEndpoint/";
     15    protected $apifield_apikey = "apiuser";
     16    protected $apifield_apipass = "apipassword";
     17    protected $apifield_ipaddress = 'requestIPAddress';
     18    protected $apifield_formurl = 'pageURL';
    1719    protected $gffield_legacyname = "donation";
    1820    protected $supports_custom_fields = true;
     
    5961
    6062        $fields[] = array(
    61             "label" => 'UDF: Comments',
    62             "type" => "select",
    63             "name" => "profilerdonation_userdefined_comments",
    64             "required" => false,
    65             "tooltip" => "Pick the Profiler User Defined Field you wish to use for the Comments field",
    66             "choices" => $userdefinedfields,
    67         );
    68 
    69         $fields[] = array(
    7063            "label" => 'Extra Comments Text',
    7164            "type" => "textarea",
    7265            "name" => "profilerdonation_commentsextra",
    73             "required" => true,
     66            "required" => false,
    7467            "class" => "merge-tag-support",
    7568            "tooltip" => "This is extra text to be sent to Profiler as an Interaction. Protip: Include Gravity Forms Merge Fields in this textarea to accept user input.",
     
    109102    public function process_feed_custom($feed, $entry, $form, $postData, $fromValidatorProcessPFGateway = false) {
    110103
    111         $postData['method'] = "integration.send";
    112104        $postData['datatype'] = "OLDON";
    113105
     
    123115        // Comments
    124116        $postData['comments'] = $comments;
    125         $postData['userdefined' . $feed['meta']['profilerdonation_userdefined_comments']] = $comments;
    126        
     117
    127118        $gfEntryId = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_gfentryid']);
    128119        $pfIntegrationId = $this->get_field_value($form, $entry, $feed['meta']['profilerdonation_profilerid']);
     
    147138
    148139        // This is the ID of the actual donation entry
    149         $postData['HoldingID'] = $pfIntegrationId;
     140        $postData['holdingId'] = $pfIntegrationId;
    150141
    151142        return $postData;
     
    154145    public function process_feed_success($feed, $entry, $form, $pfResponse, $postData) {
    155146
    156         if(!isset($pfResponse['dataArray']['status']) || $pfResponse['dataArray']['status'] != "Pass") {
     147        if(isset($pfResponse['dataArray']['success']) && $pfResponse['dataArray']['success'] === true) {
     148            // Store the Integration ID as meta so we can use it later
     149            if(isset($pfResponse['dataArray']['integrationId'])) {
     150                gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['integrationId'], $form['id']);
     151                gform_add_meta($entry["id"], "profiler_integration_guid", $pfResponse['dataArray']['integrationGuid'], $form['id']);
     152            }
     153        } else {
    157154            // Profiler failed. Send the failure email.
    158             $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']['profiler_erroremailaddress']);
    159 
    160         } else {
    161             // Store the Integration ID as meta so we can use it later
    162             if(isset($pfResponse['dataArray']['id']))
    163                 gform_add_meta($entry["id"], "profiler_integrationid", $pfResponse['dataArray']['id'], $form['id']);
     155            $this->sendFailureEmail($entry, $form, $pfResponse, $feed['meta']["profiler".$this->gffield_legacyname."_erroremailaddress"]);
    164156        }
    165 
    166157    }
    167158
  • profiler-donations-gravityforms/trunk/index.php

    r3136560 r3211366  
    11<?php
    22/*
    3 Plugin Name: Profiler Donations - Gravity Forms Add-On
     3Plugin Name: Gravity Forms + Profiler Add-On
    44Plugin URI: https://mediarealm.com.au/
    55Description: Integrates Gravity Forms with Profiler, enabling donation data and more to be sent directly to Profiler.
    6 Version: 2.4.3
     6Version: 2.5.0
    77
    88Author: Media Realm
     
    6666        //GFAddOn::register('GFProfilerEvents');
    6767
     68        // This is a settings screen to list all Profiler feeds in the system
     69        require_once('class-feedlist-gfaddon.php');
     70        GFAddOn::register('GF_Profiler_FeedList');
     71
    6872        // Include some random helper functions
    6973        require_once(plugin_dir_path(__FILE__) . '/shortcodes.php');
  • profiler-donations-gravityforms/trunk/readme.txt

    r3136560 r3211366  
    2222
    2323== Changelog ==
     24
     25= 2.5.0 =
     26
     27This is a substantial update. Please backup your site before upgrading, and test all your integrations thoroughly after upgrading this plugin.
     28
     29* Use the new Profiler Core API for Donations/payments. This removes the UDF field config and automates it within Profiler.
     30* Create 'Profiler Feed List' setting screen, for quick access to all configured feeds on your site
     31* Remove Profiler Logs fields, and move these to an entry metabox.
     32* Donation Feed: Add Extra Comments field
     33* Donation Feed: Automatic formatting of Australian phone numbers
     34* Add Profiler icon to all Feeds
     35* Donation Feed: Add new fields for gender, interactions, roles, membership mapping and payment split text.
     36* Membership Feed: Hide manual payment fields if Profiler-driven payments have been disabled
    2437
    2538= 2.4.3 =
  • profiler-donations-gravityforms/trunk/sync_users.php

    r2750662 r3211366  
    232232
    233233        if(empty($options['auth_apikey']) || empty($options['auth_apipass']) || empty($options['pf_database']) || empty($options['pf_domain'])) {
    234             $this->log("Profiler Users not configured correctly");
    235234            return;
    236235        }
  • profiler-donations-gravityforms/trunk/woocommerce/integration.php

    r2984822 r3211366  
    2323        $this->dbname                      = $this->get_option( 'dbname' );
    2424        $this->apikey                      = $this->get_option( 'apikey' );
     25
     26        // Upgrade config to new domain
     27        $this->instancedomainname = str_replace(".profilersystem.com", ".profilersoftware.com", $this->instancedomainname);
    2528
    2629        // Actions.
     
    5457                'title'             => 'Profiler Instance Domain Name',
    5558                'type'              => 'text',
    56                 'description'       => 'e.g. example.profilersystem.com',
     59                'description'       => 'e.g. example.profilersoftware.com',
    5760                'desc_tip'          => true,
    5861                'default'           => '',
     
    8588                'desc_tip'          => true,
    8689                'default'           => ''
    87             ),
    88             'udf_sourcecode' => array(
    89                 'title'             => 'UDF: Donation Source Code',
    90                 'type'              => 'select',
    91                 'description'       => '',
    92                 'desc_tip'          => true,
    93                 'default'           => '',
    94                 'options'           => $this->options_udf(),
    95             ),
    96             'udf_clientip' => array(
    97                 'title'             => 'UDF: Client IP Address',
    98                 'type'              => 'select',
    99                 'description'       => '',
    100                 'desc_tip'          => true,
    101                 'default'           => '',
    102                 'options'           => $this->options_udf(),
    103             ),
    104             'udf_transactionid' => array(
    105                 'title'             => 'UDF: Gateway Transaction ID',
    106                 'type'              => 'select',
    107                 'description'       => '',
    108                 'desc_tip'          => true,
    109                 'default'           => '',
    110                 'options'           => $this->options_udf(),
    11190            ),
    11291        );
     
    204183
    205184        // Build API payload
    206         $url = 'https://' . $this->instancedomainname . '/ProfilerAPI/Legacy/';
     185        $url = 'https://' . $this->instancedomainname . '/ProfilerAPI/RapidEndpoint/';
    207186        $profiler_data = array(
    208             'DB' => $this->dbname,
    209             'apikey' => $this->apikey,
    210             'apipass' => $this->get_option('apipass'),
    211             'method' => 'integration.send',
     187            'apiuser' => $this->apikey,
     188            'apipassword' => $this->get_option('apipass'),
    212189            'datatype' => 'OLDON',
    213190
    214191            'amount' => $total,
    215             'donationamount' => $total,
    216             'sourcecode' => $this->get_option('sourcecode'),
     192            'donationAmount' => $total,
     193            'donationSourceCode' => $this->get_option('sourcecode'),
    217194            'status' => 'Approved',
    218195
    219196            'clientname' => $first_name . ' ' . $last_name,
    220             'firstname' => $first_name,
     197            'firstName' => $first_name,
    221198            'surname' => $last_name,
    222199
     
    233210        );
    234211
    235         if($this->get_option('udf_sourcecode') != '') {
    236             // Source code as a UDF
    237             $profiler_data['userdefined' . $this->get_option('udf_sourcecode')] = $this->get_option('sourcecode');
    238         }
     212        // Source code as a UDF
     213        $profiler_data['donationSourceCode'] = $this->get_option('sourcecode');
    239214
    240215        if($order->needs_payment()) {
     
    243218        }
    244219
    245         if($this->get_option('udf_clientip') != '') {
    246             // Client IP Address
    247             $profiler_data['userdefined' . $this->get_option('udf_clientip')] = $this->get_client_ip_address();
    248         }
    249 
    250         if($this->get_option('udf_transactionid') != '') {
    251             // Payment Gateway Transaction ID
    252             $profiler_data['userdefined' . $this->get_option('udf_transactionid')] = $order->get_transaction_id();
    253         }
     220        // Client IP Address
     221        $profiler_data['requestIPAddress'] = $this->get_client_ip_address();
     222
     223        // Payment Gateway Transaction ID
     224        $profiler_data['gatewayResponseId'] = $order->get_transaction_id();
    254225
    255226        // Push data to Profiler
     
    350321
    351322        $ch = curl_init();
    352         curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query(array("DB" => $profiler_query['DB'], "Call" => 'submit')));
     323        curl_setopt($ch, CURLOPT_URL, $url);
    353324        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    354         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen(http_build_query($profiler_query))));
    355         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($profiler_query));
     325        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($profiler_query));
     326        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    356327        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    357328
     
    386357            "dataSent" => $profiler_query,
    387358            "data" => $result,
    388             "dataXML" => simplexml_load_string($result),
    389             "dataArray" => json_decode(json_encode((array)simplexml_load_string($result)), 1),
     359            "dataArray" => json_decode($result, true),
    390360            "cURLError" => $cURL_error,
    391361            "cURL_SSL_Mode" => $ssl_mode,
    392362        );
    393     }
    394 
    395     private function options_udf() {
    396         $fields = array("0" => "");
    397 
    398         for($i = 1; $i <= 99; $i++) {
    399             $fields[$i] = "User Defined Field " . $i;
    400         }
    401 
    402         return $fields;
    403363    }
    404364
Note: See TracChangeset for help on using the changeset viewer.