Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Sep 26, 2022
2 parents dc42446 + 184d8c3 commit 5bd9c68
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 109 deletions.
13 changes: 13 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"core": null,
"plugins": [
".",
"../../../",
"https://downloads.wordpress.org/plugin/formidable.5.4.4.zip",
"https://downloads.wordpress.org/plugin/query-monitor.zip",
"https://downloads.wordpress.org/plugin/one-time-login.zip"
],
"config": {
"PRONAMIC_PAY_DEBUG": true
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [Unreleased][unreleased]
-

## [4.2.0] - 2022-09-26
- Updated for new payment methods and fields registration.

## [4.1.1] - 2022-08-15
- Fixed not showing error messages if form success action is not 'message'.

Expand Down Expand Up @@ -78,7 +81,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## 1.0.0 - 2015-11-05
- First release.

[unreleased]: https://github.com/pronamic/wp-pronamic-pay-formidable-forms/compare/4.1.1...HEAD
[unreleased]: https://github.com/pronamic/wp-pronamic-pay-formidable-forms/compare/4.2.0...HEAD
[4.2.0]: https://github.com/pronamic/wp-pronamic-pay-formidable-forms/compare/4.1.1...4.2.0
[4.1.1]: https://github.com/pronamic/wp-pronamic-pay-formidable-forms/compare/4.1.0...4.1.1
[4.1.0]: https://github.com/wp-pay-extensions/formidable-forms/compare/4.0.0...4.1.0
[4.0.0]: https://github.com/wp-pay-extensions/formidable-forms/compare/3.0.0...4.0.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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",
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formidable-forms",
"version": "4.1.1",
"version": "4.2.0",
"description": "Formidable Forms driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,6 +33,7 @@
},
"homepage": "http://www.wp-pay.org/extensions/formidable-forms/",
"devDependencies": {
"@wordpress/env": "^5.2.0",
"autoprefixer": "^10.2.1",
"grunt": "^1.3.0",
"grunt-contrib-compass": "^1.1.1",
Expand All @@ -46,5 +47,9 @@
"grunt-postcss": "^0.9.0",
"grunt-sass-lint": "^0.2.4",
"load-grunt-tasks": "^5.1.0"
},
"scripts": {
"start": "wp-env start",
"login": "wp-env run cli wp user one-time-login admin"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ parameters:
bootstrapFiles:
- tests/phpstan/bootstrap.php
scanDirectories:
- wp-content/formidable
- wp-content/plugins/formidable
paths:
- src/
41 changes: 41 additions & 0 deletions pronamic-pay-formidable-forms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Plugin Name: Pronamic Pay Formidable Forms Add-On
* Plugin URI: https://www.pronamic.eu/plugins/pronamic-pay-formidable-forms/
* Description: Extend the Pronamic Pay plugin with Formidable Forms support to receive payments through a variety of payment providers.
*
* Version: 4.1.0
* Requires at least: 4.7
*
* Author: Pronamic
* Author URI: https://www.pronamic.eu/
*
* Text Domain: pronamic-pay-formidable-forms
* Domain Path: /languages/
*
* License: GPL-3.0-or-later
*
* Depends: wp-pay/core
*
* GitHub URI: https://github.com/pronamic/wp-pronamic-pay-formidable-forms
*
* @author Pronamic <[email protected]>
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\Pay\Extensions\FormidableForms
*/

add_filter(
'pronamic_pay_plugin_integrations',
function ( $integrations ) {
foreach ( $integrations as $integration ) {
if ( $integration instanceof \Pronamic\WordPress\Pay\Extensions\FormidableForms\Extension ) {
return $integrations;
}
}

$integrations[] = new \Pronamic\WordPress\Pay\Extensions\FormidableForms\Extension();

return $integrations;
}
);
30 changes: 13 additions & 17 deletions src/BankSelectFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pronamic\WordPress\Pay\Extensions\FormidableForms;

use Pronamic\WordPress\Pay\Core\PaymentMethods;
use Pronamic\WordPress\Pay\Fields\IDealIssuerSelectField;
use Pronamic\WordPress\Pay\Plugin;
use Pronamic\WordPress\Pay\Util;

Expand Down Expand Up @@ -31,16 +32,16 @@ class BankSelectFieldType {
*/
public function __construct() {
// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/models/FrmField.php#L10-L23
add_filter( 'frm_available_fields', array( $this, 'available_fields' ) );
add_filter( 'frm_available_fields', [ $this, 'available_fields' ] );

// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/controllers/FrmFieldsController.php#L74
add_filter( 'frm_before_field_created', array( $this, 'before_field_created' ) );
add_filter( 'frm_before_field_created', [ $this, 'before_field_created' ] );

// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/views/frm-fields/show-build.php#L64
add_action( 'frm_display_added_fields', array( $this, 'display_added_fields' ) );
add_action( 'frm_display_added_fields', [ $this, 'display_added_fields' ] );

// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/views/frm-fields/input.php#L171
add_action( 'frm_form_fields', array( $this, 'form_fields' ) );
add_action( 'frm_form_fields', [ $this, 'form_fields' ] );
}

/**
Expand Down Expand Up @@ -127,25 +128,23 @@ private function render_field( $field ) {
return;
}

// Always use iDEAL payment method for issuer field.
$payment_method = $gateway->get_payment_method();
$issuer_field = $gateway->first_payment_method_field( PaymentMethods::IDEAL, IDealIssuerSelectField::class );

$gateway->set_payment_method( PaymentMethods::IDEAL );
if ( null === $issuer_field ) {
return;
}

try {
$issuer_field = $gateway->get_issuer_field();

$choices = $issuer_field['choices'];
$options = Util::select_options_grouped( $choices );

printf(
'<select name="%s" id="%s">',
esc_attr( sprintf( 'item_meta[%s]', $field['id'] ) ),
esc_attr( sprintf( 'field_%s', $field['field_key'] ) )
);

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $options;
foreach ( $issuer_field->get_options() as $option ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $option->render();
}

echo '</select>';
} catch ( \Exception $e ) {
Expand All @@ -155,8 +154,5 @@ private function render_field( $field ) {
esc_html( $e->getMessage() )
);
}

// Reset payment method to original value.
$gateway->set_payment_method( $payment_method );
}
}
57 changes: 26 additions & 31 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Extension extends AbstractPluginIntegration {
*/
public function __construct() {
parent::__construct(
array(
[
'name' => __( 'Formidable Forms', 'pronamic_ideal' ),
)
]
);

// Dependencies.
Expand All @@ -67,33 +67,33 @@ 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_payment_source_text_' . self::SLUG, [ $this, 'source_text' ], 10, 2 );
add_filter( 'pronamic_payment_source_description_' . self::SLUG, [ $this, 'source_description' ], 10, 2 );

// Check if dependencies are met and integration is active.
if ( ! $this->is_active() ) {
return;
}

add_action( 'pronamic_payment_status_update_' . self::SLUG, array( $this, 'update_status' ), 10, 2 );
add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( $this, 'source_url' ), 10, 2 );
add_action( 'pronamic_payment_status_update_' . self::SLUG, [ $this, 'update_status' ], 10, 2 );
add_filter( 'pronamic_payment_source_url_' . self::SLUG, [ $this, 'source_url' ], 10, 2 );

add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );

// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/controllers/FrmFormActionsController.php#L39-L57
// @link https://github.com/wp-premium/formidable-paypal/blob/3.02/controllers/FrmPaymentSettingsController.php#L11
add_action( 'frm_registered_form_actions', array( $this, 'registered_form_actions' ) );
add_action( 'frm_registered_form_actions', [ $this, 'registered_form_actions' ] );

// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/controllers/FrmFormActionsController.php#L299-L308
// @link https://github.com/wp-premium/formidable-paypal/blob/3.02/controllers/FrmPaymentsController.php#L28-L29
add_action( 'frm_trigger_pronamic_pay_create_action', array( $this, 'create_action' ), 10, 3 );
add_action( 'frm_trigger_pronamic_pay_create_action', [ $this, 'create_action' ], 10, 3 );

// @link https://github.com/wp-premium/formidable-paypal/blob/3.06/controllers/FrmPaymentSettingsController.php#L15-L19
add_filter( 'frm_action_triggers', array( $this, 'add_payment_trigger' ) );
add_filter( 'frm_email_action_options', array( $this, 'add_trigger_to_action' ) );
add_filter( 'frm_twilio_action_options', array( $this, 'add_trigger_to_action' ) );
add_filter( 'frm_mailchimp_action_options', array( $this, 'add_trigger_to_action' ) );
add_filter( 'frm_register_action_options', array( $this, 'add_payment_trigger_to_register_user_action' ) );
add_filter( 'frm_action_triggers', [ $this, 'add_payment_trigger' ] );
add_filter( 'frm_email_action_options', [ $this, 'add_trigger_to_action' ] );
add_filter( 'frm_twilio_action_options', [ $this, 'add_trigger_to_action' ] );
add_filter( 'frm_mailchimp_action_options', [ $this, 'add_trigger_to_action' ] );
add_filter( 'frm_register_action_options', [ $this, 'add_payment_trigger_to_register_user_action' ] );

// Field types.
$this->field_type_bank_select = new BankSelectFieldType();
Expand Down Expand Up @@ -121,14 +121,14 @@ public function admin_enqueue_scripts() {
wp_register_style(
'pronamic-pay-formidable-forms',
plugins_url( 'css/admin' . $min . '.css', dirname( __FILE__ ) ),
array(),
[],
'1.0.0'
);

wp_register_script(
'pronamic-pay-formidable-forms',
plugins_url( 'js/admin' . $min . '.js', dirname( __FILE__ ) ),
array( 'jquery' ),
[ 'jquery' ],
'1.0.0',
true
);
Expand Down Expand Up @@ -246,11 +246,11 @@ public static function source_text( $text, Payment $payment ) {
$text .= sprintf(
'<a href="%s">%s</a>',
add_query_arg(
array(
[
'page' => 'formidable-entries',
'frm_action' => 'show',
'id' => $payment->get_source_id(),
),
],
admin_url( 'admin.php' )
),
sprintf(
Expand Down Expand Up @@ -285,11 +285,11 @@ public function source_description( $description, Payment $payment ) {
*/
public function source_url( $url, Payment $payment ) {
$url = add_query_arg(
array(
[
'page' => 'formidable-entries',
'frm_action' => 'show',
'id' => $payment->get_source_id(),
),
],
admin_url( 'admin.php' )
);

Expand Down Expand Up @@ -332,13 +332,13 @@ public function create_action( $action, $entry, $form ) {

// @link https://github.com/wp-premium/formidable-paypal/blob/3.02/controllers/FrmPaymentsController.php#L268-L269
// @link https://github.com/wp-premium/formidable/blob/2.0.21/classes/models/FrmEntry.php#L698-L711
add_action( 'frm_after_create_entry', array( $this, 'redirect_for_payment' ), 50, 2 );
add_action( 'frm_after_create_entry', [ $this, 'redirect_for_payment' ], 50, 2 );

// Delay notifications.
if ( ! self::$send_email_now && isset( $action->post_content['pronamic_pay_delay_notifications'] ) && 'on' === $action->post_content['pronamic_pay_delay_notifications'] ) {
remove_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10 );
add_filter( 'frm_to_email', '__return_empty_array', 20 );
add_filter( 'frm_send_new_user_notification', array( __CLASS__, 'stop_registration_email' ), 10, 3 );
add_filter( 'frm_send_new_user_notification', [ __CLASS__, 'stop_registration_email' ], 10, 3 );
}
}

Expand Down Expand Up @@ -410,11 +410,6 @@ public function redirect_for_payment( $entry_id, $form_id ) {
$payment->set_payment_method( PaymentMethods::IDEAL );
}

// Check if gateway requires payment method.
if ( empty( $payment_method ) && $gateway->payment_method_is_required() ) {
$payment->set_payment_method( PaymentMethods::IDEAL );
}

// Issuer.
$payment->set_meta( 'issuer', FormidableFormsHelper::get_issuer_from_form_entry( $form_id, $entry ) );

Expand All @@ -433,9 +428,9 @@ public function redirect_for_payment( $entry_id, $form_id ) {
if ( wp_doing_ajax() ) {
// Do not use `wp_send_json_success()` as Formidable Forms doesn't properly handle the content type.
echo wp_json_encode(
array(
[
'redirect' => $payment->get_pay_redirect_url(),
)
]
);

exit;
Expand All @@ -462,7 +457,7 @@ function( $method, $form ) {
add_filter(
'frm_main_feedback',
function ( $message, $form, $entry_id ) use ( $e ) {
$atts = array(
$atts = [
'class' => FrmFormsHelper::form_error_class(),
'form' => $form,
'entry_id' => $entry_id,
Expand All @@ -471,7 +466,7 @@ function ( $message, $form, $entry_id ) use ( $e ) {
\esc_html( Plugin::get_default_error_message() ),
\esc_html( sprintf( '%s: %s', $e->getCode(), $e->getMessage() ) )
),
);
];

return FrmFormsHelper::get_success_message( $atts );
},
Expand Down
6 changes: 3 additions & 3 deletions src/FormidableFormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public static function get_payment_method_from_action_entry( $action, $entry ) {
if ( ! empty( $payment_method_field ) && isset( $entry->metas[ $payment_method_field ] ) ) {
$payment_method = $entry->metas[ $payment_method_field ];

$replacements = array(
$replacements = [
'pronamic_pay_' => '',
'pronamic_pay' => '',
);
];

$payment_method = strtr( $payment_method, $replacements );

Expand Down Expand Up @@ -171,7 +171,7 @@ public static function get_amount_from_field( $action, $entry ) {
$values = $entry->metas[ $amount_field ];

if ( ! \is_array( $values ) ) {
$values = array( $values );
$values = [ $values ];
}

// Add values to amount.
Expand Down
Loading

0 comments on commit 5bd9c68

Please sign in to comment.