Plugin Directory

Changeset 3178082


Ignore:
Timestamp:
10/29/2024 02:00:11 PM (17 months ago)
Author:
trustist
Message:

Bug fix on Gravity Forms integration when name is a single line input, added description field selector and allowed relative cancellation URL fragments

Location:
trustistecommerce/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trustistecommerce/trunk/includes/gravityforms/TrustistGFPayments.php

    r3131773 r3178082  
    295295                'required' => false,
    296296            ],
     297            [
     298                'name' => 'description',
     299                'label' => esc_html__('Description', 'trustistgfm'),
     300                'required' => false,
     301            ],
    297302        );
    298303
     
    361366
    362367        $redirect_url = $this->return_url($form['id'], $entry['id']);
    363         $cancel_url = !empty($feed_meta['cancel_url']) && $feed_meta['cancel_url'] ? $feed_meta['cancel_url'] : $redirect_url;
     368        $cancel_url = !empty($feed_meta['cancel_url']) && $feed_meta['cancel_url'] ? $this->format_url_fragment($feed_meta['cancel_url']) : $redirect_url;
    364369
    365370        $orderid = $entry['id'];
     
    369374        $item_name = $this->get_item_name($line_items, $discounts);
    370375
    371         $int_name = isset($feed_meta['billingInformation_name']) ? $feed_meta['billingInformation_name'] : '';
    372376        $int_email = isset($feed_meta['billingInformation_email']) ? $feed_meta['billingInformation_email'] : '';
    373377        $buyer_email = isset($entry[$int_email]) ? $entry[$int_email] : '';
    374         $buyer_name = $this->extractAndConcatenate($entry, $int_name);
     378
     379        $int_name = isset($feed_meta['billingInformation_name']) ? $feed_meta['billingInformation_name'] : '';
     380        $buyer_name = isset($entry[$int_name]) ? $entry[$int_name] : $this->extractAndConcatenate($entry, $int_name);
     381
     382        $int_description = isset($feed_meta['billingInformation_description']) ? $feed_meta['billingInformation_description'] : '';
     383        $description = isset($entry[$int_description]) ? $entry[$int_description] : $item_name;
    375384
    376385        $this->log_debug(__METHOD__ . '(): Entry is being converted => ' . print_r($entry, true));
     
    381390            switch ($feed['meta']['transactionType']) {
    382391                case 'product':
    383                     $paymentRequest = new TrustistPaymentRequest($total, $orderid, $item_name, $buyer_name, $buyer_email, $redirect_url, $cancel_url);
     392                    $paymentRequest = new TrustistPaymentRequest($total, $orderid, $description, $buyer_name, $buyer_email, $redirect_url, $cancel_url);
    384393
    385394                    $this->log_debug(__METHOD__ . '(): Payment request => ' . print_r($paymentRequest, true));
     
    421430        return $payment['payLink'];
    422431    }
    423 
     432       
    424433    function extractAndConcatenate($array, $key_prefix = '')
    425434    {
     
    427436
    428437        foreach ($array as $key => $value) {
    429             // Check if the key starts with '7.' or is exactly '7'
     438            // Explicitly trim any unexpected whitespace in key_prefix
     439            $key_prefix = trim($key_prefix);
     440
     441            // Check if the key starts with the prefix and a dot, or is exactly the prefix
    430442            if (strpos($key, $key_prefix . '.') === 0 || $key === $key_prefix) {
    431443                // Concatenate the values separated by a space
     
    439451        return trim($result);
    440452    }
    441 
    442     private function return_url($form_id, $entry_id)
    443     {
    444         $pageURL = GFCommon::is_ssl() ? 'https://' : 'http://';
    445 
    446         // Sanitize SERVER_PORT
    447         $server_port = sanitize_text_field(wp_unslash($_SERVER['SERVER_PORT']));
    448 
     453   
     454    private function format_url_fragment($fragment)
     455    {
    449456        // Sanitize SERVER_NAME
    450457        $server_name = isset($_SERVER['SERVER_NAME']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])) : '';
    451 
     458   
     459        // Check if the fragment starts with "http://" or "https://"
     460        if (preg_match('/^https?:\/\//', $fragment)) {
     461            return $fragment; // Already a valid URL
     462        }
     463   
     464        // Prepend "http://<server_name>/" if the fragment isn't a full URL
     465        $protocol = GFCommon::is_ssl() ? 'https://' : 'http://';
     466        $formatted_url = $protocol . rtrim($server_name, '/') . '/' . ltrim($fragment, '/');
     467        return $formatted_url;
     468    }
     469   
     470    private function return_url($form_id, $entry_id)
     471    {
    452472        // Sanitize REQUEST_URI
    453473        $request_uri = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '';
    454 
    455         if ($server_port != '80') {
    456             $pageURL .= $server_name . ':' . $server_port . $request_uri;
    457         } else {
    458             $pageURL .= $server_name . $request_uri;
    459         }
    460 
     474   
     475        // Combine server name and request URI with SSL check
     476        $pageURL = $this->format_url_fragment($request_uri);
     477   
     478        // Build query arguments
    461479        $ids_query = "ids={$form_id}|{$entry_id}";
    462480        $ids_query .= '&hash=' . wp_hash($ids_query);
    463 
     481   
    464482        // Use add_query_arg to safely add query arguments to the URL
    465483        $url = add_query_arg('gf_tr_return', base64_encode($ids_query), $pageURL);
    466 
     484   
    467485        return $url;
    468486    }
  • trustistecommerce/trunk/readme.txt

    r3174460 r3178082  
    44Requires at least: 5.4
    55Tested up to: 6.5
    6 Stable tag: 1.0.2
     6Stable tag: 1.0.3
    77Requires PHP: 7.2
    88License: GPLv2
  • trustistecommerce/trunk/trustist-ecommerce.php

    r3174460 r3178082  
    44Plugin URI: https://www.trustistecommerce.com
    55Description: Take Open Banking or credit card payments in the UK using TrustistEcommerce.
    6 Version: 1.0.2
     6Version: 1.0.3
    77Author: Trustist
    88Author URI: https://www.trustist.com
     
    1212defined( 'ABSPATH' ) or die();
    1313
    14 \define('TRUSTISTPLUGIN_VERSION', '1.0.2');
     14\define('TRUSTISTPLUGIN_VERSION', '1.0.3');
    1515\define('TRUSTISTPLUGIN_SLUG', 'trustistecommerce');
    1616\define('TRUSTISTPLUGIN_NAME', 'TrustistEcommerce');
Note: See TracChangeset for help on using the changeset viewer.