diff --git a/.wp-env.json b/.wp-env.json new file mode 100644 index 0000000..799b4b4 --- /dev/null +++ b/.wp-env.json @@ -0,0 +1,15 @@ +{ + "core": null, + "plugins": [ + ".", + "../../../", + "https://github.com/pronamic/gravityforms/releases/download/2.6.6/gravityforms-2.6.6.zip", + "pronamic/wp-pronamic-pay-test-helper", + "https://downloads.wordpress.org/plugin/pronamic-client.zip", + "https://downloads.wordpress.org/plugin/query-monitor.zip", + "https://downloads.wordpress.org/plugin/one-time-login.zip" + ], + "config": { + "PRONAMIC_PAY_DEBUG": true + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd0385..cc17bfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C ## [Unreleased][unreleased] - +## [4.2.0] - 2022-09-26 +- Fixed conditional logic object without any logic. +- Updated for new payment methods and fields registration. + ## [4.1.1] - 2022-08-15 - Fixed compatibility issue with plugins producing output in `gform_admin_pre_render` filter. - Fixed duplicate configurations in payment gateway configuration field setting ([pronamic/wp-pronamic-pay-gravityforms#8](https://github.com/pronamic/wp-pronamic-pay-gravityforms/issues/8)). @@ -345,7 +349,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C ## 1.0.0 - 2015-01-01 - First release. -[unreleased]: https://github.com/pronamic/wp-pronamic-pay-gravityforms/compare/4.1.1...HEAD +[unreleased]: https://github.com/pronamic/wp-pronamic-pay-gravityforms/compare/4.2.0...HEAD +[4.2.0]: https://github.com/pronamic/wp-pronamic-pay-gravityforms/compare/4.1.1...4.2.0 [4.1.1]: https://github.com/pronamic/wp-pronamic-pay-gravityforms/compare/4.1.0...4.1.1 [4.1.0]: https://github.com/pronamic/wp-pronamic-pay-gravityforms/compare/4.0.1...4.1.0 [4.0.1]: https://github.com/pronamic/wp-pronamic-pay-gravityforms/compare/4.0.0...4.0.1 diff --git a/composer.json b/composer.json index fa3c0ce..fe00ca6 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ }, "scripts": { "coveralls": "vendor/bin/php-coveralls -v", - "phpcbf": "vendor/bin/phpcbf", + "phpcbf": "XDEBUG_MODE=off vendor/bin/phpcbf", "phpcs": "XDEBUG_MODE=off vendor/bin/phpcs -s -v", "phplint": "find src tests -name '*.php' | xargs -n 1 -P 4 php -l", "phpmd": "vendor/bin/phpmd src,tests text phpmd.ruleset.xml --suffixes php", diff --git a/package.json b/package.json index ffd2beb..e75e344 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gravityforms", - "version": "4.1.1", + "version": "4.2.0", "description": "Gravity Forms driver for the WordPress payment processing library.", "repository": { "type": "git", @@ -35,6 +35,7 @@ "last 2 versions" ], "devDependencies": { + "@wordpress/env": "^5.2.0", "autoprefixer": "^10.2.5", "eslint": "^8.0", "eslint-plugin-json": "^3.1", @@ -46,6 +47,7 @@ "grunt-postcss": "^0.9.0", "grunt-sass-lint": "^0.2.4", "load-grunt-tasks": "^5.1.0", + "npm-run-all": "^4.1.5", "sass-lint": "^1.13.1" }, "scripts": { @@ -53,6 +55,13 @@ "build-image-svg-default": "svgo images/src/wp-pay.svg -o images/dist/wp-pay.svgo-min.svg", "eslint": "eslint . --ext .json --ext .js", "lint": "npm-run-all --parallel eslint sass-lint", - "sass-lint": "sass-lint --verbose" + "sass-lint": "sass-lint --verbose", + "start": "wp-env start && npm run setup && npm run login", + "setup": "npm-run-all setup-*", + "setup-gravityforms": "wp-env run cli wp config set GF_LICENSE_KEY $GRAVITYFORMS_LICENSE_KEY", + "setup-mollie": "wp-env run cli wp config set MOLLIE_API_KEY $MOLLIE_API_KEY", + "setup-buckaroo-website-key": "wp-env run cli wp config set BUCKAROO_WEBSITE_KEY $BUCKAROO_WEBSITE_KEY", + "setup-buckaroo-secret-key": "wp-env run cli wp config set BUCKAROO_SECRET_KEY $BUCKAROO_SECRET_KEY", + "login": "wp-env run cli wp user one-time-login admin" } } diff --git a/pronamic-pay-gravityforms.php b/pronamic-pay-gravityforms.php new file mode 100644 index 0000000..89525e4 --- /dev/null +++ b/pronamic-pay-gravityforms.php @@ -0,0 +1,41 @@ + + * @copyright 2005-2022 Pronamic + * @license GPL-3.0-or-later + * @package Pronamic\WordPress\Pay\Extensions\GravityForms + */ + +add_filter( + 'pronamic_pay_plugin_integrations', + function ( $integrations ) { + foreach ( $integrations as $integration ) { + if ( $integration instanceof \Pronamic\WordPress\Pay\Extensions\GravityForms\Extension ) { + return $integrations; + } + } + + $integrations[] = new \Pronamic\WordPress\Pay\Extensions\GravityForms\Extension(); + + return $integrations; + } +); diff --git a/src/Admin.php b/src/Admin.php index 1a41de3..5ef6a97 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -29,16 +29,16 @@ class Admin { */ public static function bootstrap() { // Actions. - add_action( 'admin_init', array( __CLASS__, 'admin_init' ) ); - add_action( 'admin_init', array( __CLASS__, 'maybe_redirect_to_entry' ) ); + add_action( 'admin_init', [ __CLASS__, 'admin_init' ] ); + add_action( 'admin_init', [ __CLASS__, 'maybe_redirect_to_entry' ] ); - add_action( 'gform_entry_info', array( __CLASS__, 'entry_info' ), 10, 2 ); + add_action( 'gform_entry_info', [ __CLASS__, 'entry_info' ], 10, 2 ); // Filters. - add_filter( 'gform_custom_merge_tags', array( __CLASS__, 'custom_merge_tags' ), 10 ); + add_filter( 'gform_custom_merge_tags', [ __CLASS__, 'custom_merge_tags' ], 10 ); // Actions - AJAX. - add_action( 'wp_ajax_gf_get_form_data', array( __CLASS__, 'ajax_get_form_data' ) ); + add_action( 'wp_ajax_gf_get_form_data', [ __CLASS__, 'ajax_get_form_data' ] ); } /** @@ -56,11 +56,11 @@ public static function admin_init() { * @return array */ public static function form_settings_menu_item( $menu_items ) { - $menu_items[] = array( + $menu_items[] = [ 'name' => 'pronamic_pay', 'label' => __( 'Pay', 'pronamic_ideal' ), - 'query' => array( 'fid' => null ), - ); + 'query' => [ 'fid' => null ], + ]; return $menu_items; } @@ -93,102 +93,102 @@ public static function entry_info( $form_id, $lead ) { */ public static function custom_merge_tags( $merge_tags ) { // Payment. - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Payment Status', 'pronamic_ideal' ), 'tag' => '{payment_status}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Payment Date', 'pronamic_ideal' ), 'tag' => '{payment_date}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Transaction Id', 'pronamic_ideal' ), 'tag' => '{transaction_id}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Payment Amount', 'pronamic_ideal' ), 'tag' => '{payment_amount}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Payment ID', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_id}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Pay Again URL', 'pronamic_ideal' ), 'tag' => '{pronamic_pay_again_url}', - ); + ]; // Bank transfer. - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient reference', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_reference}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient bank name', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_bank_name}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient name', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_name}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient IBAN', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_iban}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient BIC', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_bic}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient city', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_city}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient country', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_country}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic bank transfer recipient account number', 'pronamic_ideal' ), 'tag' => '{pronamic_payment_bank_transfer_recipient_account_number}', - ); + ]; // Subscription. - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Subscription Payment ID', 'pronamic_ideal' ), 'tag' => '{pronamic_subscription_payment_id}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Subscription Amount', 'pronamic_ideal' ), 'tag' => '{pronamic_subscription_amount}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Subscription Cancel URL', 'pronamic_ideal' ), 'tag' => '{pronamic_subscription_cancel_url}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Subscription Renew URL', 'pronamic_ideal' ), 'tag' => '{pronamic_subscription_renew_url}', - ); + ]; - $merge_tags[] = array( + $merge_tags[] = [ 'label' => __( 'Pronamic Subscription Renewal Date', 'pronamic_ideal' ), 'tag' => '{pronamic_subscription_renewal_date}', - ); + ]; return $merge_tags; } @@ -207,12 +207,12 @@ public static function maybe_redirect_to_entry() { if ( ! empty( $lead ) ) { $url = add_query_arg( - array( + [ 'page' => 'gf_entries', 'view' => 'entry', 'id' => $lead['form_id'], 'lid' => $lead_id, - ), + ], admin_url( 'admin.php' ) ); @@ -243,13 +243,13 @@ public static function ajax_get_form_data() { */ public static function get_new_feed_url( $form_id ) { return add_query_arg( - array( + [ 'page' => 'gf_edit_forms', 'view' => 'settings', 'subview' => 'pronamic_pay', 'id' => $form_id, 'fid' => 0, - ), + ], admin_url( 'admin.php' ) ); } diff --git a/src/AdminPaymentFormPostType.php b/src/AdminPaymentFormPostType.php index ee977d4..243dfa5 100644 --- a/src/AdminPaymentFormPostType.php +++ b/src/AdminPaymentFormPostType.php @@ -36,17 +36,17 @@ class AdminPaymentFormPostType { * Construct and initialize admin payment form post type. */ public function __construct() { - add_filter( 'manage_edit-pronamic_pay_gf_columns', array( $this, 'edit_columns' ) ); + add_filter( 'manage_edit-pronamic_pay_gf_columns', [ $this, 'edit_columns' ] ); - add_action( 'manage_pronamic_pay_gf_posts_custom_column', array( $this, 'custom_columns' ), 10, 2 ); + add_action( 'manage_pronamic_pay_gf_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 ); - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); + add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] ); - add_action( 'gform_after_delete_form', array( $this, 'delete_payment_form' ) ); + add_action( 'gform_after_delete_form', [ $this, 'delete_payment_form' ] ); - add_filter( 'wp_insert_post_data', array( $this, 'insert_post_data' ), 99, 2 ); + add_filter( 'wp_insert_post_data', [ $this, 'insert_post_data' ], 99, 2 ); - add_action( 'save_post_' . self::POST_TYPE, array( $this, 'save_post' ) ); + add_action( 'save_post_' . self::POST_TYPE, [ $this, 'save_post' ] ); } /** @@ -56,14 +56,14 @@ public function __construct() { * @return array */ public function edit_columns( $columns ) { - $columns = array( + $columns = [ 'cb' => '', 'title' => __( 'Title', 'pronamic_ideal' ), 'pronamic_pay_gf_form' => __( 'Form', 'pronamic_ideal' ), 'pronamic_pay_gf_config' => __( 'Configuration', 'pronamic_ideal' ), 'pronamic_pay_gf_transaction_description' => __( 'Transaction Description', 'pronamic_ideal' ), 'date' => __( 'Date', 'pronamic_ideal' ), - ); + ]; return $columns; } @@ -84,10 +84,10 @@ public function custom_columns( $column, $post_id ) { '%s', esc_attr( add_query_arg( - array( + [ 'page' => 'gf_edit_forms', 'id' => $form_id, - ), + ], admin_url( 'admin.php' ) ) ), @@ -122,7 +122,7 @@ public function add_meta_boxes() { add_meta_box( 'pronamic_pay_gf', __( 'Configuration', 'pronamic_ideal' ), - array( $this, 'meta_box_config' ), + [ $this, 'meta_box_config' ], 'pronamic_pay_gf', 'normal', 'high' @@ -148,15 +148,15 @@ public function meta_box_config( $post ) { */ public function delete_payment_form( $form_id ) { $query = new WP_Query( - array( + [ 'post_type' => 'pronamic_pay_gf', - 'meta_query' => array( - array( + 'meta_query' => [ + [ 'key' => '_pronamic_pay_gf_form_id', 'value' => $form_id, - ), - ), - ) + ], + ], + ] ); foreach ( $query->posts as $post ) { @@ -239,7 +239,7 @@ public function save_post( $post_id ) { } /* OK, its safe for us to save the data now. */ - $definition = array( + $definition = [ '_pronamic_pay_gf_form_id' => 'sanitize_text_field', '_pronamic_pay_gf_config_id' => 'sanitize_text_field', '_pronamic_pay_gf_entry_id_prefix' => 'sanitize_text_field', @@ -247,19 +247,19 @@ public function save_post( $post_id ) { '_pronamic_pay_gf_transaction_description' => 'sanitize_text_field', '_pronamic_pay_gf_delay_admin_notification' => FILTER_VALIDATE_BOOLEAN, '_pronamic_pay_gf_delay_user_notification' => FILTER_VALIDATE_BOOLEAN, - '_pronamic_pay_gf_delay_notification_ids' => array( + '_pronamic_pay_gf_delay_notification_ids' => [ 'filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY, - ), + ], '_pronamic_pay_gf_delay_post_creation' => FILTER_VALIDATE_BOOLEAN, - '_pronamic_pay_gf_fields' => array( + '_pronamic_pay_gf_fields' => [ 'filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY, - ), - '_pronamic_pay_gf_links' => array( + ], + '_pronamic_pay_gf_links' => [ 'filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY, - ), + ], '_pronamic_pay_gf_user_role_field_id' => 'sanitize_text_field', '_pronamic_pay_gf_subscription_amount_type' => 'sanitize_text_field', '_pronamic_pay_gf_subscription_amount_field' => 'sanitize_text_field', @@ -279,7 +279,7 @@ public function save_post( $post_id ) { // Feed conditions. '_gaddon_setting_feed_condition_conditional_logic_object' => 'sanitize_text_field', '_gform_setting_feed_condition_conditional_logic_object' => 'sanitize_text_field', - ); + ]; $delay_actions = Extension::get_delay_actions(); @@ -367,7 +367,7 @@ function( $action ) { \delete_post_meta( $post_id, '_pronamic_pay_gf_subscription_frequency' ); } - if ( \in_array( $meta_key, array( '_gform_setting_feed_condition_conditional_logic_object', '_gaddon_setting_feed_condition_conditional_logic_object' ), true ) ) { + if ( \in_array( $meta_key, [ '_gform_setting_feed_condition_conditional_logic_object', '_gaddon_setting_feed_condition_conditional_logic_object' ], true ) ) { \delete_post_meta( $post_id, '_pronamic_pay_gf_condition_field_id' ); \delete_post_meta( $post_id, '_pronamic_pay_gf_condition_operator' ); \delete_post_meta( $post_id, '_pronamic_pay_gf_condition_value' ); diff --git a/src/Entry.php b/src/Entry.php index 55e99fd..939cac6 100644 --- a/src/Entry.php +++ b/src/Entry.php @@ -53,12 +53,12 @@ public static function is_payment_approved( array $entry ) { $approved = in_array( $payment_status, - array( + [ // @since 1.0.0 - Approved PaymentStatuses::APPROVED, // @since 1.2.3 - Paid PaymentStatuses::PAID, - ), + ], true ); } diff --git a/src/Extension.php b/src/Extension.php index 32722a2..a2c17bb 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -59,10 +59,10 @@ class Extension extends AbstractPluginIntegration { */ public function __construct() { parent::__construct( - array( + [ 'name' => __( 'Gravity Forms', 'pronamic_ideal' ), 'version' => '2.3.0', - ) + ] ); // Dependencies. @@ -77,10 +77,10 @@ public function __construct() { * @return void */ public function setup() { - add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( $this, 'source_text' ), 10, 2 ); - add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( $this, 'source_description' ), 10, 2 ); - add_filter( 'pronamic_subscription_source_text_' . self::SLUG, array( $this, 'subscription_source_text' ), 10, 2 ); - add_filter( 'pronamic_subscription_source_description_' . self::SLUG, array( $this, 'subscription_source_description' ), 10, 2 ); + add_filter( 'pronamic_payment_source_text_' . self::SLUG, [ $this, 'source_text' ], 10, 2 ); + add_filter( 'pronamic_payment_source_description_' . self::SLUG, [ $this, 'source_description' ], 10, 2 ); + add_filter( 'pronamic_subscription_source_text_' . self::SLUG, [ $this, 'subscription_source_text' ], 10, 2 ); + add_filter( 'pronamic_subscription_source_description_' . self::SLUG, [ $this, 'subscription_source_description' ], 10, 2 ); // Check if dependencies are met and integration is active. if ( ! $this->is_active() ) { @@ -95,9 +95,9 @@ public function setup() { // Actions // Initialize hook, Gravity Forms uses the default priority (10). - add_action( 'init', array( $this, 'init' ), 20 ); + add_action( 'init', [ $this, 'init' ], 20 ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); // Add-on // The `class_exists` call is required to prevent strange errors on some hosting environments. @@ -121,32 +121,30 @@ public function init() { if ( is_admin() ) { Admin::bootstrap(); } else { - add_action( 'gform_pre_submission', array( $this, 'pre_submission' ) ); + add_action( 'gform_pre_submission', [ $this, 'pre_submission' ] ); } - add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( $this, 'source_url' ), 10, 2 ); - add_filter( 'pronamic_subscription_source_url_' . self::SLUG, array( $this, 'subscription_source_url' ), 10, 2 ); - add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( $this, 'redirect_url' ), 10, 2 ); - add_action( 'pronamic_payment_status_update_' . self::SLUG, array( $this, 'update_status' ), 10, 2 ); - add_action( 'pronamic_pay_update_payment', array( $this, 'update_payment' ) ); - add_action( 'pronamic_subscription_status_update_' . self::SLUG, array( $this, 'subscription_update_status' ) ); - add_action( 'pronamic_subscription_renewal_notice_' . self::SLUG, array( $this, 'subscription_renewal_notice' ) ); + add_filter( 'pronamic_payment_source_url_' . self::SLUG, [ $this, 'source_url' ], 10, 2 ); + add_filter( 'pronamic_subscription_source_url_' . self::SLUG, [ $this, 'subscription_source_url' ], 10, 2 ); + add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, [ $this, 'redirect_url' ], 10, 2 ); + add_action( 'pronamic_payment_status_update_' . self::SLUG, [ $this, 'update_status' ], 10, 2 ); + add_action( 'pronamic_pay_update_payment', [ $this, 'update_payment' ] ); + add_action( 'pronamic_subscription_status_update_' . self::SLUG, [ $this, 'subscription_update_status' ] ); + add_action( 'pronamic_subscription_renewal_notice_' . self::SLUG, [ $this, 'subscription_renewal_notice' ] ); add_filter( 'pronamic_pay_subscription_amount_editable_' . self::SLUG, '__return_true' ); - add_filter( 'gform_replace_merge_tags', array( $this, 'replace_merge_tags' ), 10, 7 ); - - add_filter( 'gform_gf_field_create', array( $this, 'field_create' ), 10, 2 ); + add_filter( 'gform_replace_merge_tags', [ $this, 'replace_merge_tags' ], 10, 7 ); - add_filter( 'gform_currencies', array( __CLASS__, 'currencies' ), 10, 1 ); + add_filter( 'gform_gf_field_create', [ $this, 'field_create' ], 10, 2 ); - \add_filter( 'gform_form_args', array( $this, 'maybe_prepopulate_form' ), 10, 1 ); - \add_filter( 'gform_pre_render', array( $this, 'allow_field_prepopulation' ), 10, 3 ); + \add_filter( 'gform_form_args', [ $this, 'maybe_prepopulate_form' ], 10, 1 ); + \add_filter( 'gform_pre_render', [ $this, 'allow_field_prepopulation' ], 10, 3 ); // Register scripts and styles if Gravity Forms No-Conflict Mode is enabled. - add_filter( 'gform_noconflict_scripts', array( $this, 'no_conflict_scripts' ) ); - add_filter( 'gform_noconflict_styles', array( $this, 'no_conflict_styles' ) ); + add_filter( 'gform_noconflict_scripts', [ $this, 'no_conflict_scripts' ] ); + add_filter( 'gform_noconflict_styles', [ $this, 'no_conflict_styles' ] ); - \add_filter( 'gform_payment_statuses', array( $this, 'gform_payment_statuses' ) ); + \add_filter( 'gform_payment_statuses', [ $this, 'gform_payment_statuses' ] ); $this->maybe_display_confirmation(); } @@ -200,14 +198,14 @@ public function admin_enqueue_scripts() { wp_register_style( 'pronamic-pay-gravityforms', plugins_url( 'css/admin' . $min . '.css', dirname( __FILE__ ) ), - array(), + [], $this->get_version() ); wp_register_script( 'pronamic-pay-gravityforms', plugins_url( 'js/admin' . $min . '.js', dirname( __FILE__ ) ), - array( 'jquery' ), + [ 'jquery' ], $this->get_version(), true ); @@ -278,7 +276,7 @@ public function source_text( $text, Payment $payment ) { $text .= sprintf( false === $entry ? '%2$s' : '%2$s', - add_query_arg( array( 'pronamic_gf_lid' => $payment->get_source_id() ), admin_url( 'admin.php' ) ), + add_query_arg( [ 'pronamic_gf_lid' => $payment->get_source_id() ], admin_url( 'admin.php' ) ), /* translators: %s: source id */ sprintf( __( 'Entry #%s', 'pronamic_ideal' ), $payment->get_source_id() ) ); @@ -311,9 +309,9 @@ public function source_url( $url, Payment $payment ) { if ( false !== $entry ) { $url = add_query_arg( - array( + [ 'pronamic_gf_lid' => $payment->get_source_id(), - ), + ], admin_url( 'admin.php' ) ); } @@ -336,7 +334,7 @@ public function subscription_source_text( $text, Subscription $subscription ) { $text .= sprintf( false === $entry ? '%2$s' : '%2$s', - add_query_arg( array( 'pronamic_gf_lid' => $subscription->get_source_id() ), admin_url( 'admin.php' ) ), + add_query_arg( [ 'pronamic_gf_lid' => $subscription->get_source_id() ], admin_url( 'admin.php' ) ), /* translators: %s: source id */ sprintf( __( 'Entry #%s', 'pronamic_ideal' ), $subscription->get_source_id() ) ); @@ -369,9 +367,9 @@ public function subscription_source_url( $url, Subscription $subscription ) { if ( false !== $entry ) { $url = add_query_arg( - array( + [ 'pronamic_gf_lid' => $subscription->get_source_id(), - ), + ], admin_url( 'admin.php' ) ); } @@ -454,10 +452,10 @@ private function maybe_update_payment_user( $lead, $feed ) { // Update payment post author. wp_update_post( - array( + [ 'ID' => $payment->get_id(), 'post_author' => $user->ID, - ) + ] ); // Update subscription customer user ID and post author. @@ -475,10 +473,10 @@ private function maybe_update_payment_user( $lead, $feed ) { // Update subscription post author. wp_update_post( - array( + [ 'ID' => $subscription->get_id(), 'post_author' => $user->ID, - ) + ] ); } } @@ -554,10 +552,10 @@ public function redirect_url( $url, $payment ) { $url = $confirmation['redirect']; } else { $url = add_query_arg( - array( + [ 'pay_confirmation' => $payment->get_id(), '_wpnonce' => wp_create_nonce( 'gf_confirmation_payment_' . $payment->get_id() ), - ), + ], $lead['source_url'] ); } @@ -593,12 +591,12 @@ public function update_status( Payment $payment, $can_redirect = false ) { $data = new PaymentData( $form, $lead, $feed ); - $action = array( + $action = [ 'id' => $payment->get_id(), 'transaction_id' => $payment->get_transaction_id(), 'amount' => $payment->get_total_amount()->get_value(), 'entry_id' => $lead['id'], - ); + ]; // Get subscription ID from payment period. $periods = $payment->get_periods(); @@ -731,7 +729,7 @@ public function update_payment( Payment $payment ) { $result = $this->addon->refund_payment( $entry, - array( + [ // The Gravity Forms payment add-on callback feature uses the action ID to prevent processing an action twice. 'id' => '', 'type' => 'refund_payment', @@ -760,7 +758,7 @@ public function update_payment( Payment $payment ) { \__( 'Payment has been (partially) refunded. Amount: %s.', 'pronamic_ideal' ), $diff_amount->format_i18n() ), - ) + ] ); if ( true === $result ) { @@ -803,12 +801,12 @@ public function subscription_update_status( Subscription $subscription ) { } // Action. - $action = array( + $action = [ 'id' => $subscription->get_id(), 'subscription_id' => $subscription->get_id(), 'amount' => $amount, 'entry_id' => $lead['id'], - ); + ]; switch ( $subscription->get_status() ) { case SubscriptionStatus::ACTIVE: @@ -868,12 +866,12 @@ public function subscription_renewal_notice( Subscription $subscription ) { $amount = $current_phase->get_amount()->get_value(); } - $action = array( + $action = [ 'subscription_id' => $subscription->get_id(), 'amount' => $amount, 'entry_id' => $lead['id'], 'type' => 'renew_subscription', - ); + ]; $this->addon->post_payment_action( $lead, $action ); } @@ -1048,7 +1046,7 @@ public function fulfill_order( $entry ) { // Delay notifications. // Determine if the feed has Gravity Form 1.7 Feed IDs. if ( $feed->has_delayed_notifications() ) { - $delay_notification_ids = array(); + $delay_notification_ids = []; foreach ( $feed->delay_notification_ids as $notification_id ) { if ( ! isset( $form['notifications'][ $notification_id ] ) ) { @@ -1139,12 +1137,12 @@ public function maybe_display_confirmation() { $form = GFAPI::get_form( $lead['form_id'] ); - GFFormDisplay::$submission[ $form['id'] ] = array( + GFFormDisplay::$submission[ $form['id'] ] = [ 'is_confirmation' => true, 'confirmation_message' => $confirmation, 'form' => $form, 'lead' => $lead, - ); + ]; } } @@ -1172,7 +1170,7 @@ public function get_confirmation( $lead, $payment_status = PaymentStatus::OPEN ) $confirmation_id = $feed->links[ $link ]['confirmation_id']; if ( isset( $form['confirmations'][ $confirmation_id ] ) ) { - $form['confirmations'] = array_intersect_key( $form['confirmations'], array( $confirmation_id => true ) ); + $form['confirmations'] = array_intersect_key( $form['confirmations'], [ $confirmation_id => true ] ); } } @@ -1271,16 +1269,16 @@ public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html if ( null !== $payment ) { $pay_again_url = \add_query_arg( - array( + [ 'pay_again' => $payment->get_id(), 'key' => $payment->key, - ), + ], rgar( $entry, 'source_url' ) ); } // Replacements. - $replacements = array( + $replacements = [ '{payment_status}' => rgar( $entry, 'payment_status' ), '{payment_date}' => rgar( $entry, 'payment_date' ), '{transaction_id}' => rgar( $entry, 'transaction_id' ), @@ -1300,7 +1298,7 @@ public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html '{pronamic_subscription_cancel_url}' => $subscription_cancel_url, '{pronamic_subscription_renew_url}' => $subscription_renew_url, '{pronamic_subscription_renewal_date}' => $subscription_renewal_date, - ); + ]; if ( $url_encode ) { foreach ( $replacements as &$value ) { @@ -1313,142 +1311,119 @@ public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html return $text; } - /** - * Filter currencies. - * - * @param array $currencies Available currencies. - * - * @return mixed - */ - public static function currencies( $currencies ) { - if ( PaymentMethods::is_active( PaymentMethods::GULDEN ) ) { - $currencies['NLG'] = array( - 'name' => PaymentMethods::get_name( PaymentMethods::GULDEN ), - 'symbol_left' => 'G', - 'symbol_right' => '', - 'symbol_padding' => ' ', - 'thousand_separator' => '', - 'decimal_separator' => '.', - 'decimals' => 4, - ); - } - - return $currencies; - } - /** * Get delay actions based on active addons and built-in delay support. * * @return array */ public static function get_delay_actions() { - $actions = array( - 'gravityformsactivecampaign' => array( + $actions = [ + 'gravityformsactivecampaign' => [ 'active' => false, 'meta_key_suffix' => 'activecampaign_subscription', 'delayed_payment_integration' => true, 'label' => __( 'Subscribing the user to ActiveCampaign', 'pronamic_ideal' ), - ), - 'gravityformsaweber' => array( + ], + 'gravityformsaweber' => [ 'active' => false, 'meta_key_suffix' => 'aweber_subscription', 'delayed_payment_integration' => true, 'label' => __( 'Subscribing the user to AWeber', 'pronamic_ideal' ), 'delay_callback' => function() { // @link https://github.com/wp-premium/gravityformsaweber/blob/1.4.2/aweber.php#L124-L125 - \remove_action( 'gform_post_submission', array( 'GFAWeber', 'export' ), 10 ); + \remove_action( 'gform_post_submission', [ 'GFAWeber', 'export' ], 10 ); }, 'process_callback' => function( $entry, $form ) { if ( Core_Util::class_method_exists( 'GFAWeber', 'export' ) ) { - call_user_func( array( 'GFAWeber', 'export' ), $entry, $form, false ); + call_user_func( [ 'GFAWeber', 'export' ], $entry, $form, false ); } }, - ), - 'gravityformscampaignmonitor' => array( + ], + 'gravityformscampaignmonitor' => [ 'active' => false, 'meta_key_suffix' => 'campaignmonitor_subscription', 'delayed_payment_integration' => true, 'label' => __( 'Subscribing the user to Campaign Monitor', 'pronamic_ideal' ), 'delay_callback' => function() { // @link https://github.com/wp-premium/gravityformscampaignmonitor/blob/2.5.1/campaignmonitor.php#L124-L125 - \remove_action( 'gform_after_submission', array( 'GFCampaignMonitor', 'export' ), 10 ); + \remove_action( 'gform_after_submission', [ 'GFCampaignMonitor', 'export' ], 10 ); }, 'process_callback' => function( $entry, $form ) { // @link https://github.com/wp-premium/gravityformscampaignmonitor/blob/2.5.1/campaignmonitor.php#L1184 if ( Core_Util::class_method_exists( 'GFCampaignMonitor', 'export' ) ) { - call_user_func( array( 'GFCampaignMonitor', 'export' ), $entry, $form, false ); + call_user_func( [ 'GFCampaignMonitor', 'export' ], $entry, $form, false ); } }, - ), - 'gravityformsmailchimp' => array( + ], + 'gravityformsmailchimp' => [ 'active' => false, 'meta_key_suffix' => 'mailchimp_subscription', 'delayed_payment_integration' => true, 'label' => __( 'Subscribing the user to MailChimp', 'pronamic_ideal' ), 'delay_callback' => function() { // @link https://github.com/wp-premium/gravityformsmailchimp/blob/2.4.1/mailchimp.php#L120-L121 - \remove_action( 'gform_after_submission', array( 'GFMailChimp', 'export' ), 10 ); + \remove_action( 'gform_after_submission', [ 'GFMailChimp', 'export' ], 10 ); }, 'process_callback' => function( $entry, $form ) { // @link https://github.com/wp-premium/gravityformsmailchimp/blob/2.4.5/mailchimp.php#L1512. if ( Core_Util::class_method_exists( 'GFMailChimp', 'export' ) ) { - call_user_func( array( 'GFMailChimp', 'export' ), $entry, $form, false ); + call_user_func( [ 'GFMailChimp', 'export' ], $entry, $form, false ); } }, - ), - 'slicedinvoices' => array( + ], + 'slicedinvoices' => [ 'active' => false, 'meta_key_suffix' => 'sliced_invoices', 'delayed_payment_integration' => false, 'label' => __( 'Creating quotes and invoices with Sliced Invoices', 'pronamic_ideal' ), - ), - 'gravityforms-moneybird' => array( + ], + 'gravityforms-moneybird' => [ 'active' => false, 'meta_key_suffix' => 'moneybird', 'delayed_payment_integration' => false, 'label' => __( 'Sending estimates and invoices with Moneybird', 'pronamic_ideal' ), - ), - 'gravityformstwilio' => array( + ], + 'gravityformstwilio' => [ 'active' => false, 'meta_key_suffix' => 'twilio', 'delayed_payment_integration' => true, 'label' => __( 'Sending data to Twilio', 'pronamic_ideal' ), - ), - 'gravityformswebhooks' => array( + ], + 'gravityformswebhooks' => [ 'active' => false, 'meta_key_suffix' => 'webhooks', 'delayed_payment_integration' => false, 'label' => __( 'Sending a trigger to Webhooks', 'pronamic_ideal' ), - ), - 'gravityformsdropbox' => array( + ], + 'gravityformsdropbox' => [ 'active' => false, 'meta_key_suffix' => 'dropbox', 'delayed_payment_integration' => false, 'label' => __( 'Uploading files to Dropbox', 'pronamic_ideal' ), - ), - 'gravityformszapier' => array( + ], + 'gravityformszapier' => [ 'active' => class_exists( 'GFZapier' ), 'meta_key_suffix' => 'zapier', 'delayed_payment_integration' => false, 'label' => __( 'Sending data to Zapier', 'pronamic_ideal' ), 'delay_callback' => function() { // @link https://github.com/wp-premium/gravityformszapier/blob/1.4.2/zapier.php#L106 - remove_action( 'gform_after_submission', array( 'GFZapier', 'send_form_data_to_zapier' ), 10 ); + remove_action( 'gform_after_submission', [ 'GFZapier', 'send_form_data_to_zapier' ], 10 ); }, 'process_callback' => function( $entry, $form ) { // @link https://github.com/wp-premium/gravityformszapier/blob/1.4.2/zapier.php#L469-L533. if ( Core_Util::class_method_exists( 'GFZapier', 'send_form_data_to_zapier' ) ) { - call_user_func( array( 'GFZapier', 'send_form_data_to_zapier' ), $entry, $form ); + call_user_func( [ 'GFZapier', 'send_form_data_to_zapier' ], $entry, $form ); } }, - ), - 'gravityformsuserregistration' => array( + ], + 'gravityformsuserregistration' => [ 'active' => false, 'meta_key_suffix' => 'user_registration', 'delayed_payment_integration' => true, 'label' => __( 'Registering the user', 'pronamic_ideal' ), - ), - 'gravityflow' => array( + ], + 'gravityflow' => [ 'active' => false, 'meta_key_suffix' => 'gravityflow', 'delayed_payment_integration' => true, @@ -1464,19 +1439,19 @@ public static function get_delay_actions() { $gravityflow->process_workflow( $form, $entry['id'] ); } }, - ), - ); + ], + ]; $addons = GFAddOn::get_registered_addons(); foreach ( $addons as $class ) { - $addon = call_user_func( array( $class, 'get_instance' ) ); + $addon = call_user_func( [ $class, 'get_instance' ] ); $slug = $addon->get_slug(); if ( isset( $addon->delayed_payment_integration ) ) { if ( ! isset( $actions[ $slug ] ) ) { - $actions[ $slug ] = array(); + $actions[ $slug ] = []; } $actions[ $slug ]['meta_key_suffix'] = $slug; @@ -1544,7 +1519,7 @@ public function maybe_prepopulate_form( $args ) { } // Set field values. - $field_values = array(); + $field_values = []; foreach ( $entry as $key => $value ) { $is_numeric = \is_numeric( $key ); diff --git a/src/FeedsDB.php b/src/FeedsDB.php index 62e7d05..cdcd2e8 100644 --- a/src/FeedsDB.php +++ b/src/FeedsDB.php @@ -32,25 +32,25 @@ class FeedsDB { * @param array $meta Meta query array. * @return PayFeed[] */ - public static function get_feeds_by_form_id( $form_id, $meta = array() ) { - $feeds = array(); + public static function get_feeds_by_form_id( $form_id, $meta = [] ) { + $feeds = []; - $meta_query = array( - array( + $meta_query = [ + [ 'key' => '_pronamic_pay_gf_form_id', 'value' => $form_id, - ), - ); + ], + ]; $meta_query = array_merge( $meta_query, $meta ); $query = new WP_Query( - array( + [ 'fields' => 'ids', 'post_type' => 'pronamic_pay_gf', 'posts_per_page' => 50, 'meta_query' => $meta_query, - ) + ] ); foreach ( $query->posts as $post_id ) { @@ -69,19 +69,19 @@ public static function get_feeds_by_form_id( $form_id, $meta = array() ) { * @return array */ public static function get_active_feeds_by_form_id( $form_id ) { - $meta = array( - array( + $meta = [ + [ 'relation' => 'OR', - array( + [ 'key' => '_pronamic_pay_gf_feed_active', 'value' => 1, - ), - array( + ], + [ 'key' => '_pronamic_pay_gf_feed_active', 'compare' => 'NOT EXISTS', - ), - ), - ); + ], + ], + ]; $feeds = self::get_feeds_by_form_id( $form_id, $meta ); diff --git a/src/Fields.php b/src/Fields.php index 0b0a14b..890b6af 100644 --- a/src/Fields.php +++ b/src/Fields.php @@ -52,7 +52,7 @@ public function __construct() { } // Add extra fields settings. - add_action( 'gform_field_standard_settings', array( $this, 'field_standard_settings' ), 10, 2 ); + add_action( 'gform_field_standard_settings', [ $this, 'field_standard_settings' ], 10, 2 ); } /** @@ -67,11 +67,11 @@ public function __construct() { */ public static function add_pay_field_group( $field_groups ) { if ( ! isset( $field_groups['pronamic_pay_fields'] ) ) { - $field_groups['pronamic_pay_fields'] = array( + $field_groups['pronamic_pay_fields'] = [ 'name' => 'pronamic_pay_fields', 'label' => __( 'Payment Fields', 'pronamic_ideal' ), - 'fields' => array(), - ); + 'fields' => [], + ]; } return $field_groups; diff --git a/src/IssuersField.php b/src/IssuersField.php index 7682c96..ef18169 100644 --- a/src/IssuersField.php +++ b/src/IssuersField.php @@ -12,6 +12,7 @@ use GF_Field_Select; use Pronamic\WordPress\Pay\Core\Gateway; +use Pronamic\WordPress\Pay\Fields\IDealIssuerSelectField; use Pronamic\WordPress\Pay\Core\PaymentMethods; use Pronamic\WordPress\Pay\Plugin; @@ -49,12 +50,12 @@ class IssuersField extends GF_Field_Select { * * @param array $properties Properties. */ - public function __construct( $properties = array() ) { + public function __construct( $properties = [] ) { parent::__construct( $properties ); // Actions. - if ( ! has_action( 'gform_editor_js_set_default_values', array( __CLASS__, 'editor_js_set_default_values' ) ) ) { - add_action( 'gform_editor_js_set_default_values', array( __CLASS__, 'editor_js_set_default_values' ) ); + if ( ! has_action( 'gform_editor_js_set_default_values', [ __CLASS__, 'editor_js_set_default_values' ] ) ) { + add_action( 'gform_editor_js_set_default_values', [ __CLASS__, 'editor_js_set_default_values' ] ); } if ( @@ -86,7 +87,7 @@ public function __construct( $properties = array() ) { $this->cssClass .= ' pronamic_pay_display_icons'; } - if ( false === strpos( $this->cssClass, 'gf_list_2col' ) && in_array( $this->pronamicPayDisplayMode, array( 'icons-64', 'icons-125' ), true ) ) { + if ( false === strpos( $this->cssClass, 'gf_list_2col' ) && in_array( $this->pronamicPayDisplayMode, [ 'icons-64', 'icons-125' ], true ) ) { $this->cssClass .= ' gf_list_2col'; } } @@ -99,7 +100,7 @@ public function __construct( $properties = array() ) { * @return array */ public function get_form_editor_field_settings() { - return array( + return [ 'conditional_logic_field_setting', 'error_message_setting', 'enable_enhanced_ui_setting', @@ -113,7 +114,7 @@ public function get_form_editor_field_settings() { 'rules_setting', 'pronamic_pay_config_field_setting', 'pronamic_pay_display_field_setting', - ); + ]; } /** @@ -139,15 +140,24 @@ private function get_gateway() { $gateway = Plugin::get_gateway( $feed->config_id ); - if ( $gateway ) { - $issuers = $gateway->get_transient_issuers(); + if ( null === $gateway ) { + continue; + } - if ( empty( $issuers ) ) { - continue; - } + // Always use iDEAL payment method for issuer field. + $issuer_field = $gateway->first_payment_method_field( PaymentMethods::IDEAL, IDealIssuerSelectField::class ); + + if ( null === $issuer_field ) { + continue; + } + + $options = $issuer_field->get_options(); - return $gateway; + if ( 1 === count( $options ) ) { + continue; } + + return $gateway; } } @@ -160,7 +170,7 @@ private function get_gateway() { * @param int $form_id Gravity Forms form ID. */ private function set_choices( $form_id ) { - $this->choices = array(); + $this->choices = []; // Prevent HTTP requests in forms list. if ( \doing_filter( 'gform_form_actions' ) ) { @@ -174,21 +184,24 @@ private function set_choices( $form_id ) { } // Always use iDEAL payment method for issuer field. - $gateway->set_payment_method( PaymentMethods::IDEAL ); + $issuer_field = $gateway->first_payment_method_field( PaymentMethods::IDEAL, IDealIssuerSelectField::class ); - $field = $gateway->get_issuer_field(); - - if ( null === $field ) { + if ( null === $issuer_field ) { return; } - foreach ( $field['choices'] as $group ) { - foreach ( $group['options'] as $value => $label ) { - $this->choices[] = array( - 'value' => $value, - 'text' => $label, - ); - } + /** + * Gravity Forms has no support for elements. + * + * @link https://github.com/pronamic/wp-pronamic-pay/issues/154#issuecomment-1183309350 + */ + $options = $issuer_field->get_flat_options(); + + foreach ( $options as $option ) { + $this->choices[] = [ + 'value' => $option->value, + 'text' => $option->label, + ]; } } @@ -228,30 +241,35 @@ public function get_field_input( $form, $value = '', $entry = null ) { '', ' ' => '-', - ); + ]; // Icon file and size. switch ( $this->pronamicPayDisplayMode ) { case 'icons-24': - $dimensions = array( 24, 24 ); + $dimensions = [ 24, 24 ]; break; case 'icons-64': - $dimensions = array( 64, 64 ); + $dimensions = [ 64, 64 ]; break; case 'icons-125': default: - $dimensions = array( 125, 60 ); + $dimensions = [ 125, 60 ]; } $images_path = plugin_dir_path( Plugin::$file ) . 'images/'; // Loop issuers. foreach ( $this->choices as $choice ) { + // Ignore choices without value. + if ( \array_key_exists( 'value', $choice ) && empty( $choice['value'] ) ) { + continue; + } + // Icon file name. $issuer = strtr( strtolower( $choice['text'] ), $replacements ); @@ -537,10 +555,10 @@ public function get_form_editor_field_title() { * @return array */ public function get_form_editor_button() { - return array( + return [ 'group' => 'pronamic_pay_fields', 'text' => __( 'Issuer', 'pronamic_ideal' ), - ); + ]; } /** diff --git a/src/PayFeed.php b/src/PayFeed.php index e4b6720..79a42e5 100644 --- a/src/PayFeed.php +++ b/src/PayFeed.php @@ -148,11 +148,16 @@ public function __construct( $post_id ) { $this->conditional_logic_object = $conditional_logic_object; } + // Unset conditional logic object without any logic. + if ( \is_array( $this->conditional_logic_object ) && \array_key_exists( 'conditionalLogic', $this->conditional_logic_object ) && empty( $this->conditional_logic_object['conditionalLogic'] ) ) { + $this->conditional_logic_object = null; + } + // The `_gform_setting_...` does not include the `conditionalLogic` key, as was the case previously with the `_gaddon_setting`. if ( GravityForms::version_compare( '2.5', '>=' ) && \is_array( $this->conditional_logic_object ) && ! \array_key_exists( 'conditionalLogic', $this->conditional_logic_object ) ) { - $this->conditional_logic_object = array( + $this->conditional_logic_object = [ 'conditionalLogic' => $this->conditional_logic_object, - ); + ]; } } @@ -166,27 +171,27 @@ public function __construct( $post_id ) { $condition_operator = get_post_meta( $post_id, '_pronamic_pay_gf_condition_operator', true ); $condition_value = get_post_meta( $post_id, '_pronamic_pay_gf_condition_value', true ); - $rule = array( + $rule = [ 'fieldId' => 0, 'operator' => 'is', 'value' => '', - ); + ]; if ( ! empty( $condition_field_id ) && ! empty( $condition_operator ) && ! empty( $condition_value ) ) { - $rule = array( + $rule = [ 'fieldId' => $condition_field_id, 'operator' => ( GravityForms::OPERATOR_IS === $condition_operator ? 'is' : 'isnot' ), 'value' => $condition_value, - ); + ]; } - $this->conditional_logic_object = array( - 'conditionalLogic' => array( + $this->conditional_logic_object = [ + 'conditionalLogic' => [ 'actionType' => 'show', 'logicType' => 'all', - 'rules' => array( $rule ), - ), - ); + 'rules' => [ $rule ], + ], + ]; } // Delay actions. @@ -194,7 +199,7 @@ public function __construct( $post_id ) { $this->delay_user_notification = get_post_meta( $post_id, '_pronamic_pay_gf_delay_user_notification', true ); $this->delay_post_creation = get_post_meta( $post_id, '_pronamic_pay_gf_delay_post_creation', true ); - $this->delay_actions = array(); + $this->delay_actions = []; $delay_actions = Extension::get_delay_actions(); @@ -256,15 +261,15 @@ function( $action ) { // Delay notification IDs. $ids = get_post_meta( $post_id, '_pronamic_pay_gf_delay_notification_ids', true ); - $this->delay_notification_ids = is_array( $ids ) ? $ids : array(); + $this->delay_notification_ids = is_array( $ids ) ? $ids : []; // Fields. $fields = get_post_meta( $post_id, '_pronamic_pay_gf_fields', true ); - $this->fields = is_array( $fields ) ? $fields : array(); + $this->fields = is_array( $fields ) ? $fields : []; // Links. $links = get_post_meta( $post_id, '_pronamic_pay_gf_links', true ); - $this->links = is_array( $links ) ? $links : array(); + $this->links = is_array( $links ) ? $links : []; } /** diff --git a/src/PaymentAddOn.php b/src/PaymentAddOn.php index 7cd11db..235ce1f 100644 --- a/src/PaymentAddOn.php +++ b/src/PaymentAddOn.php @@ -39,10 +39,10 @@ class PaymentAddOn extends GFPaymentAddOn { * * @var array */ - protected $_capabilities = array( + protected $_capabilities = [ 'gravityforms_pronamic_pay', 'gravityforms_pronamic_pay_uninstall', - ); + ]; /** * Capabilities settings page. @@ -104,12 +104,12 @@ public function __construct() { /* * Actions. */ - add_action( 'admin_init', array( $this, 'pronamic_maybe_save_feed' ), 20 ); + add_action( 'admin_init', [ $this, 'pronamic_maybe_save_feed' ], 20 ); /* * Filters. */ - add_filter( 'gform_admin_pre_render', array( $this, 'admin_pre_render' ), 10, 1 ); + add_filter( 'gform_admin_pre_render', [ $this, 'admin_pre_render' ], 10, 1 ); } /** @@ -156,25 +156,25 @@ public function pronamic_maybe_save_feed() { } $post_id = wp_insert_post( - array( + [ 'ID' => $post_id, 'post_type' => 'pronamic_pay_gf', 'post_title' => $post_title, 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', - ) + ] ); $url = add_query_arg( - array( + [ 'page' => 'gf_edit_forms', 'view' => 'settings', 'subview' => 'pronamic_pay', 'id' => $form_id, 'fid' => $post_id, 'message' => $post_id ? '1' : '0', - ), + ], 'admin.php' ); @@ -197,7 +197,7 @@ public function admin_pre_render( $form ) { $feeds = FeedsDB::get_feeds_by_form_id( $form['id'] ); - $condition_field_ids = array(); + $condition_field_ids = []; foreach ( $feeds as $feed ) { if ( empty( $feed->condition_field_id ) ) { @@ -259,10 +259,10 @@ public function form_settings( $form ) { $feed = new PayFeed( $post_id ); $this->set_settings( - array( + [ 'feed_condition_conditional_logic' => $feed->condition_enabled, 'feed_condition_conditional_logic_object' => $feed->conditional_logic_object, - ) + ] ); require dirname( __FILE__ ) . '/../views/html-admin-feed-gf-box.php'; @@ -291,7 +291,7 @@ public function feed_list_title() { return $title; } - $url = add_query_arg( array( 'fid' => '0' ) ); + $url = add_query_arg( [ 'fid' => '0' ] ); $title .= sprintf( '%s', @@ -314,9 +314,9 @@ public function get_feed_table( $form ) { $columns = $this->feed_list_columns(); $bulk_actions = $this->get_bulk_actions(); $action_links = $this->get_action_links(); - $column_value_callback = array( $this, 'get_column_value' ); - $no_item_callback = array( $this, 'feed_list_no_item_message' ); - $message_callback = array( $this, 'feed_list_message' ); + $column_value_callback = [ $this, 'get_column_value' ]; + $no_item_callback = [ $this, 'feed_list_no_item_message' ]; + $message_callback = [ $this, 'feed_list_message' ]; $feed_table = new GFAddOnFeedsTable( $feeds, $this->_slug, $columns, $bulk_actions, $action_links, $column_value_callback, $no_item_callback, $message_callback, $this ); @@ -334,35 +334,35 @@ public function get_feed_table( $form ) { */ public function get_feeds( $form_id = null ) { $query = new WP_Query( - array( + [ 'post_type' => 'pronamic_pay_gf', 'posts_per_page' => 50, - 'meta_query' => array( - array( + 'meta_query' => [ + [ 'key' => '_pronamic_pay_gf_form_id', 'value' => $form_id, - ), - ), - ) + ], + ], + ] ); - $posts = array(); + $posts = []; foreach ( $query->posts as $post ) { $post = (array) $post; $post = array_merge( $post, - array( + [ 'id' => $post['ID'], 'form_id' => get_post_meta( $post['ID'], '_pronamic_pay_gf_form_id', true ), 'is_active' => true, - 'meta' => array( + 'meta' => [ 'post' => $post, 'feed_name' => $post['post_title'], 'transactionType' => 'product', - ), - ) + ], + ] ); // Is activated? @@ -394,18 +394,18 @@ public function get_feed( $id ) { $post = array_merge( $post, - array( + [ 'id' => $post['ID'], 'form_id' => get_post_meta( $id, '_pronamic_pay_gf_form_id', true ), 'is_active' => true, - 'meta' => array( + 'meta' => [ 'post' => $post, 'feed_name' => $post['post_title'], 'transactionType' => 'product', 'feed_condition_conditional_logic' => $feed->condition_enabled, 'feed_condition_conditional_logic_object' => $feed->conditional_logic_object, - ), - ) + ], + ] ); // Is activated? @@ -429,13 +429,13 @@ public function is_feed_condition_met( $feed, $form, $entry ) { $pay_feed = new PayFeed( $feed['ID'] ); if ( ! \array_key_exists( 'meta', $feed ) ) { - $feed['meta'] = array(); + $feed['meta'] = []; } - $feed['meta'] = array( + $feed['meta'] = [ 'feed_condition_conditional_logic' => $pay_feed->condition_enabled, 'feed_condition_conditional_logic_object' => $pay_feed->conditional_logic_object, - ); + ]; return parent::is_feed_condition_met( $feed, $form, $entry ); } @@ -446,11 +446,11 @@ public function is_feed_condition_met( $feed, $form, $entry ) { * @return array */ public function feed_list_columns() { - return array( + return [ 'name' => esc_html__( 'Name', 'pronamic_ideal' ), 'transaction_description' => esc_html__( 'Transaction Description', 'pronamic_ideal' ), 'configuration' => esc_html__( 'Configuration', 'pronamic_ideal' ), - ); + ]; } /** @@ -467,7 +467,7 @@ public function get_column_value_name( $feed ) { $title = __( 'Default pay feed', 'pronamic_ideal' ); } - $edit_url = add_query_arg( array( 'fid' => $feed['id'] ) ); + $edit_url = add_query_arg( [ 'fid' => $feed['id'] ] ); ?> @@ -520,7 +520,7 @@ public function feed_list_no_item_message() { printf( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $label, - '', + '', '' ); } @@ -533,14 +533,14 @@ public function feed_list_no_item_message() { * @return array */ public function supported_notification_events( $form ) { - $events = array(); + $events = []; // Check if form has feeds for this add-on. if ( ! $this->has_feed( $form['id'] ) ) { return $events; } - $events = array( + $events = [ 'complete_payment' => esc_html__( 'Payment Completed', 'pronamic_ideal' ), 'fail_payment' => esc_html__( 'Payment Failed', 'pronamic_ideal' ), 'add_pending_payment' => esc_html__( 'Payment Pending', 'pronamic_ideal' ), @@ -552,7 +552,7 @@ public function supported_notification_events( $form ) { 'renew_subscription' => esc_html__( 'Subscription Renewal Notice', 'pronamic_ideal' ), 'add_subscription_payment' => esc_html__( 'Subscription Payment Added', 'pronamic_ideal' ), 'fail_subscription_payment' => esc_html__( 'Subscription Payment Failed', 'pronamic_ideal' ), - ); + ]; return $events; } @@ -595,13 +595,13 @@ public function insert_feed( $form_id, $is_active, $meta ) { // Insert post. $post_id = wp_insert_post( - array( + [ 'post_type' => 'pronamic_pay_gf', 'post_title' => $meta['feed_name'], 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', - ) + ] ); $original_meta = get_post_meta( $original_feed['ID'] ); diff --git a/src/PaymentData.php b/src/PaymentData.php index 62e34c2..ac69233 100644 --- a/src/PaymentData.php +++ b/src/PaymentData.php @@ -11,7 +11,6 @@ namespace Pronamic\WordPress\Pay\Extensions\GravityForms; use GFCommon; -use Pronamic\WordPress\DateTime\DateTime; use Pronamic\WordPress\Pay\Core\PaymentMethods; use Pronamic\WordPress\Pay\Core\Util as Core_Util; use Pronamic\WordPress\Pay\CreditCard; @@ -52,7 +51,7 @@ class PaymentData { private $feed; /** - * Constructs and initialize an Gravity Forms iDEAL data proxy + * Constructs and initialize a Gravity Forms iDEAL data proxy * * @param array $form Gravity Forms form. * @param array $lead Gravity Forms lead/entry. @@ -71,7 +70,7 @@ public function __construct( $form, $lead, $feed ) { * * @return null|string */ - public function get_field_value( $field_name ) { + public function get_field_value( $field_name ) : ?string { if ( ! isset( $this->feed->fields[ $field_name ] ) ) { return null; } @@ -98,7 +97,7 @@ public function get_field_value( $field_name ) { * * @return string */ - public function get_description() { + public function get_description() : string { $description = $this->feed->transaction_description; if ( empty( $description ) ) { @@ -115,7 +114,7 @@ public function get_description() { * * @return string */ - public function get_order_id() { + public function get_order_id() : string { $order_id = $this->feed->order_id; if ( ! empty( $this->feed->entry_id_prefix ) ) { @@ -136,7 +135,7 @@ public function get_order_id() { * * @return string */ - public function get_currency_alphabetic_code() { + public function get_currency_alphabetic_code() : string { if ( isset( $this->lead['currency'] ) ) { return $this->lead['currency']; } @@ -149,16 +148,18 @@ public function get_currency_alphabetic_code() { * * @return string|null */ - public function get_payment_method() { - $fields = GFCommon::get_fields_by_type( $this->form, array( Fields::PAYMENT_METHODS_FIELD_TYPE ) ); + public function get_payment_method() : ?string { + $fields = GFCommon::get_fields_by_type( $this->form, [ Fields::PAYMENT_METHODS_FIELD_TYPE ] ); foreach ( $fields as $field ) { - if ( ! RGFormsModel::is_field_hidden( $this->form, $field, array(), $this->lead ) ) { + if ( ! RGFormsModel::is_field_hidden( $this->form, $field, [], $this->lead ) ) { $method = RGFormsModel::get_field_value( $field ); return $method; } } + + return null; } /** @@ -166,16 +167,18 @@ public function get_payment_method() { * * @return string|null */ - public function get_issuer_id() { - $fields = GFCommon::get_fields_by_type( $this->form, array( IssuersField::TYPE ) ); + public function get_issuer_id() : ?string { + $fields = GFCommon::get_fields_by_type( $this->form, [ IssuersField::TYPE ] ); foreach ( $fields as $field ) { - if ( RGFormsModel::is_field_hidden( $this->form, $field, array() ) ) { + if ( RGFormsModel::is_field_hidden( $this->form, $field, [] ) ) { continue; } return RGFormsModel::get_field_value( $field ); } + + return null; } /** @@ -183,10 +186,10 @@ public function get_issuer_id() { * * @return CreditCard|null */ - public function get_credit_card() { + public function get_credit_card() : ?CreditCard { $credit_card = null; - $credit_card_fields = GFCommon::get_fields_by_type( $this->form, array( 'creditcard' ) ); + $credit_card_fields = GFCommon::get_fields_by_type( $this->form, [ 'creditcard' ] ); $credit_card_field = array_shift( $credit_card_fields ); @@ -230,14 +233,14 @@ public function get_credit_card() { * * @return int|null */ - public function get_subscription_frequency() { + public function get_subscription_frequency() : ?int { $frequency = null; switch ( $this->feed->subscription_frequency_type ) { case GravityForms::SUBSCRIPTION_FREQUENCY_FIELD: $field = RGFormsModel::get_field( $this->form, $this->feed->subscription_frequency_field ); - if ( ! RGFormsModel::is_field_hidden( $this->form, $field, array(), $this->lead ) ) { + if ( ! RGFormsModel::is_field_hidden( $this->form, $field, [], $this->lead ) ) { if ( isset( $this->lead[ $this->feed->subscription_frequency_field ] ) ) { $frequency = intval( $this->lead[ $this->feed->subscription_frequency_field ] ); } @@ -258,17 +261,17 @@ public function get_subscription_frequency() { * * @return object */ - public function get_subscription_interval() { - $interval = (object) array( + public function get_subscription_interval() : object { + $interval = (object) [ 'unit' => 'D', 'value' => null, - ); + ]; switch ( $this->feed->subscription_interval_type ) { case GravityForms::SUBSCRIPTION_INTERVAL_FIELD: $field = RGFormsModel::get_field( $this->form, $this->feed->subscription_interval_field ); - if ( ! RGFormsModel::is_field_hidden( $this->form, $field, array(), $this->lead ) ) { + if ( ! RGFormsModel::is_field_hidden( $this->form, $field, [], $this->lead ) ) { if ( isset( $this->lead[ $this->feed->subscription_interval_field ] ) ) { $value = $this->lead[ $this->feed->subscription_interval_field ]; diff --git a/src/PaymentFormPostType.php b/src/PaymentFormPostType.php index f0dad20..2be4431 100644 --- a/src/PaymentFormPostType.php +++ b/src/PaymentFormPostType.php @@ -33,7 +33,7 @@ public function __construct() { * * @link https://github.com/WordPress/WordPress/blob/4.0/wp-includes/post.php#L167 */ - add_action( 'init', array( $this, 'init' ), 0 ); // Highest priority. + add_action( 'init', [ $this, 'init' ], 0 ); // Highest priority. } /** @@ -42,9 +42,9 @@ public function __construct() { public function init() { register_post_type( 'pronamic_pay_gf', - array( + [ 'label' => __( 'Payment Feeds', 'pronamic_ideal' ), - 'labels' => array( + 'labels' => [ 'name' => __( 'Payment Feeds', 'pronamic_ideal' ), 'singular_name' => __( 'Payment Feed', 'pronamic_ideal' ), 'add_new' => __( 'Add New', 'pronamic_ideal' ), @@ -60,17 +60,17 @@ public function init() { 'filter_items_list' => __( 'Filter payment feeds list', 'pronamic_ideal' ), 'items_list_navigation' => __( 'Payment feeds list navigation', 'pronamic_ideal' ), 'items_list' => __( 'Payment feeds list', 'pronamic_ideal' ), - ), + ], 'public' => false, 'publicly_queryable' => false, 'show_ui' => false, 'show_in_nav_menus' => false, 'show_in_menu' => false, 'show_in_admin_bar' => false, - 'supports' => array( 'title', 'revisions' ), + 'supports' => [ 'title', 'revisions' ], 'rewrite' => false, 'query_var' => false, - ) + ] ); } } diff --git a/src/PaymentMethodsField.php b/src/PaymentMethodsField.php index a02883b..6586a9e 100644 --- a/src/PaymentMethodsField.php +++ b/src/PaymentMethodsField.php @@ -52,7 +52,7 @@ class PaymentMethodsField extends GF_Field_Select { * * @param array $properties Field properties. */ - public function __construct( $properties = array() ) { + public function __construct( $properties = [] ) { parent::__construct( $properties ); /* @@ -65,25 +65,25 @@ public function __construct( $properties = array() ) { $this->inputs = null; // Actions. - if ( ! has_action( 'gform_editor_js_set_default_values', array( $this, 'editor_js_set_default_values' ) ) ) { - add_action( 'gform_editor_js_set_default_values', array( $this, 'editor_js_set_default_values' ) ); + if ( ! has_action( 'gform_editor_js_set_default_values', [ $this, 'editor_js_set_default_values' ] ) ) { + add_action( 'gform_editor_js_set_default_values', [ $this, 'editor_js_set_default_values' ] ); } // Filters. - if ( ! has_filter( 'gform_gf_field_create', array( $this, 'field_create' ) ) ) { - add_filter( 'gform_gf_field_create', array( $this, 'field_create' ), 10, 2 ); + if ( ! has_filter( 'gform_gf_field_create', [ $this, 'field_create' ] ) ) { + add_filter( 'gform_gf_field_create', [ $this, 'field_create' ], 10, 2 ); } - if ( ! has_filter( 'gform_get_field_value', array( $this, 'get_field_value' ) ) ) { - add_filter( 'gform_get_field_value', array( $this, 'get_field_value' ), 10, 3 ); + if ( ! has_filter( 'gform_get_field_value', [ $this, 'get_field_value' ] ) ) { + add_filter( 'gform_get_field_value', [ $this, 'get_field_value' ], 10, 3 ); } - if ( ! has_filter( 'gform_form_update_meta', array( __CLASS__, 'form_update_meta' ) ) ) { - add_filter( 'gform_form_update_meta', array( __CLASS__, 'form_update_meta' ), 10, 3 ); + if ( ! has_filter( 'gform_form_update_meta', [ __CLASS__, 'form_update_meta' ] ) ) { + add_filter( 'gform_form_update_meta', [ __CLASS__, 'form_update_meta' ], 10, 3 ); } - if ( ! has_filter( 'gform_pre_render', array( __CLASS__, 'form_pre_render' ) ) ) { - add_filter( 'gform_pre_render', array( __CLASS__, 'form_pre_render' ), 10, 3 ); + if ( ! has_filter( 'gform_pre_render', [ __CLASS__, 'form_pre_render' ] ) ) { + add_filter( 'gform_pre_render', [ __CLASS__, 'form_pre_render' ], 10, 3 ); } // Admin. @@ -95,7 +95,7 @@ public function __construct( $properties = array() ) { * * @link https://github.com/wp-premium/gravityforms/blob/2.4.17/common.php#L804-L805 */ - $this->inputs = array(); + $this->inputs = []; if ( empty( $this->formId ) && 'gf_edit_forms' === filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ) ) { $this->formId = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_STRING ); @@ -119,7 +119,7 @@ public function __construct( $properties = array() ) { $this->cssClass .= ' pronamic_pay_display_icons'; } - if ( false === strpos( $this->cssClass, 'gf_list_' ) && in_array( $this->pronamicPayDisplayMode, array( 'icons-64', 'icons-125' ), true ) ) { + if ( false === strpos( $this->cssClass, 'gf_list_' ) && in_array( $this->pronamicPayDisplayMode, [ 'icons-64', 'icons-125' ], true ) ) { $this->cssClass .= ' gf_list_2col'; } } @@ -157,7 +157,7 @@ public function field_create( $field, $properties ) { * @return array */ public function get_form_editor_field_settings() { - return array( + return [ 'conditional_logic_field_setting', 'error_message_setting', 'enable_enhanced_ui_setting', @@ -172,7 +172,7 @@ public function get_form_editor_field_settings() { 'rules_setting', 'pronamic_pay_config_field_setting', 'pronamic_pay_display_field_setting', - ); + ]; } /** @@ -181,7 +181,7 @@ public function get_form_editor_field_settings() { * @return array */ private function get_gateways() { - $gateways = array(); + $gateways = []; $feeds = FeedsDB::get_feeds_by_form_id( $this->formId ); @@ -203,7 +203,7 @@ private function get_gateways() { // Get all gateways if config ID setting is unused. if ( empty( $gateways ) ) { $gateways = array_map( - array( 'Pronamic\WordPress\Pay\Plugin', 'get_gateway' ), + [ 'Pronamic\WordPress\Pay\Plugin', 'get_gateway' ], $config_ids ); @@ -222,7 +222,7 @@ private function get_gateways() { private function set_choices( $form_id ) { // Prevent HTTP requests in forms list. if ( \doing_filter( 'gform_form_actions' ) ) { - $this->choices = array(); + $this->choices = []; return; } @@ -231,7 +231,7 @@ private function set_choices( $form_id ) { $payment_methods = $this->get_gateway_payment_methods(); // Choices. - $choices = array(); + $choices = []; // Gravity Forms. if ( is_array( $this->choices ) ) { @@ -248,12 +248,12 @@ private function set_choices( $form_id ) { foreach ( $payment_methods as $value => $label ) { // Only add built-in payment if it's not already set. if ( ! isset( $choices[ $value ] ) ) { - $choices[ $value ] = array( + $choices[ $value ] = [ 'value' => $value, 'text' => $label, 'isSelected' => false, 'builtin' => true, - ); + ]; } } @@ -304,7 +304,7 @@ public function get_field_input( $form, $value = '', $entry = null ) { $display_choices = $choices; if ( \is_admin() && 'gf_edit_forms' === \filter_input( \INPUT_GET, 'page', \FILTER_SANITIZE_STRING ) ) { - $display_choices = array_filter( $choices, array( __CLASS__, 'filter_choice_is_selected' ) ); + $display_choices = array_filter( $choices, [ __CLASS__, 'filter_choice_is_selected' ] ); } // Make first item selected. @@ -332,24 +332,24 @@ function ( &$item, $key ) { '-', ' ' => '-', - ); + ]; // Icon file and size. switch ( $this->pronamicPayDisplayMode ) { case 'icons-24': - $dimensions = array( 24, 24 ); + $dimensions = [ 24, 24 ]; break; case 'icons-64': - $dimensions = array( 64, 64 ); + $dimensions = [ 64, 64 ]; break; case 'icons-125': default: - $dimensions = array( 125, 60 ); + $dimensions = [ 125, 60 ]; } // Loop payment methods. @@ -361,11 +361,15 @@ function ( &$item, $key ) { $label_content = \sprintf( '%s', esc_html( $choice['text'] ) ); if ( \array_key_exists( $payment_method, PaymentMethods::get_payment_methods() ) ) { - $label_content = \sprintf( - '%1$s%1$s', - \esc_html( $choice['text'] ), - \esc_url( PaymentMethods::get_icon_url( $payment_method ) ) - ); + $icon_url = PaymentMethods::get_icon_url( $payment_method ); + + if ( null !== $icon_url ) { + $label_content = \sprintf( + '%1$s%1$s', + \esc_html( $choice['text'] ), + \esc_url( $icon_url ) + ); + } } \printf( @@ -671,7 +675,7 @@ public static function form_pre_render( $form, $ajax, $field_values ) { } // Remove unselected choices. - $display_choices = array_filter( $field['choices'], array( __CLASS__, 'filter_choice_is_selected' ) ); + $display_choices = array_filter( $field['choices'], [ __CLASS__, 'filter_choice_is_selected' ] ); // Set first item as selected. \array_walk( @@ -708,10 +712,10 @@ public function get_form_editor_field_title() { * @return array */ public function get_form_editor_button() { - return array( + return [ 'group' => 'pronamic_pay_fields', 'text' => __( 'Payment Method', 'pronamic_ideal' ), - ); + ]; } /** @@ -739,12 +743,18 @@ public function add_button( $field_groups ) { private function get_gateway_payment_methods() { $gateways = $this->get_gateways(); - $payment_methods = array(); + $payment_methods = []; foreach ( $gateways as $gateway ) { - $options = $gateway->get_payment_method_field_options( false ); + $methods = $gateway->get_payment_methods( + [ + 'status' => [ '', 'active' ], + ] + ); - $payment_methods = array_merge( $payment_methods, $options ); + foreach ( $methods as $method ) { + $payment_methods[ $method->get_id() ] = $method->get_name(); + } } if ( empty( $payment_methods ) ) { diff --git a/src/PaymentStatuses.php b/src/PaymentStatuses.php index e1d0d5e..80db00f 100644 --- a/src/PaymentStatuses.php +++ b/src/PaymentStatuses.php @@ -124,7 +124,6 @@ public static function transform( $status ) { case Core_Statuses::REFUNDED: return self::REFUNDED; - case Core_Statuses::RESERVED: case Core_Statuses::OPEN: return self::PROCESSING; diff --git a/src/Processor.php b/src/Processor.php index de9d83d..d0db53e 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -104,7 +104,7 @@ public function __construct( array $form, Extension $extension ) { // Determine payment feed for processing. $feeds = FeedsDB::get_active_feeds_by_form_id( $this->form_id ); - $entry = array(); + $entry = []; foreach ( $feeds as $feed ) { $gf_feed = $extension->addon->get_feed( $feed->id ); @@ -134,25 +134,25 @@ private function add_hooks() { */ // Lead. - add_action( 'gform_entry_post_save', array( $this, 'entry_post_save' ), 10, 2 ); + add_action( 'gform_entry_post_save', [ $this, 'entry_post_save' ], 10, 2 ); // Delay (@see GFFormDisplay::handle_submission > GFCommon::send_form_submission_notifications). - add_filter( 'gform_disable_admin_notification_' . $this->form_id, array( $this, 'maybe_delay_admin_notification' ), 10, 3 ); - add_filter( 'gform_disable_user_notification_' . $this->form_id, array( $this, 'maybe_delay_user_notification' ), 10, 3 ); - add_filter( 'gform_disable_post_creation_' . $this->form_id, array( $this, 'maybe_delay_post_creation' ), 10, 3 ); - add_filter( 'gform_disable_notification_' . $this->form_id, array( $this, 'maybe_delay_notification' ), 10, 4 ); + add_filter( 'gform_disable_admin_notification_' . $this->form_id, [ $this, 'maybe_delay_admin_notification' ], 10, 3 ); + add_filter( 'gform_disable_user_notification_' . $this->form_id, [ $this, 'maybe_delay_user_notification' ], 10, 3 ); + add_filter( 'gform_disable_post_creation_' . $this->form_id, [ $this, 'maybe_delay_post_creation' ], 10, 3 ); + add_filter( 'gform_disable_notification_' . $this->form_id, [ $this, 'maybe_delay_notification' ], 10, 4 ); // Confirmation (@see GFFormDisplay::handle_confirmation). // @link http://www.gravityhelp.com/documentation/page/Gform_confirmation. - add_filter( 'gform_confirmation_' . $this->form_id, array( $this, 'confirmation' ), 10, 4 ); + add_filter( 'gform_confirmation_' . $this->form_id, [ $this, 'confirmation' ], 10, 4 ); /* * After submission. */ - add_action( 'gform_after_submission_' . $this->form_id, array( $this, 'after_submission' ), 10, 2 ); + add_action( 'gform_after_submission_' . $this->form_id, [ $this, 'after_submission' ], 10, 2 ); - add_filter( 'gform_is_delayed_pre_process_feed_' . $this->form_id, array( $this, 'maybe_delay_feed' ), 10, 4 ); - add_filter( 'gravityflow_is_delayed_pre_process_workflow', array( $this, 'maybe_delay_workflow' ), 10, 3 ); + add_filter( 'gform_is_delayed_pre_process_feed_' . $this->form_id, [ $this, 'maybe_delay_feed' ], 10, 4 ); + add_filter( 'gravityflow_is_delayed_pre_process_workflow', [ $this, 'maybe_delay_workflow' ], 10, 3 ); } /** @@ -199,7 +199,7 @@ public function pre_submission( $form ) { $delayed_payment_integration = ( isset( $data['delayed_payment_integration'] ) && true === $data['delayed_payment_integration'] ); if ( isset( $data['addon'] ) && ! $delayed_payment_integration ) { - remove_filter( 'gform_entry_post_save', array( $data['addon'], 'maybe_process_feed' ), 10 ); + remove_filter( 'gform_entry_post_save', [ $data['addon'], 'maybe_process_feed' ], 10 ); } if ( isset( $data['delay_callback'] ) ) { @@ -338,7 +338,7 @@ public function entry_post_save( $lead, $form ) { foreach ( $products as $key => $product ) { $key = \strval( $key ); - $product_lines = array(); + $product_lines = []; $line = $payment->lines->new_line(); @@ -462,7 +462,7 @@ public function entry_post_save( $lead, $form ) { ( $payment->get_lines()->get_amount()->get_number()->is_zero() && $subscription_lines->get_amount()->get_number()->is_zero() ) ) { // Allow delayed feeds to be processed during fulfilment for free payments (e.g. user registration for entry with discount). - \remove_filter( 'gform_is_delayed_pre_process_feed_' . $this->form_id, array( $this, 'maybe_delay_feed' ), 10 ); + \remove_filter( 'gform_is_delayed_pre_process_feed_' . $this->form_id, [ $this, 'maybe_delay_feed' ], 10 ); $payment->set_status( PaymentStatus::SUCCESS ); $payment->save(); @@ -600,12 +600,12 @@ public function entry_post_save( $lead, $form ) { // Pending payment. if ( PaymentStatuses::PROCESSING === $lead[ LeadProperties::PAYMENT_STATUS ] ) { // Add pending payment. - $action = array( + $action = [ 'id' => $this->payment->get_id(), 'transaction_id' => $this->payment->get_transaction_id(), 'amount' => $this->payment->get_total_amount()->get_value(), 'entry_id' => $lead['id'], - ); + ]; $this->extension->payment_action( 'add_pending_payment', $lead, $action ); } @@ -794,7 +794,7 @@ public function confirmation( $confirmation, $form, $lead, $ajax ) { return $confirmation; } - $confirmation = array( 'redirect' => $this->payment->get_pay_redirect_url() ); + $confirmation = [ 'redirect' => $this->payment->get_pay_redirect_url() ]; if ( $this->error instanceof \Exception ) { $html = '