Plugin Directory

Changeset 3009319


Ignore:
Timestamp:
12/13/2023 10:30:22 AM (2 years ago)
Author:
indigonl
Message:

version 2.0.0

Location:
gf-mollie-by-indigo
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • gf-mollie-by-indigo/tags/2.0.0/class-gf-mollie.php

    r2227779 r3009319  
    88
    99    protected $_version = GF_MOLLIE_BY_INDIGO_VERSION;
    10     protected $_min_gravityforms_version = '2.2.5';
     10    protected $_min_gravityforms_version = '2.8.0';
    1111    protected $_slug = 'gf-mollie-by-indigo';
    1212    protected $_path = 'gf-mollie-by-indigo/gf-mollie-by-indigo.php';
     
    2424    protected $_capabilities_form_settings = 'gravityforms_mollie';
    2525    protected $_capabilities_uninstall = 'gravityforms_mollie';
    26 
    2726    // Automatic upgrade enabled
    2827    protected $_enable_rg_autoupgrade = false;
    29 
    3028    private static $_instance = null;
    31 
    3229    public static function get_instance() {
    3330        if ( self::$_instance == null ) {
     
    3734        return self::$_instance;
    3835    }
    39 
    4036    private function __clone() {
    4137    } /* do nothing */
    42 
    4338    public function init_frontend() {
    4439        parent::init_frontend();
    45 
    46         //add_filter( 'gform_disable_post_creation', array( $this, 'delay_post' ), 10, 3 );
    47         //add_filter( 'gform_disable_notification', array( $this, 'delay_notification' ), 10, 4 );
    48     }
    49 
     40    }
    5041    public function init() {
    5142        parent::init();
     
    5445        add_filter( 'gform_replace_merge_tags', array( $this, 'gf_replace_merge_tags' ), 10, 7);
    5546    }
    56 
    57 
    58    
    5947    /*
    6048     *  Remove all billing fields from the mollie feed
     
    6452        return $fields;
    6553    }
    66 
    67 
    68    
    69    
    7054    public function feed_list_no_item_message() {
    7155        return parent::feed_list_no_item_message();
     
    8064        $fields = array(
    8165            array(
    82                 'type'  => 'helper_text',
     66                'type'  =>  __('helper_text',  'gf-mollie-by-indigo'),
    8367                'name'  => 'help',
    8468                'label' => '',
    8569            ),
    86 
    8770            array(
    88                 'label'   => 'Use default api key',
     71                'label'   =>  __('Use default api key',  'gf-mollie-by-indigo'),
    8972                'type'    => 'checkbox',
    9073                'name'    => 'useDefaultKey',
     
    9780                )
    9881            ),
    99 
    10082            array(
    10183                'name'     => 'mollieKey',
    10284                'label'    => esc_html__( 'Mollie api key ', 'gf-mollie-by-indigo' ),
    10385                'type'     => 'text',
    104 
    10586                'class'    => 'medium',
    10687                'required' => false,
     
    126107        //-------------------------------------------------------------------------------------------------
    127108
    128        
    129109        //Add post fields if form has a post
    130110        $form = $this->get_current_form();
     
    148128    }
    149129
    150 
    151130    /**
    152131     * Prevent the GFPaymentAddOn version of the options field being added to the feed settings.
     
    159138
    160139    public function save_feed_settings( $feed_id, $form_id, $settings ) {
    161 
    162140        //--------------------------------------------------------
    163141        //For backwards compatibility
     
    176154            return false;
    177155        }
    178 
    179156        $settings = $feed['meta'];
    180        
    181         //--------------------------------------------------------
    182157
    183158        return parent::save_feed_settings( $feed_id, $form_id, $settings );
     
    185160
    186161    //------ SENDING TO MOLLIE -----------//
    187 
    188162    public function redirect_url( $feed, $submission_data, $form, $entry ) {
    189 
    190 
    191 
    192 
    193163        if ( ! rgempty( 'gf_mollie_return', $_GET ) ) {
    194164            return false;
    195165        }
    196 
    197166        //updating lead's payment_status to Processing
    198167        GFAPI::update_entry_property( $entry['id'], 'payment_status', 'Processing' );
    199168
    200169        $payment_amount = rgar( $submission_data, 'payment_amount' );
    201                
     170        //  Make sure that we always has two decimals
     171        $payment_amount = number_format($payment_amount, 2, '.', '');
     172
    202173        $mollieKey = $this->get_mollie_key( $feed );
    203174        if ( ! $mollieKey ) {
     
    206177        }
    207178       
    208         $mollie = new Mollie_API_Client;
     179        $mollie = new \Mollie\Api\MollieApiClient();
    209180        $mollie->setApiKey($mollieKey);
    210        
    211181        $order_id = time();
    212        
    213182        $return_url =  $this->return_url( $form['id'], $entry['id'] );
    214183       
     
    221190        // Allow Mollie Payment Create adjustments
    222191        $mollie_request_args = apply_filters( 'gf_mollie_request_args', array(
    223             "amount"       => $payment_amount,
     192            "amount"       => array("currency" => "EUR", "value" => $payment_amount),
    224193            "description"  => $description,
    225194            "redirectUrl"  => $return_url,
     
    235204        //  Store transaction id as unique identification in gravityforms entry
    236205        GFAPI::update_entry_property( $entry['id'], 'transaction_id',  $payment->id );
    237 
    238         $url = $payment->links->paymentUrl;
    239 
    240 
     206        $url = $payment->getCheckoutUrl();;
    241207        $this->log_debug( __METHOD__ . "(): Sending to Mollie: {$url}" );
    242 
    243208        return $url;
    244209    }
     
    251216    public function return_url( $form_id, $lead_id ) {
    252217        $pageURL = GFCommon::is_ssl() ? 'https://' : 'http://';
    253 
    254218        $server_port = apply_filters( 'gform_mollie_return_url_port', $_SERVER['SERVER_PORT'] );
    255 
    256219        if ( $server_port != '80' ) {
    257220            $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI'];
     
    260223        }
    261224
    262 
    263 
    264 
    265225        $ids_query = "ids={$form_id}|{$lead_id}";
    266226        $ids_query .= '&hash=' . wp_hash( $ids_query );
    267 
    268227        $url = add_query_arg( 'gf_mollie_return', base64_encode( $ids_query ), $pageURL );
    269228
    270 
    271 
    272229        $query = 'gf_mollie_return=' . base64_encode( $ids_query );
    273         /**
    274          * Filters PayPal's return URL, which is the URL that users will be sent to after completing the payment on PayPal's site.
    275          * Useful when URL isn't created correctly (could happen on some server configurations using PROXY servers).
    276          *
    277          * @since 2.4.5
    278          *
    279          * @param string  $url  The URL to be filtered.
    280          * @param int $form_id  The ID of the form being submitted.
    281          * @param int $entry_id The ID of the entry that was just created.
    282          * @param string $query The query string portion of the URL.
    283          */
     230        //  Allow modification of the mollie return url
    284231        return apply_filters( 'gform_mollie_return_url', $url, $form_id, $lead_id, $query  );
    285232
     
    288235    public static function maybe_thankyou_page() {
    289236        $instance = self::get_instance();
    290 
    291237        if ( ! $instance->is_gravityforms_supported() ) {
    292238            return;
     
    295241        if ( $str = rgget( 'gf_mollie_return' ) ) {
    296242            $str = base64_decode( $str );
    297 
    298243            parse_str( $str, $query );
    299244            if ( wp_hash( 'ids=' . $query['ids'] ) == $query['hash'] ) {
    300245                list( $form_id, $lead_id ) = explode( '|', $query['ids'] );
    301 
    302246                $form = GFAPI::get_form( $form_id );
    303247                $lead = GFAPI::get_entry( $lead_id );
    304 
    305248                if ( ! class_exists( 'GFFormDisplay' ) ) {
    306249                    require_once( GFCommon::get_base_path() . '/form_display.php' );
    307250                }
    308 
    309251                $confirmation = GFFormDisplay::handle_confirmation( $form, $lead, false );
    310 
    311252                if ( is_array( $confirmation ) && isset( $confirmation['redirect'] ) ) {
    312253                    header( "Location: {$confirmation['redirect']}" );
    313254                    exit;
    314255                }
    315 
    316256                GFFormDisplay::$submission[ $form_id ] = array( 'is_confirmation' => true, 'confirmation_message' => $confirmation, 'form' => $form, 'lead' => $lead );
    317257            }
     
    321261
    322262    //------- PROCESSING MOLLIE CALLBACK -----------//
    323 
    324263    public function callback() {
    325 
    326264        if ( ! $this->is_gravityforms_supported() ) {
    327265            return false;
    328266        }
    329 
    330267        $this->log_debug( __METHOD__ . '(): request received. Starting to process => ' . print_r( $_POST, true ) );
    331 
    332268        $this->log_debug( __METHOD__ . '(): request received. Starting to process GET=> ' . print_r( $_GET, true ) );
    333 
    334        
    335269        $custom_field = rgpost( 'id' );
    336270        if ( empty( $custom_field ) ) {
    337271            $this->log_error( __METHOD__ . '(): Requests should have an id' );
    338 
    339             return false;
    340         }
    341 
     272            return false;
     273        }
    342274       
    343275        //  Get the entry
     
    350282   
    351283        try {
    352 
    353             $mollie = new Mollie_API_Client;
    354             $mollieKey = $mollieKey = $this->get_mollie_key( $feed );
     284            $mollie = new \Mollie\Api\MollieApiClient();
     285            $mollieKey = $this->get_mollie_key( $feed );
    355286            $mollie->setApiKey($mollieKey);
    356287            /*
     
    359290            $payment  = $mollie->payments->get($_POST["id"]);
    360291            $order_id = $payment->metadata->order_id;
    361 
    362292            $this->log_debug( __METHOD__ . '(): Mollie Payment object'. print_r( $payment, true ) );
    363293            $this->log_debug( __METHOD__ . '(): Mollie Payment entry id'. $payment->metadata->entry_id );
    364            
    365            
    366294            $entry = GFAPI::get_entry(  $payment->metadata->entry_id );
    367295            /*
     
    369297             */
    370298            do_action( 'gform_mollie_payment_retreived', $entry, $payment );
    371             if ( ! $payment->isRefunded() ) {
    372                 if ( $payment->isPaid() == true ) {
    373                     /*
    374                      * At this point you'd probably want to start the process of delivering the product to the customer.
    375                      */
    376                     $this->log_debug( __METHOD__ . '(): Mollie status paid' );
    377 
    378                     $action['id']             = $order_id . '_' . $payment->status;
    379                     $action['type']           = 'complete_payment';
    380                     $action['transaction_id'] = $order_id;
    381                     $action['amount']         = $payment->amount;
    382                     $action['entry_id']       = $entry['id'];
    383                     $action['payment_date']   = gmdate( 'y-m-d H:i:s' );
    384                     $action['payment_method'] = 'Mollie';
    385 
    386                     return $action;
    387 
    388 
    389                 } else {
    390                     /*
    391                      * The payment isn't paid and
    392                      */
    393                     $this->log_debug( __METHOD__ . '(): Mollie status not paid' );
    394 
    395                     $action['id']             = $order_id . '_' . $payment->status;
    396                     $action['type']           = 'fail_payment';
    397                     $action['transaction_id'] = $order_id;
    398                     $action['entry_id']       = $entry['id'];
    399                     $action['amount']         = $payment->amount;
    400                     return $action;
    401                 }
     299
     300            if ($payment->isPaid() && !$payment->hasRefunds() && !$payment->hasChargebacks()) {
     301                /*
     302                 * The payment is paid and isn't refunded or charged back.
     303                 * At this point you'd probably want to start the process of delivering the product to the customer.
     304                 */
     305                $this->log_debug( __METHOD__ . '(): Mollie status paid' );
     306                $action['id']             = $order_id . '_' . $payment->status;
     307                $action['type']           = 'complete_payment';
     308                $action['transaction_id'] = $order_id;
     309                $action['amount']         = $payment->amount->value;
     310                $action['entry_id']       = $entry['id'];
     311                $action['payment_date']   = gmdate( 'y-m-d H:i:s' );
     312                $action['payment_method'] = 'Mollie';
     313                return $action;
     314            } else {
     315                /*
     316                 * The payment isn't paid
     317                 */
     318                $this->log_debug( __METHOD__ . '(): Mollie status not paid' );
     319                $action['id']             = $order_id . '_' . $payment->status;
     320                $action['type']           = 'fail_payment';
     321                $action['transaction_id'] = $order_id;
     322                $action['entry_id']       = $entry['id'];
     323                $action['amount']         = $payment->amount->value;
     324                return $action;
    402325            }
    403326        } catch (Mollie_API_Exception $e) {
    404                 /*
    405                  * The Api failed
    406                  */
    407                  $this->log_debug( __METHOD__ . '(): API call failed: ' . htmlspecialchars($e->getMessage()));
    408         }
    409 
     327            /*
     328             * The Api failed
     329             */
     330             $this->log_debug( __METHOD__ . '(): API call failed: ' . htmlspecialchars($e->getMessage()));
     331        }
    410332        return false;
    411 
    412333    }
    413334
    414335    public function get_payment_feed( $entry, $form = false ) {
    415 
    416336        $feed = parent::get_payment_feed( $entry, $form );
    417 
    418337        if ( empty( $feed ) && ! empty( $entry['id'] ) ) {
    419338            //looking for feed created by legacy versions
    420339            $feed = $this->get_mollie_feed_by_entry( $entry['id'] );
    421340        }
    422 
    423341        $feed = apply_filters( 'gform_mollie_get_payment_feed', $feed, $entry, $form ? $form : GFAPI::get_form( $entry['form_id'] ) );
    424 
    425342        return $feed;
    426343    }
    427344
    428 
    429 
    430345    private function get_mollie_feed_by_entry( $entry_id ) {
    431 
    432346        $feed_id = gform_get_meta( $entry_id, 'mollie_feed_id' );
    433347        $feed    = $this->get_feed( $feed_id );
    434 
    435348        return ! empty( $feed ) ? $feed : false;
    436349    }
    437350
    438351    public function get_entry( $custom_field ) {
    439 
    440352        //Getting entry associated with this IPN message (entry id is sent in the 'custom' field)
    441353        list( $entry_id, $hash ) = explode( '|', $custom_field );
    442354        $hash_matches = wp_hash( $entry_id ) == $hash;
    443 
    444355        //allow the user to do some other kind of validation of the hash
    445356        $hash_matches = apply_filters( 'gform_mollie_hash_matches', $hash_matches, $entry_id, $hash, $custom_field );
    446 
    447357        //Validates that Entry Id wasn't tampered with
    448358        if ( ! rgpost( 'test_ipn' ) && ! $hash_matches ) {
    449359            $this->log_error( __METHOD__ . "(): Entry ID verification failed. Hash does not match. Custom field: {$custom_field}. Aborting." );
    450 
    451             return false;
    452         }
    453 
     360            return false;
     361        }
    454362        $this->log_debug( __METHOD__ . "(): IPN message has a valid custom field: {$custom_field}" );
    455 
    456363        $entry = GFAPI::get_entry( $entry_id );
    457 
    458364        if ( is_wp_error( $entry ) ) {
    459365            $this->log_error( __METHOD__ . '(): ' . $entry->get_error_message() );
    460 
    461             return false;
    462         }
    463 
     366            return false;
     367        }
    464368        return $entry;
    465369    }
    466 
    467370
    468371    public function is_callback_valid() {
     
    471374            $valid = false;
    472375        }
    473 
    474376        return apply_filters( 'gf_mollie_is_callback_valid', $valid );
    475377    }
     
    479381            return false;
    480382        }
    481 
    482383        return array(
    483384                'complete_payment'          => esc_html__( 'Mollie Payment Completed', 'gf-mollie-by-indigo' ),
     
    489390        $notifications_to_send  = array();
    490391        $selected_notifications = rgars( $feed, 'meta/selectedNotifications' );
    491 
    492392        if ( is_array( $selected_notifications ) ) {
    493393            // Make sure that the notifications being sent belong to the form submission event, just in case the notification event was changed after the feed was configured.
     
    496396                    continue;
    497397                }
    498 
    499398                $notifications_to_send[] = $notification['id'];
    500399            }
    501400        }
    502 
    503401        return $notifications_to_send;
    504402    }
    505 
    506 
    507 
    508 
    509403
    510404    public function plugin_settings_fields() {
     
    513407                       esc_html__( 'Submit your default API key in the field below. You can override this field in the individual form settings if needed.', 'gf-mollie-by-indigo' ) .
    514408                       '</p>';
    515 
    516409        return array(
    517410            array(
     
    519412                'description' => $description,
    520413                'fields'      => array(
    521 
    522 
    523414                    array(
    524415                        'type'  => 'helper_text',
     
    540431                        ),
    541432                    ),
    542 
    543 
    544             ),
    545             ));
    546 
    547 
    548 
    549     }
     433                ),
     434            )
     435        );
     436    }
     437
    550438    //  Return mollie key for current feed
    551439    public function get_mollie_key( $feed ) {
    552        
    553440        if ( isset( $feed['meta']['useDefaultKey'] ) && $feed['meta']['useDefaultKey'] == true ) {
    554441            $mollieKey = $this->get_plugin_setting( 'mollieKey' );
    555 
    556442        } else {
    557443            $mollieKey = $feed['meta']['mollieKey'];
     
    559445        return $mollieKey;
    560446    }
    561 
    562447
    563448    /*
     
    576461            return $text;
    577462        }
    578 
    579 
    580463        //The current payment status of the entry (ie “Authorized”, “Paid”, “Processing”, “Pending”, “Active”, “Expired”, “Failed”, “Cancelled”, “Approved”, “Reversed”, “Refunded”, “Voided”).
    581464        if ( isset($entry['payment_status'] ) ) {
     
    584467            $replace = '';
    585468        }
    586 
    587469        $text = str_replace($custom_merge_tag, $replace, $text);
    588470        return $text;
  • gf-mollie-by-indigo/tags/2.0.0/gf-mollie-by-indigo.php

    r2946580 r3009319  
    44Plugin URI: http://www.indigowebstudio.nl
    55Description: Integrates Gravity Forms with Mollie, enabling end users to purchase goods and services through Gravity Forms.
    6 Version: 1.11.7
     6Version: 2.0.0
    77Author: Indigo webstudio
    88Author URI: http://www.indigowebstudio.nl
     
    3030
    3131
    32 define( 'GF_MOLLIE_BY_INDIGO_VERSION', '1.11.7' );
     32define( 'GF_MOLLIE_BY_INDIGO_VERSION', '2.0.0' );
    3333
    3434add_action( 'gform_loaded', array( 'GF_Mollie_Bootstrap', 'load' ), 5 );
     
    5454        $load_mollie = apply_filters( 'gf_mollie_load_api', true );
    5555        if ( $load_mollie ) {
    56             require_once plugin_dir_path( __FILE__ ) . 'Mollie/API/Autoloader.php';
     56
     57            require_once plugin_dir_path( __FILE__ ) . 'Mollie/vendor/autoload.php';
    5758        }
    5859
  • gf-mollie-by-indigo/tags/2.0.0/readme.txt

    r2946580 r3009319  
    22Contributors: indigonl
    33Tags: gravity forms, ideal, bancontact, mollie
    4 Requires at least: 4.9.7
    5 Tested up to: 6.3
    6 Stable tag: 1.11.7
     4Requires at least: 6.4.2
     5Tested up to: 6.4.2
     6Stable tag: 2.0.0
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2727Author: Rocketgenius
    2828Website: https://www.gravityforms.com/
    29 Requires at least version: 2.2.5
    30 Tested till version: 2.6.8
     29Requires at least version: 2.8.0
     30Tested till version: 2.8.0
    3131
    3232Payment methods supported
     
    4848
    4949== Changelog ==
     50=2.0.0=
     51Tested up to WP 6.4.2 & GF 2.8.0
     52Updated Mollie API to 2.62.0
     53
    5054=1.11.7=
    5155Tested up to WP 6.3 & GF 2.7.11
  • gf-mollie-by-indigo/trunk/class-gf-mollie.php

    r2227779 r3009319  
    88
    99    protected $_version = GF_MOLLIE_BY_INDIGO_VERSION;
    10     protected $_min_gravityforms_version = '2.2.5';
     10    protected $_min_gravityforms_version = '2.8.0';
    1111    protected $_slug = 'gf-mollie-by-indigo';
    1212    protected $_path = 'gf-mollie-by-indigo/gf-mollie-by-indigo.php';
     
    2424    protected $_capabilities_form_settings = 'gravityforms_mollie';
    2525    protected $_capabilities_uninstall = 'gravityforms_mollie';
    26 
    2726    // Automatic upgrade enabled
    2827    protected $_enable_rg_autoupgrade = false;
    29 
    3028    private static $_instance = null;
    31 
    3229    public static function get_instance() {
    3330        if ( self::$_instance == null ) {
     
    3734        return self::$_instance;
    3835    }
    39 
    4036    private function __clone() {
    4137    } /* do nothing */
    42 
    4338    public function init_frontend() {
    4439        parent::init_frontend();
    45 
    46         //add_filter( 'gform_disable_post_creation', array( $this, 'delay_post' ), 10, 3 );
    47         //add_filter( 'gform_disable_notification', array( $this, 'delay_notification' ), 10, 4 );
    48     }
    49 
     40    }
    5041    public function init() {
    5142        parent::init();
     
    5445        add_filter( 'gform_replace_merge_tags', array( $this, 'gf_replace_merge_tags' ), 10, 7);
    5546    }
    56 
    57 
    58    
    5947    /*
    6048     *  Remove all billing fields from the mollie feed
     
    6452        return $fields;
    6553    }
    66 
    67 
    68    
    69    
    7054    public function feed_list_no_item_message() {
    7155        return parent::feed_list_no_item_message();
     
    8064        $fields = array(
    8165            array(
    82                 'type'  => 'helper_text',
     66                'type'  =>  __('helper_text',  'gf-mollie-by-indigo'),
    8367                'name'  => 'help',
    8468                'label' => '',
    8569            ),
    86 
    8770            array(
    88                 'label'   => 'Use default api key',
     71                'label'   =>  __('Use default api key',  'gf-mollie-by-indigo'),
    8972                'type'    => 'checkbox',
    9073                'name'    => 'useDefaultKey',
     
    9780                )
    9881            ),
    99 
    10082            array(
    10183                'name'     => 'mollieKey',
    10284                'label'    => esc_html__( 'Mollie api key ', 'gf-mollie-by-indigo' ),
    10385                'type'     => 'text',
    104 
    10586                'class'    => 'medium',
    10687                'required' => false,
     
    126107        //-------------------------------------------------------------------------------------------------
    127108
    128        
    129109        //Add post fields if form has a post
    130110        $form = $this->get_current_form();
     
    148128    }
    149129
    150 
    151130    /**
    152131     * Prevent the GFPaymentAddOn version of the options field being added to the feed settings.
     
    159138
    160139    public function save_feed_settings( $feed_id, $form_id, $settings ) {
    161 
    162140        //--------------------------------------------------------
    163141        //For backwards compatibility
     
    176154            return false;
    177155        }
    178 
    179156        $settings = $feed['meta'];
    180        
    181         //--------------------------------------------------------
    182157
    183158        return parent::save_feed_settings( $feed_id, $form_id, $settings );
     
    185160
    186161    //------ SENDING TO MOLLIE -----------//
    187 
    188162    public function redirect_url( $feed, $submission_data, $form, $entry ) {
    189 
    190 
    191 
    192 
    193163        if ( ! rgempty( 'gf_mollie_return', $_GET ) ) {
    194164            return false;
    195165        }
    196 
    197166        //updating lead's payment_status to Processing
    198167        GFAPI::update_entry_property( $entry['id'], 'payment_status', 'Processing' );
    199168
    200169        $payment_amount = rgar( $submission_data, 'payment_amount' );
    201                
     170        //  Make sure that we always has two decimals
     171        $payment_amount = number_format($payment_amount, 2, '.', '');
     172
    202173        $mollieKey = $this->get_mollie_key( $feed );
    203174        if ( ! $mollieKey ) {
     
    206177        }
    207178       
    208         $mollie = new Mollie_API_Client;
     179        $mollie = new \Mollie\Api\MollieApiClient();
    209180        $mollie->setApiKey($mollieKey);
    210        
    211181        $order_id = time();
    212        
    213182        $return_url =  $this->return_url( $form['id'], $entry['id'] );
    214183       
     
    221190        // Allow Mollie Payment Create adjustments
    222191        $mollie_request_args = apply_filters( 'gf_mollie_request_args', array(
    223             "amount"       => $payment_amount,
     192            "amount"       => array("currency" => "EUR", "value" => $payment_amount),
    224193            "description"  => $description,
    225194            "redirectUrl"  => $return_url,
     
    235204        //  Store transaction id as unique identification in gravityforms entry
    236205        GFAPI::update_entry_property( $entry['id'], 'transaction_id',  $payment->id );
    237 
    238         $url = $payment->links->paymentUrl;
    239 
    240 
     206        $url = $payment->getCheckoutUrl();;
    241207        $this->log_debug( __METHOD__ . "(): Sending to Mollie: {$url}" );
    242 
    243208        return $url;
    244209    }
     
    251216    public function return_url( $form_id, $lead_id ) {
    252217        $pageURL = GFCommon::is_ssl() ? 'https://' : 'http://';
    253 
    254218        $server_port = apply_filters( 'gform_mollie_return_url_port', $_SERVER['SERVER_PORT'] );
    255 
    256219        if ( $server_port != '80' ) {
    257220            $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI'];
     
    260223        }
    261224
    262 
    263 
    264 
    265225        $ids_query = "ids={$form_id}|{$lead_id}";
    266226        $ids_query .= '&hash=' . wp_hash( $ids_query );
    267 
    268227        $url = add_query_arg( 'gf_mollie_return', base64_encode( $ids_query ), $pageURL );
    269228
    270 
    271 
    272229        $query = 'gf_mollie_return=' . base64_encode( $ids_query );
    273         /**
    274          * Filters PayPal's return URL, which is the URL that users will be sent to after completing the payment on PayPal's site.
    275          * Useful when URL isn't created correctly (could happen on some server configurations using PROXY servers).
    276          *
    277          * @since 2.4.5
    278          *
    279          * @param string  $url  The URL to be filtered.
    280          * @param int $form_id  The ID of the form being submitted.
    281          * @param int $entry_id The ID of the entry that was just created.
    282          * @param string $query The query string portion of the URL.
    283          */
     230        //  Allow modification of the mollie return url
    284231        return apply_filters( 'gform_mollie_return_url', $url, $form_id, $lead_id, $query  );
    285232
     
    288235    public static function maybe_thankyou_page() {
    289236        $instance = self::get_instance();
    290 
    291237        if ( ! $instance->is_gravityforms_supported() ) {
    292238            return;
     
    295241        if ( $str = rgget( 'gf_mollie_return' ) ) {
    296242            $str = base64_decode( $str );
    297 
    298243            parse_str( $str, $query );
    299244            if ( wp_hash( 'ids=' . $query['ids'] ) == $query['hash'] ) {
    300245                list( $form_id, $lead_id ) = explode( '|', $query['ids'] );
    301 
    302246                $form = GFAPI::get_form( $form_id );
    303247                $lead = GFAPI::get_entry( $lead_id );
    304 
    305248                if ( ! class_exists( 'GFFormDisplay' ) ) {
    306249                    require_once( GFCommon::get_base_path() . '/form_display.php' );
    307250                }
    308 
    309251                $confirmation = GFFormDisplay::handle_confirmation( $form, $lead, false );
    310 
    311252                if ( is_array( $confirmation ) && isset( $confirmation['redirect'] ) ) {
    312253                    header( "Location: {$confirmation['redirect']}" );
    313254                    exit;
    314255                }
    315 
    316256                GFFormDisplay::$submission[ $form_id ] = array( 'is_confirmation' => true, 'confirmation_message' => $confirmation, 'form' => $form, 'lead' => $lead );
    317257            }
     
    321261
    322262    //------- PROCESSING MOLLIE CALLBACK -----------//
    323 
    324263    public function callback() {
    325 
    326264        if ( ! $this->is_gravityforms_supported() ) {
    327265            return false;
    328266        }
    329 
    330267        $this->log_debug( __METHOD__ . '(): request received. Starting to process => ' . print_r( $_POST, true ) );
    331 
    332268        $this->log_debug( __METHOD__ . '(): request received. Starting to process GET=> ' . print_r( $_GET, true ) );
    333 
    334        
    335269        $custom_field = rgpost( 'id' );
    336270        if ( empty( $custom_field ) ) {
    337271            $this->log_error( __METHOD__ . '(): Requests should have an id' );
    338 
    339             return false;
    340         }
    341 
     272            return false;
     273        }
    342274       
    343275        //  Get the entry
     
    350282   
    351283        try {
    352 
    353             $mollie = new Mollie_API_Client;
    354             $mollieKey = $mollieKey = $this->get_mollie_key( $feed );
     284            $mollie = new \Mollie\Api\MollieApiClient();
     285            $mollieKey = $this->get_mollie_key( $feed );
    355286            $mollie->setApiKey($mollieKey);
    356287            /*
     
    359290            $payment  = $mollie->payments->get($_POST["id"]);
    360291            $order_id = $payment->metadata->order_id;
    361 
    362292            $this->log_debug( __METHOD__ . '(): Mollie Payment object'. print_r( $payment, true ) );
    363293            $this->log_debug( __METHOD__ . '(): Mollie Payment entry id'. $payment->metadata->entry_id );
    364            
    365            
    366294            $entry = GFAPI::get_entry(  $payment->metadata->entry_id );
    367295            /*
     
    369297             */
    370298            do_action( 'gform_mollie_payment_retreived', $entry, $payment );
    371             if ( ! $payment->isRefunded() ) {
    372                 if ( $payment->isPaid() == true ) {
    373                     /*
    374                      * At this point you'd probably want to start the process of delivering the product to the customer.
    375                      */
    376                     $this->log_debug( __METHOD__ . '(): Mollie status paid' );
    377 
    378                     $action['id']             = $order_id . '_' . $payment->status;
    379                     $action['type']           = 'complete_payment';
    380                     $action['transaction_id'] = $order_id;
    381                     $action['amount']         = $payment->amount;
    382                     $action['entry_id']       = $entry['id'];
    383                     $action['payment_date']   = gmdate( 'y-m-d H:i:s' );
    384                     $action['payment_method'] = 'Mollie';
    385 
    386                     return $action;
    387 
    388 
    389                 } else {
    390                     /*
    391                      * The payment isn't paid and
    392                      */
    393                     $this->log_debug( __METHOD__ . '(): Mollie status not paid' );
    394 
    395                     $action['id']             = $order_id . '_' . $payment->status;
    396                     $action['type']           = 'fail_payment';
    397                     $action['transaction_id'] = $order_id;
    398                     $action['entry_id']       = $entry['id'];
    399                     $action['amount']         = $payment->amount;
    400                     return $action;
    401                 }
     299
     300            if ($payment->isPaid() && !$payment->hasRefunds() && !$payment->hasChargebacks()) {
     301                /*
     302                 * The payment is paid and isn't refunded or charged back.
     303                 * At this point you'd probably want to start the process of delivering the product to the customer.
     304                 */
     305                $this->log_debug( __METHOD__ . '(): Mollie status paid' );
     306                $action['id']             = $order_id . '_' . $payment->status;
     307                $action['type']           = 'complete_payment';
     308                $action['transaction_id'] = $order_id;
     309                $action['amount']         = $payment->amount->value;
     310                $action['entry_id']       = $entry['id'];
     311                $action['payment_date']   = gmdate( 'y-m-d H:i:s' );
     312                $action['payment_method'] = 'Mollie';
     313                return $action;
     314            } else {
     315                /*
     316                 * The payment isn't paid
     317                 */
     318                $this->log_debug( __METHOD__ . '(): Mollie status not paid' );
     319                $action['id']             = $order_id . '_' . $payment->status;
     320                $action['type']           = 'fail_payment';
     321                $action['transaction_id'] = $order_id;
     322                $action['entry_id']       = $entry['id'];
     323                $action['amount']         = $payment->amount->value;
     324                return $action;
    402325            }
    403326        } catch (Mollie_API_Exception $e) {
    404                 /*
    405                  * The Api failed
    406                  */
    407                  $this->log_debug( __METHOD__ . '(): API call failed: ' . htmlspecialchars($e->getMessage()));
    408         }
    409 
     327            /*
     328             * The Api failed
     329             */
     330             $this->log_debug( __METHOD__ . '(): API call failed: ' . htmlspecialchars($e->getMessage()));
     331        }
    410332        return false;
    411 
    412333    }
    413334
    414335    public function get_payment_feed( $entry, $form = false ) {
    415 
    416336        $feed = parent::get_payment_feed( $entry, $form );
    417 
    418337        if ( empty( $feed ) && ! empty( $entry['id'] ) ) {
    419338            //looking for feed created by legacy versions
    420339            $feed = $this->get_mollie_feed_by_entry( $entry['id'] );
    421340        }
    422 
    423341        $feed = apply_filters( 'gform_mollie_get_payment_feed', $feed, $entry, $form ? $form : GFAPI::get_form( $entry['form_id'] ) );
    424 
    425342        return $feed;
    426343    }
    427344
    428 
    429 
    430345    private function get_mollie_feed_by_entry( $entry_id ) {
    431 
    432346        $feed_id = gform_get_meta( $entry_id, 'mollie_feed_id' );
    433347        $feed    = $this->get_feed( $feed_id );
    434 
    435348        return ! empty( $feed ) ? $feed : false;
    436349    }
    437350
    438351    public function get_entry( $custom_field ) {
    439 
    440352        //Getting entry associated with this IPN message (entry id is sent in the 'custom' field)
    441353        list( $entry_id, $hash ) = explode( '|', $custom_field );
    442354        $hash_matches = wp_hash( $entry_id ) == $hash;
    443 
    444355        //allow the user to do some other kind of validation of the hash
    445356        $hash_matches = apply_filters( 'gform_mollie_hash_matches', $hash_matches, $entry_id, $hash, $custom_field );
    446 
    447357        //Validates that Entry Id wasn't tampered with
    448358        if ( ! rgpost( 'test_ipn' ) && ! $hash_matches ) {
    449359            $this->log_error( __METHOD__ . "(): Entry ID verification failed. Hash does not match. Custom field: {$custom_field}. Aborting." );
    450 
    451             return false;
    452         }
    453 
     360            return false;
     361        }
    454362        $this->log_debug( __METHOD__ . "(): IPN message has a valid custom field: {$custom_field}" );
    455 
    456363        $entry = GFAPI::get_entry( $entry_id );
    457 
    458364        if ( is_wp_error( $entry ) ) {
    459365            $this->log_error( __METHOD__ . '(): ' . $entry->get_error_message() );
    460 
    461             return false;
    462         }
    463 
     366            return false;
     367        }
    464368        return $entry;
    465369    }
    466 
    467370
    468371    public function is_callback_valid() {
     
    471374            $valid = false;
    472375        }
    473 
    474376        return apply_filters( 'gf_mollie_is_callback_valid', $valid );
    475377    }
     
    479381            return false;
    480382        }
    481 
    482383        return array(
    483384                'complete_payment'          => esc_html__( 'Mollie Payment Completed', 'gf-mollie-by-indigo' ),
     
    489390        $notifications_to_send  = array();
    490391        $selected_notifications = rgars( $feed, 'meta/selectedNotifications' );
    491 
    492392        if ( is_array( $selected_notifications ) ) {
    493393            // Make sure that the notifications being sent belong to the form submission event, just in case the notification event was changed after the feed was configured.
     
    496396                    continue;
    497397                }
    498 
    499398                $notifications_to_send[] = $notification['id'];
    500399            }
    501400        }
    502 
    503401        return $notifications_to_send;
    504402    }
    505 
    506 
    507 
    508 
    509403
    510404    public function plugin_settings_fields() {
     
    513407                       esc_html__( 'Submit your default API key in the field below. You can override this field in the individual form settings if needed.', 'gf-mollie-by-indigo' ) .
    514408                       '</p>';
    515 
    516409        return array(
    517410            array(
     
    519412                'description' => $description,
    520413                'fields'      => array(
    521 
    522 
    523414                    array(
    524415                        'type'  => 'helper_text',
     
    540431                        ),
    541432                    ),
    542 
    543 
    544             ),
    545             ));
    546 
    547 
    548 
    549     }
     433                ),
     434            )
     435        );
     436    }
     437
    550438    //  Return mollie key for current feed
    551439    public function get_mollie_key( $feed ) {
    552        
    553440        if ( isset( $feed['meta']['useDefaultKey'] ) && $feed['meta']['useDefaultKey'] == true ) {
    554441            $mollieKey = $this->get_plugin_setting( 'mollieKey' );
    555 
    556442        } else {
    557443            $mollieKey = $feed['meta']['mollieKey'];
     
    559445        return $mollieKey;
    560446    }
    561 
    562447
    563448    /*
     
    576461            return $text;
    577462        }
    578 
    579 
    580463        //The current payment status of the entry (ie “Authorized”, “Paid”, “Processing”, “Pending”, “Active”, “Expired”, “Failed”, “Cancelled”, “Approved”, “Reversed”, “Refunded”, “Voided”).
    581464        if ( isset($entry['payment_status'] ) ) {
     
    584467            $replace = '';
    585468        }
    586 
    587469        $text = str_replace($custom_merge_tag, $replace, $text);
    588470        return $text;
  • gf-mollie-by-indigo/trunk/gf-mollie-by-indigo.php

    r2946580 r3009319  
    44Plugin URI: http://www.indigowebstudio.nl
    55Description: Integrates Gravity Forms with Mollie, enabling end users to purchase goods and services through Gravity Forms.
    6 Version: 1.11.7
     6Version: 2.0.0
    77Author: Indigo webstudio
    88Author URI: http://www.indigowebstudio.nl
     
    3030
    3131
    32 define( 'GF_MOLLIE_BY_INDIGO_VERSION', '1.11.7' );
     32define( 'GF_MOLLIE_BY_INDIGO_VERSION', '2.0.0' );
    3333
    3434add_action( 'gform_loaded', array( 'GF_Mollie_Bootstrap', 'load' ), 5 );
     
    5454        $load_mollie = apply_filters( 'gf_mollie_load_api', true );
    5555        if ( $load_mollie ) {
    56             require_once plugin_dir_path( __FILE__ ) . 'Mollie/API/Autoloader.php';
     56
     57            require_once plugin_dir_path( __FILE__ ) . 'Mollie/vendor/autoload.php';
    5758        }
    5859
  • gf-mollie-by-indigo/trunk/readme.txt

    r2946580 r3009319  
    22Contributors: indigonl
    33Tags: gravity forms, ideal, bancontact, mollie
    4 Requires at least: 4.9.7
    5 Tested up to: 6.3
    6 Stable tag: 1.11.7
     4Requires at least: 6.4.2
     5Tested up to: 6.4.2
     6Stable tag: 2.0.0
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2727Author: Rocketgenius
    2828Website: https://www.gravityforms.com/
    29 Requires at least version: 2.2.5
    30 Tested till version: 2.6.8
     29Requires at least version: 2.8.0
     30Tested till version: 2.8.0
    3131
    3232Payment methods supported
     
    4848
    4949== Changelog ==
     50=2.0.0=
     51Tested up to WP 6.4.2 & GF 2.8.0
     52Updated Mollie API to 2.62.0
     53
    5054=1.11.7=
    5155Tested up to WP 6.3 & GF 2.7.11
Note: See TracChangeset for help on using the changeset viewer.