Changeset 3009319
- Timestamp:
- 12/13/2023 10:30:22 AM (2 years ago)
- Location:
- gf-mollie-by-indigo
- Files:
-
- 6 edited
- 1 copied
-
tags/2.0.0 (copied) (copied from gf-mollie-by-indigo/trunk)
-
tags/2.0.0/class-gf-mollie.php (modified) (33 diffs)
-
tags/2.0.0/gf-mollie-by-indigo.php (modified) (3 diffs)
-
tags/2.0.0/readme.txt (modified) (3 diffs)
-
trunk/class-gf-mollie.php (modified) (33 diffs)
-
trunk/gf-mollie-by-indigo.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gf-mollie-by-indigo/tags/2.0.0/class-gf-mollie.php
r2227779 r3009319 8 8 9 9 protected $_version = GF_MOLLIE_BY_INDIGO_VERSION; 10 protected $_min_gravityforms_version = '2. 2.5';10 protected $_min_gravityforms_version = '2.8.0'; 11 11 protected $_slug = 'gf-mollie-by-indigo'; 12 12 protected $_path = 'gf-mollie-by-indigo/gf-mollie-by-indigo.php'; … … 24 24 protected $_capabilities_form_settings = 'gravityforms_mollie'; 25 25 protected $_capabilities_uninstall = 'gravityforms_mollie'; 26 27 26 // Automatic upgrade enabled 28 27 protected $_enable_rg_autoupgrade = false; 29 30 28 private static $_instance = null; 31 32 29 public static function get_instance() { 33 30 if ( self::$_instance == null ) { … … 37 34 return self::$_instance; 38 35 } 39 40 36 private function __clone() { 41 37 } /* do nothing */ 42 43 38 public function init_frontend() { 44 39 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 } 50 41 public function init() { 51 42 parent::init(); … … 54 45 add_filter( 'gform_replace_merge_tags', array( $this, 'gf_replace_merge_tags' ), 10, 7); 55 46 } 56 57 58 59 47 /* 60 48 * Remove all billing fields from the mollie feed … … 64 52 return $fields; 65 53 } 66 67 68 69 70 54 public function feed_list_no_item_message() { 71 55 return parent::feed_list_no_item_message(); … … 80 64 $fields = array( 81 65 array( 82 'type' => 'helper_text',66 'type' => __('helper_text', 'gf-mollie-by-indigo'), 83 67 'name' => 'help', 84 68 'label' => '', 85 69 ), 86 87 70 array( 88 'label' => 'Use default api key',71 'label' => __('Use default api key', 'gf-mollie-by-indigo'), 89 72 'type' => 'checkbox', 90 73 'name' => 'useDefaultKey', … … 97 80 ) 98 81 ), 99 100 82 array( 101 83 'name' => 'mollieKey', 102 84 'label' => esc_html__( 'Mollie api key ', 'gf-mollie-by-indigo' ), 103 85 'type' => 'text', 104 105 86 'class' => 'medium', 106 87 'required' => false, … … 126 107 //------------------------------------------------------------------------------------------------- 127 108 128 129 109 //Add post fields if form has a post 130 110 $form = $this->get_current_form(); … … 148 128 } 149 129 150 151 130 /** 152 131 * Prevent the GFPaymentAddOn version of the options field being added to the feed settings. … … 159 138 160 139 public function save_feed_settings( $feed_id, $form_id, $settings ) { 161 162 140 //-------------------------------------------------------- 163 141 //For backwards compatibility … … 176 154 return false; 177 155 } 178 179 156 $settings = $feed['meta']; 180 181 //--------------------------------------------------------182 157 183 158 return parent::save_feed_settings( $feed_id, $form_id, $settings ); … … 185 160 186 161 //------ SENDING TO MOLLIE -----------// 187 188 162 public function redirect_url( $feed, $submission_data, $form, $entry ) { 189 190 191 192 193 163 if ( ! rgempty( 'gf_mollie_return', $_GET ) ) { 194 164 return false; 195 165 } 196 197 166 //updating lead's payment_status to Processing 198 167 GFAPI::update_entry_property( $entry['id'], 'payment_status', 'Processing' ); 199 168 200 169 $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 202 173 $mollieKey = $this->get_mollie_key( $feed ); 203 174 if ( ! $mollieKey ) { … … 206 177 } 207 178 208 $mollie = new Mollie_API_Client;179 $mollie = new \Mollie\Api\MollieApiClient(); 209 180 $mollie->setApiKey($mollieKey); 210 211 181 $order_id = time(); 212 213 182 $return_url = $this->return_url( $form['id'], $entry['id'] ); 214 183 … … 221 190 // Allow Mollie Payment Create adjustments 222 191 $mollie_request_args = apply_filters( 'gf_mollie_request_args', array( 223 "amount" => $payment_amount,192 "amount" => array("currency" => "EUR", "value" => $payment_amount), 224 193 "description" => $description, 225 194 "redirectUrl" => $return_url, … … 235 204 // Store transaction id as unique identification in gravityforms entry 236 205 GFAPI::update_entry_property( $entry['id'], 'transaction_id', $payment->id ); 237 238 $url = $payment->links->paymentUrl; 239 240 206 $url = $payment->getCheckoutUrl();; 241 207 $this->log_debug( __METHOD__ . "(): Sending to Mollie: {$url}" ); 242 243 208 return $url; 244 209 } … … 251 216 public function return_url( $form_id, $lead_id ) { 252 217 $pageURL = GFCommon::is_ssl() ? 'https://' : 'http://'; 253 254 218 $server_port = apply_filters( 'gform_mollie_return_url_port', $_SERVER['SERVER_PORT'] ); 255 256 219 if ( $server_port != '80' ) { 257 220 $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI']; … … 260 223 } 261 224 262 263 264 265 225 $ids_query = "ids={$form_id}|{$lead_id}"; 266 226 $ids_query .= '&hash=' . wp_hash( $ids_query ); 267 268 227 $url = add_query_arg( 'gf_mollie_return', base64_encode( $ids_query ), $pageURL ); 269 228 270 271 272 229 $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 284 231 return apply_filters( 'gform_mollie_return_url', $url, $form_id, $lead_id, $query ); 285 232 … … 288 235 public static function maybe_thankyou_page() { 289 236 $instance = self::get_instance(); 290 291 237 if ( ! $instance->is_gravityforms_supported() ) { 292 238 return; … … 295 241 if ( $str = rgget( 'gf_mollie_return' ) ) { 296 242 $str = base64_decode( $str ); 297 298 243 parse_str( $str, $query ); 299 244 if ( wp_hash( 'ids=' . $query['ids'] ) == $query['hash'] ) { 300 245 list( $form_id, $lead_id ) = explode( '|', $query['ids'] ); 301 302 246 $form = GFAPI::get_form( $form_id ); 303 247 $lead = GFAPI::get_entry( $lead_id ); 304 305 248 if ( ! class_exists( 'GFFormDisplay' ) ) { 306 249 require_once( GFCommon::get_base_path() . '/form_display.php' ); 307 250 } 308 309 251 $confirmation = GFFormDisplay::handle_confirmation( $form, $lead, false ); 310 311 252 if ( is_array( $confirmation ) && isset( $confirmation['redirect'] ) ) { 312 253 header( "Location: {$confirmation['redirect']}" ); 313 254 exit; 314 255 } 315 316 256 GFFormDisplay::$submission[ $form_id ] = array( 'is_confirmation' => true, 'confirmation_message' => $confirmation, 'form' => $form, 'lead' => $lead ); 317 257 } … … 321 261 322 262 //------- PROCESSING MOLLIE CALLBACK -----------// 323 324 263 public function callback() { 325 326 264 if ( ! $this->is_gravityforms_supported() ) { 327 265 return false; 328 266 } 329 330 267 $this->log_debug( __METHOD__ . '(): request received. Starting to process => ' . print_r( $_POST, true ) ); 331 332 268 $this->log_debug( __METHOD__ . '(): request received. Starting to process GET=> ' . print_r( $_GET, true ) ); 333 334 335 269 $custom_field = rgpost( 'id' ); 336 270 if ( empty( $custom_field ) ) { 337 271 $this->log_error( __METHOD__ . '(): Requests should have an id' ); 338 339 return false; 340 } 341 272 return false; 273 } 342 274 343 275 // Get the entry … … 350 282 351 283 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 ); 355 286 $mollie->setApiKey($mollieKey); 356 287 /* … … 359 290 $payment = $mollie->payments->get($_POST["id"]); 360 291 $order_id = $payment->metadata->order_id; 361 362 292 $this->log_debug( __METHOD__ . '(): Mollie Payment object'. print_r( $payment, true ) ); 363 293 $this->log_debug( __METHOD__ . '(): Mollie Payment entry id'. $payment->metadata->entry_id ); 364 365 366 294 $entry = GFAPI::get_entry( $payment->metadata->entry_id ); 367 295 /* … … 369 297 */ 370 298 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; 402 325 } 403 326 } 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 } 410 332 return false; 411 412 333 } 413 334 414 335 public function get_payment_feed( $entry, $form = false ) { 415 416 336 $feed = parent::get_payment_feed( $entry, $form ); 417 418 337 if ( empty( $feed ) && ! empty( $entry['id'] ) ) { 419 338 //looking for feed created by legacy versions 420 339 $feed = $this->get_mollie_feed_by_entry( $entry['id'] ); 421 340 } 422 423 341 $feed = apply_filters( 'gform_mollie_get_payment_feed', $feed, $entry, $form ? $form : GFAPI::get_form( $entry['form_id'] ) ); 424 425 342 return $feed; 426 343 } 427 344 428 429 430 345 private function get_mollie_feed_by_entry( $entry_id ) { 431 432 346 $feed_id = gform_get_meta( $entry_id, 'mollie_feed_id' ); 433 347 $feed = $this->get_feed( $feed_id ); 434 435 348 return ! empty( $feed ) ? $feed : false; 436 349 } 437 350 438 351 public function get_entry( $custom_field ) { 439 440 352 //Getting entry associated with this IPN message (entry id is sent in the 'custom' field) 441 353 list( $entry_id, $hash ) = explode( '|', $custom_field ); 442 354 $hash_matches = wp_hash( $entry_id ) == $hash; 443 444 355 //allow the user to do some other kind of validation of the hash 445 356 $hash_matches = apply_filters( 'gform_mollie_hash_matches', $hash_matches, $entry_id, $hash, $custom_field ); 446 447 357 //Validates that Entry Id wasn't tampered with 448 358 if ( ! rgpost( 'test_ipn' ) && ! $hash_matches ) { 449 359 $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 } 454 362 $this->log_debug( __METHOD__ . "(): IPN message has a valid custom field: {$custom_field}" ); 455 456 363 $entry = GFAPI::get_entry( $entry_id ); 457 458 364 if ( is_wp_error( $entry ) ) { 459 365 $this->log_error( __METHOD__ . '(): ' . $entry->get_error_message() ); 460 461 return false; 462 } 463 366 return false; 367 } 464 368 return $entry; 465 369 } 466 467 370 468 371 public function is_callback_valid() { … … 471 374 $valid = false; 472 375 } 473 474 376 return apply_filters( 'gf_mollie_is_callback_valid', $valid ); 475 377 } … … 479 381 return false; 480 382 } 481 482 383 return array( 483 384 'complete_payment' => esc_html__( 'Mollie Payment Completed', 'gf-mollie-by-indigo' ), … … 489 390 $notifications_to_send = array(); 490 391 $selected_notifications = rgars( $feed, 'meta/selectedNotifications' ); 491 492 392 if ( is_array( $selected_notifications ) ) { 493 393 // 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. … … 496 396 continue; 497 397 } 498 499 398 $notifications_to_send[] = $notification['id']; 500 399 } 501 400 } 502 503 401 return $notifications_to_send; 504 402 } 505 506 507 508 509 403 510 404 public function plugin_settings_fields() { … … 513 407 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' ) . 514 408 '</p>'; 515 516 409 return array( 517 410 array( … … 519 412 'description' => $description, 520 413 'fields' => array( 521 522 523 414 array( 524 415 'type' => 'helper_text', … … 540 431 ), 541 432 ), 542 543 544 ), 545 )); 546 547 548 549 } 433 ), 434 ) 435 ); 436 } 437 550 438 // Return mollie key for current feed 551 439 public function get_mollie_key( $feed ) { 552 553 440 if ( isset( $feed['meta']['useDefaultKey'] ) && $feed['meta']['useDefaultKey'] == true ) { 554 441 $mollieKey = $this->get_plugin_setting( 'mollieKey' ); 555 556 442 } else { 557 443 $mollieKey = $feed['meta']['mollieKey']; … … 559 445 return $mollieKey; 560 446 } 561 562 447 563 448 /* … … 576 461 return $text; 577 462 } 578 579 580 463 //The current payment status of the entry (ie “Authorized”, “Paid”, “Processing”, “Pending”, “Active”, “Expired”, “Failed”, “Cancelled”, “Approved”, “Reversed”, “Refunded”, “Voided”). 581 464 if ( isset($entry['payment_status'] ) ) { … … 584 467 $replace = ''; 585 468 } 586 587 469 $text = str_replace($custom_merge_tag, $replace, $text); 588 470 return $text; -
gf-mollie-by-indigo/tags/2.0.0/gf-mollie-by-indigo.php
r2946580 r3009319 4 4 Plugin URI: http://www.indigowebstudio.nl 5 5 Description: Integrates Gravity Forms with Mollie, enabling end users to purchase goods and services through Gravity Forms. 6 Version: 1.11.76 Version: 2.0.0 7 7 Author: Indigo webstudio 8 8 Author URI: http://www.indigowebstudio.nl … … 30 30 31 31 32 define( 'GF_MOLLIE_BY_INDIGO_VERSION', ' 1.11.7' );32 define( 'GF_MOLLIE_BY_INDIGO_VERSION', '2.0.0' ); 33 33 34 34 add_action( 'gform_loaded', array( 'GF_Mollie_Bootstrap', 'load' ), 5 ); … … 54 54 $load_mollie = apply_filters( 'gf_mollie_load_api', true ); 55 55 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'; 57 58 } 58 59 -
gf-mollie-by-indigo/tags/2.0.0/readme.txt
r2946580 r3009319 2 2 Contributors: indigonl 3 3 Tags: gravity forms, ideal, bancontact, mollie 4 Requires at least: 4.9.75 Tested up to: 6. 36 Stable tag: 1.11.74 Requires at least: 6.4.2 5 Tested up to: 6.4.2 6 Stable tag: 2.0.0 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 27 27 Author: Rocketgenius 28 28 Website: https://www.gravityforms.com/ 29 Requires at least version: 2. 2.530 Tested till version: 2. 6.829 Requires at least version: 2.8.0 30 Tested till version: 2.8.0 31 31 32 32 Payment methods supported … … 48 48 49 49 == Changelog == 50 =2.0.0= 51 Tested up to WP 6.4.2 & GF 2.8.0 52 Updated Mollie API to 2.62.0 53 50 54 =1.11.7= 51 55 Tested up to WP 6.3 & GF 2.7.11 -
gf-mollie-by-indigo/trunk/class-gf-mollie.php
r2227779 r3009319 8 8 9 9 protected $_version = GF_MOLLIE_BY_INDIGO_VERSION; 10 protected $_min_gravityforms_version = '2. 2.5';10 protected $_min_gravityforms_version = '2.8.0'; 11 11 protected $_slug = 'gf-mollie-by-indigo'; 12 12 protected $_path = 'gf-mollie-by-indigo/gf-mollie-by-indigo.php'; … … 24 24 protected $_capabilities_form_settings = 'gravityforms_mollie'; 25 25 protected $_capabilities_uninstall = 'gravityforms_mollie'; 26 27 26 // Automatic upgrade enabled 28 27 protected $_enable_rg_autoupgrade = false; 29 30 28 private static $_instance = null; 31 32 29 public static function get_instance() { 33 30 if ( self::$_instance == null ) { … … 37 34 return self::$_instance; 38 35 } 39 40 36 private function __clone() { 41 37 } /* do nothing */ 42 43 38 public function init_frontend() { 44 39 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 } 50 41 public function init() { 51 42 parent::init(); … … 54 45 add_filter( 'gform_replace_merge_tags', array( $this, 'gf_replace_merge_tags' ), 10, 7); 55 46 } 56 57 58 59 47 /* 60 48 * Remove all billing fields from the mollie feed … … 64 52 return $fields; 65 53 } 66 67 68 69 70 54 public function feed_list_no_item_message() { 71 55 return parent::feed_list_no_item_message(); … … 80 64 $fields = array( 81 65 array( 82 'type' => 'helper_text',66 'type' => __('helper_text', 'gf-mollie-by-indigo'), 83 67 'name' => 'help', 84 68 'label' => '', 85 69 ), 86 87 70 array( 88 'label' => 'Use default api key',71 'label' => __('Use default api key', 'gf-mollie-by-indigo'), 89 72 'type' => 'checkbox', 90 73 'name' => 'useDefaultKey', … … 97 80 ) 98 81 ), 99 100 82 array( 101 83 'name' => 'mollieKey', 102 84 'label' => esc_html__( 'Mollie api key ', 'gf-mollie-by-indigo' ), 103 85 'type' => 'text', 104 105 86 'class' => 'medium', 106 87 'required' => false, … … 126 107 //------------------------------------------------------------------------------------------------- 127 108 128 129 109 //Add post fields if form has a post 130 110 $form = $this->get_current_form(); … … 148 128 } 149 129 150 151 130 /** 152 131 * Prevent the GFPaymentAddOn version of the options field being added to the feed settings. … … 159 138 160 139 public function save_feed_settings( $feed_id, $form_id, $settings ) { 161 162 140 //-------------------------------------------------------- 163 141 //For backwards compatibility … … 176 154 return false; 177 155 } 178 179 156 $settings = $feed['meta']; 180 181 //--------------------------------------------------------182 157 183 158 return parent::save_feed_settings( $feed_id, $form_id, $settings ); … … 185 160 186 161 //------ SENDING TO MOLLIE -----------// 187 188 162 public function redirect_url( $feed, $submission_data, $form, $entry ) { 189 190 191 192 193 163 if ( ! rgempty( 'gf_mollie_return', $_GET ) ) { 194 164 return false; 195 165 } 196 197 166 //updating lead's payment_status to Processing 198 167 GFAPI::update_entry_property( $entry['id'], 'payment_status', 'Processing' ); 199 168 200 169 $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 202 173 $mollieKey = $this->get_mollie_key( $feed ); 203 174 if ( ! $mollieKey ) { … … 206 177 } 207 178 208 $mollie = new Mollie_API_Client;179 $mollie = new \Mollie\Api\MollieApiClient(); 209 180 $mollie->setApiKey($mollieKey); 210 211 181 $order_id = time(); 212 213 182 $return_url = $this->return_url( $form['id'], $entry['id'] ); 214 183 … … 221 190 // Allow Mollie Payment Create adjustments 222 191 $mollie_request_args = apply_filters( 'gf_mollie_request_args', array( 223 "amount" => $payment_amount,192 "amount" => array("currency" => "EUR", "value" => $payment_amount), 224 193 "description" => $description, 225 194 "redirectUrl" => $return_url, … … 235 204 // Store transaction id as unique identification in gravityforms entry 236 205 GFAPI::update_entry_property( $entry['id'], 'transaction_id', $payment->id ); 237 238 $url = $payment->links->paymentUrl; 239 240 206 $url = $payment->getCheckoutUrl();; 241 207 $this->log_debug( __METHOD__ . "(): Sending to Mollie: {$url}" ); 242 243 208 return $url; 244 209 } … … 251 216 public function return_url( $form_id, $lead_id ) { 252 217 $pageURL = GFCommon::is_ssl() ? 'https://' : 'http://'; 253 254 218 $server_port = apply_filters( 'gform_mollie_return_url_port', $_SERVER['SERVER_PORT'] ); 255 256 219 if ( $server_port != '80' ) { 257 220 $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI']; … … 260 223 } 261 224 262 263 264 265 225 $ids_query = "ids={$form_id}|{$lead_id}"; 266 226 $ids_query .= '&hash=' . wp_hash( $ids_query ); 267 268 227 $url = add_query_arg( 'gf_mollie_return', base64_encode( $ids_query ), $pageURL ); 269 228 270 271 272 229 $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 284 231 return apply_filters( 'gform_mollie_return_url', $url, $form_id, $lead_id, $query ); 285 232 … … 288 235 public static function maybe_thankyou_page() { 289 236 $instance = self::get_instance(); 290 291 237 if ( ! $instance->is_gravityforms_supported() ) { 292 238 return; … … 295 241 if ( $str = rgget( 'gf_mollie_return' ) ) { 296 242 $str = base64_decode( $str ); 297 298 243 parse_str( $str, $query ); 299 244 if ( wp_hash( 'ids=' . $query['ids'] ) == $query['hash'] ) { 300 245 list( $form_id, $lead_id ) = explode( '|', $query['ids'] ); 301 302 246 $form = GFAPI::get_form( $form_id ); 303 247 $lead = GFAPI::get_entry( $lead_id ); 304 305 248 if ( ! class_exists( 'GFFormDisplay' ) ) { 306 249 require_once( GFCommon::get_base_path() . '/form_display.php' ); 307 250 } 308 309 251 $confirmation = GFFormDisplay::handle_confirmation( $form, $lead, false ); 310 311 252 if ( is_array( $confirmation ) && isset( $confirmation['redirect'] ) ) { 312 253 header( "Location: {$confirmation['redirect']}" ); 313 254 exit; 314 255 } 315 316 256 GFFormDisplay::$submission[ $form_id ] = array( 'is_confirmation' => true, 'confirmation_message' => $confirmation, 'form' => $form, 'lead' => $lead ); 317 257 } … … 321 261 322 262 //------- PROCESSING MOLLIE CALLBACK -----------// 323 324 263 public function callback() { 325 326 264 if ( ! $this->is_gravityforms_supported() ) { 327 265 return false; 328 266 } 329 330 267 $this->log_debug( __METHOD__ . '(): request received. Starting to process => ' . print_r( $_POST, true ) ); 331 332 268 $this->log_debug( __METHOD__ . '(): request received. Starting to process GET=> ' . print_r( $_GET, true ) ); 333 334 335 269 $custom_field = rgpost( 'id' ); 336 270 if ( empty( $custom_field ) ) { 337 271 $this->log_error( __METHOD__ . '(): Requests should have an id' ); 338 339 return false; 340 } 341 272 return false; 273 } 342 274 343 275 // Get the entry … … 350 282 351 283 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 ); 355 286 $mollie->setApiKey($mollieKey); 356 287 /* … … 359 290 $payment = $mollie->payments->get($_POST["id"]); 360 291 $order_id = $payment->metadata->order_id; 361 362 292 $this->log_debug( __METHOD__ . '(): Mollie Payment object'. print_r( $payment, true ) ); 363 293 $this->log_debug( __METHOD__ . '(): Mollie Payment entry id'. $payment->metadata->entry_id ); 364 365 366 294 $entry = GFAPI::get_entry( $payment->metadata->entry_id ); 367 295 /* … … 369 297 */ 370 298 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; 402 325 } 403 326 } 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 } 410 332 return false; 411 412 333 } 413 334 414 335 public function get_payment_feed( $entry, $form = false ) { 415 416 336 $feed = parent::get_payment_feed( $entry, $form ); 417 418 337 if ( empty( $feed ) && ! empty( $entry['id'] ) ) { 419 338 //looking for feed created by legacy versions 420 339 $feed = $this->get_mollie_feed_by_entry( $entry['id'] ); 421 340 } 422 423 341 $feed = apply_filters( 'gform_mollie_get_payment_feed', $feed, $entry, $form ? $form : GFAPI::get_form( $entry['form_id'] ) ); 424 425 342 return $feed; 426 343 } 427 344 428 429 430 345 private function get_mollie_feed_by_entry( $entry_id ) { 431 432 346 $feed_id = gform_get_meta( $entry_id, 'mollie_feed_id' ); 433 347 $feed = $this->get_feed( $feed_id ); 434 435 348 return ! empty( $feed ) ? $feed : false; 436 349 } 437 350 438 351 public function get_entry( $custom_field ) { 439 440 352 //Getting entry associated with this IPN message (entry id is sent in the 'custom' field) 441 353 list( $entry_id, $hash ) = explode( '|', $custom_field ); 442 354 $hash_matches = wp_hash( $entry_id ) == $hash; 443 444 355 //allow the user to do some other kind of validation of the hash 445 356 $hash_matches = apply_filters( 'gform_mollie_hash_matches', $hash_matches, $entry_id, $hash, $custom_field ); 446 447 357 //Validates that Entry Id wasn't tampered with 448 358 if ( ! rgpost( 'test_ipn' ) && ! $hash_matches ) { 449 359 $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 } 454 362 $this->log_debug( __METHOD__ . "(): IPN message has a valid custom field: {$custom_field}" ); 455 456 363 $entry = GFAPI::get_entry( $entry_id ); 457 458 364 if ( is_wp_error( $entry ) ) { 459 365 $this->log_error( __METHOD__ . '(): ' . $entry->get_error_message() ); 460 461 return false; 462 } 463 366 return false; 367 } 464 368 return $entry; 465 369 } 466 467 370 468 371 public function is_callback_valid() { … … 471 374 $valid = false; 472 375 } 473 474 376 return apply_filters( 'gf_mollie_is_callback_valid', $valid ); 475 377 } … … 479 381 return false; 480 382 } 481 482 383 return array( 483 384 'complete_payment' => esc_html__( 'Mollie Payment Completed', 'gf-mollie-by-indigo' ), … … 489 390 $notifications_to_send = array(); 490 391 $selected_notifications = rgars( $feed, 'meta/selectedNotifications' ); 491 492 392 if ( is_array( $selected_notifications ) ) { 493 393 // 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. … … 496 396 continue; 497 397 } 498 499 398 $notifications_to_send[] = $notification['id']; 500 399 } 501 400 } 502 503 401 return $notifications_to_send; 504 402 } 505 506 507 508 509 403 510 404 public function plugin_settings_fields() { … … 513 407 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' ) . 514 408 '</p>'; 515 516 409 return array( 517 410 array( … … 519 412 'description' => $description, 520 413 'fields' => array( 521 522 523 414 array( 524 415 'type' => 'helper_text', … … 540 431 ), 541 432 ), 542 543 544 ), 545 )); 546 547 548 549 } 433 ), 434 ) 435 ); 436 } 437 550 438 // Return mollie key for current feed 551 439 public function get_mollie_key( $feed ) { 552 553 440 if ( isset( $feed['meta']['useDefaultKey'] ) && $feed['meta']['useDefaultKey'] == true ) { 554 441 $mollieKey = $this->get_plugin_setting( 'mollieKey' ); 555 556 442 } else { 557 443 $mollieKey = $feed['meta']['mollieKey']; … … 559 445 return $mollieKey; 560 446 } 561 562 447 563 448 /* … … 576 461 return $text; 577 462 } 578 579 580 463 //The current payment status of the entry (ie “Authorized”, “Paid”, “Processing”, “Pending”, “Active”, “Expired”, “Failed”, “Cancelled”, “Approved”, “Reversed”, “Refunded”, “Voided”). 581 464 if ( isset($entry['payment_status'] ) ) { … … 584 467 $replace = ''; 585 468 } 586 587 469 $text = str_replace($custom_merge_tag, $replace, $text); 588 470 return $text; -
gf-mollie-by-indigo/trunk/gf-mollie-by-indigo.php
r2946580 r3009319 4 4 Plugin URI: http://www.indigowebstudio.nl 5 5 Description: Integrates Gravity Forms with Mollie, enabling end users to purchase goods and services through Gravity Forms. 6 Version: 1.11.76 Version: 2.0.0 7 7 Author: Indigo webstudio 8 8 Author URI: http://www.indigowebstudio.nl … … 30 30 31 31 32 define( 'GF_MOLLIE_BY_INDIGO_VERSION', ' 1.11.7' );32 define( 'GF_MOLLIE_BY_INDIGO_VERSION', '2.0.0' ); 33 33 34 34 add_action( 'gform_loaded', array( 'GF_Mollie_Bootstrap', 'load' ), 5 ); … … 54 54 $load_mollie = apply_filters( 'gf_mollie_load_api', true ); 55 55 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'; 57 58 } 58 59 -
gf-mollie-by-indigo/trunk/readme.txt
r2946580 r3009319 2 2 Contributors: indigonl 3 3 Tags: gravity forms, ideal, bancontact, mollie 4 Requires at least: 4.9.75 Tested up to: 6. 36 Stable tag: 1.11.74 Requires at least: 6.4.2 5 Tested up to: 6.4.2 6 Stable tag: 2.0.0 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 27 27 Author: Rocketgenius 28 28 Website: https://www.gravityforms.com/ 29 Requires at least version: 2. 2.530 Tested till version: 2. 6.829 Requires at least version: 2.8.0 30 Tested till version: 2.8.0 31 31 32 32 Payment methods supported … … 48 48 49 49 == Changelog == 50 =2.0.0= 51 Tested up to WP 6.4.2 & GF 2.8.0 52 Updated Mollie API to 2.62.0 53 50 54 =1.11.7= 51 55 Tested up to WP 6.3 & GF 2.7.11
Note: See TracChangeset
for help on using the changeset viewer.