Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 78 additions & 3 deletions classes/controllers/FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.',
),
);
$addons = $pro + $addons;
$addons = $pro + self::get_built_in_addons() + $addons;
self::prepare_addons( $addons );

$pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
Expand All @@ -174,6 +174,74 @@
include $view_path . 'index.php';
}

/**
* Get the payment gateways that ship inside Lite so they render as active add-on cards.
*
* These are not installable plugins. The `built_in` flag gives them an active
* status, keeps them unlocked, and limits the card footer to the docs link.
*
* @since x.x
*
* @return array<string,array<string,mixed>>
*/
protected static function get_built_in_addons() {
return array(
'stripe-payments' => array(
'slug' => 'stripe-payments',
'title' => 'Stripe',
'built_in' => true,
'categories' => array( 'Ecommerce' ),
'docs' => 'knowledgebase/stripe/',
'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
),
'square-payments' => array(
'slug' => 'square-payments',
'title' => 'Square',
'built_in' => true,
'categories' => array( 'Ecommerce' ),
'docs' => 'knowledgebase/square/',
'excerpt' => 'Take one-time payments with Square, with support for Apple Pay and Google Pay.',
),
'paypal-commerce' => array(
'slug' => 'paypal-commerce',
'title' => 'PayPal Commerce',
'built_in' => true,
'categories' => array( 'Ecommerce' ),
'docs' => 'knowledgebase/formidable-paypal/',
'excerpt' => 'Collect instant payments and recurring payments with PayPal Commerce on any Formidable form.',
),
);
}

/**
* Override how an add-on is presented on the Add-Ons page.
*
* The built-in gateways cover base payment processing, so the add-ons that
* extend them are presented as their Pro/Legacy tiers until the API reflects
* it. Names only — the add-ons keep their original excerpts.
*
* @since x.x
*
* @param array $addon The addon array that will be modified by reference.
* @param string $slug The addon slug.
*
* @return void
*/
protected static function override_addon_display( &$addon, $slug ) {
$overrides = array(
'stripe' => array(
'display_name' => 'Stripe Pro',
),
'paypal-standard' => array(
'display_name' => 'PayPal Legacy',
),
);

if ( isset( $overrides[ $slug ] ) ) {
$addon = array_merge( $addon, $overrides[ $slug ] );
}
}

/**
* Organize and set categories.
*
Expand Down Expand Up @@ -899,6 +967,8 @@
}
}

self::override_addon_display( $addon, $slug );

$addon['installed'] = self::is_installed( $file_name );

if ( 'highrise' === $slug && ! $addon['installed'] ) {
Expand Down Expand Up @@ -1001,7 +1071,12 @@
* @return void
*/
protected static function set_addon_status( &$addon ) {
if ( ! empty( $addon['activate_url'] ) ) {
if ( ! empty( $addon['built_in'] ) ) {
$addon['status'] = array(
'type' => 'active',
'label' => __( 'Active', 'formidable' ),
);
} elseif ( ! empty( $addon['activate_url'] ) ) {
$addon['status'] = array(
'type' => 'installed',
'label' => __( 'Installed', 'formidable' ),
Expand All @@ -1016,7 +1091,7 @@
'type' => 'not-installed',
'label' => __( 'Not Installed', 'formidable' ),
);
}
}//end if
}

/**
Expand Down Expand Up @@ -1541,7 +1616,7 @@
* Button attributes.
*
* @type array $addon
* @type false|string $license_type

Check notice on line 1619 in classes/controllers/FrmAddonsController.php

View workflow job for this annotation

GitHub Actions / Mago

valid-docblock

Unexpected token in PHPDoc type This token cannot appear here, so the type or tag stops making sense at this point. Help: Remove the stray token, or fix the type or tag syntax leading up to it.
* @type string $plan_required
* @type string $upgrade_link
* }
Expand Down
26 changes: 26 additions & 0 deletions classes/helpers/FrmAddonsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class FrmAddonsHelper {
*/
private static $plan_required;

/**
* Whether the add-on being rendered is built into Lite (e.g. Stripe, Square, PayPal).
*
* @var bool
*/
private static $built_in = false;

/**
* Show the CTA to upgrade or renew.
*
Expand Down Expand Up @@ -170,8 +177,11 @@ public static function get_addon_icon( $slug ) {
'hubspot-wordpress' => 'hubspot',
'mailchimp' => 'mailchimp',
'mailpoet-newsletters' => 'mailpoet',
'paypal-commerce' => 'paypal',
'paypal-standard' => 'paypal',
'polylang' => 'polylang',
'square-payments' => 'square',
'stripe-payments' => 'stripe',
'salesforce' => 'salesforcealt',
'stripe' => 'stripealt',
'twilio' => 'twilio',
Expand Down Expand Up @@ -249,9 +259,24 @@ private static function prepare_single_addon_classes( $addon ) {
* @return bool
*/
public static function is_locked() {
if ( self::$built_in ) {
return false;
}

return self::$plan_required || ! FrmAppHelper::pro_is_installed();
}

/**
* Check if the add-on being rendered is built into Lite.
*
* @since x.x
*
* @return bool
*/
public static function is_built_in() {
return self::$built_in;
}

/**
* Set the required plan for the given addon.
*
Expand All @@ -267,6 +292,7 @@ public static function is_locked() {
*/
private static function set_plan_required( $addon ) {
self::$plan_required = FrmFormsHelper::get_plan_required( $addon );
self::$built_in = ! empty( $addon['built_in'] );
}

/**
Expand Down
49 changes: 37 additions & 12 deletions classes/views/addons/addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,40 @@
</span>
<?php
} else {
FrmAddonsController::show_conditional_action_button(
array(
'addon' => $addon,
'license_type' => ! empty( $license_type ) ? $license_type : false,
'plan_required' => 'plan_required',
'upgrade_link' => $pricing,
)
);
$toggle_classes = 'with_frm_style frm_toggle frm-ml-auto';

if ( FrmAddonsHelper::is_built_in() ) {
// The wrapper carries the layout class and explains the always-on toggle.
$toggle_classes = 'with_frm_style frm_toggle';
?>
<span class="frm-ml-auto frm_help" title="<?php esc_attr_e( 'This payment gateway is built into Formidable and is always on.', 'formidable' ); ?>">
<?php
} else {
FrmAddonsController::show_conditional_action_button(
array(
'addon' => $addon,
'license_type' => ! empty( $license_type ) ? $license_type : false,
'plan_required' => 'plan_required',
'upgrade_link' => $pricing,
)
);
}

FrmHtmlHelper::toggle(
'frm-' . $addon['slug'],
'frm-' . $addon['slug'],
array(
'div_class' => 'with_frm_style frm_toggle frm-ml-auto',
'div_class' => $toggle_classes,
'checked' => $addon['status']['type'] === 'active',
'disabled' => $addon['slug'] === 'formidable-pro',
'disabled' => $addon['slug'] === 'formidable-pro' || FrmAddonsHelper::is_built_in(),
'echo' => true,
'aria-label-attr' => $addon['title'],
)
);

if ( FrmAddonsHelper::is_built_in() ) {
echo '</span>';
}
}//end if
?>
</div>
Expand All @@ -72,7 +87,17 @@

<div class="frm-flex frm-items-center frm-justify-between">
<?php
if ( ! empty( $addon['docs'] ) && ! FrmAddonsHelper::get_plan() ) {
if ( FrmAddonsHelper::is_built_in() ) {
if ( ! empty( $addon['docs'] ) ) {
$docs_label = ! empty( $addon['docs_label'] ) ? $addon['docs_label'] : __( 'View Docs', 'formidable' );
?>
<a class="frm-link-with-external-icon" href="<?php echo esc_url( $addon['docs'] ); ?>" target="_blank" aria-label="<?php echo esc_attr( $docs_label ); ?>">
<?php echo esc_html( $docs_label ); ?>
<?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowup8_icon' ); ?>
</a>
<?php
}
} elseif ( ! empty( $addon['docs'] ) && ! FrmAddonsHelper::get_plan() ) {
$docs_label = ! empty( $addon['docs_label'] ) ? $addon['docs_label'] : __( 'View Docs', 'formidable' );
?>
<a class="frm-link-with-external-icon" href="<?php echo esc_url( $addon['docs'] ); ?>" target="_blank" aria-label="<?php echo esc_attr( $docs_label ); ?>">
Expand All @@ -87,7 +112,7 @@
<?php FrmAddonsController::addon_upgrade_link( $addon, $pricing ); ?>
</div>
<?php
}
}//end if
?>
</div>
</li>
2 changes: 1 addition & 1 deletion js/addons-page.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions js/src/addons-page/events/addonToggleListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const onAddonToggleClick = event => {
}

const addonToggle = event.currentTarget;

if ( addonToggle.querySelector( 'input[disabled]' ) ) {
return;
}

const addon = addonToggle.closest( '.frm-card-item' );

const actionMap = new Map( [
Expand Down
6 changes: 3 additions & 3 deletions tests/cypress/e2e/Add-Ons/validateAddOnsPage.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ describe( 'Add-Ons page', () => {
.and( 'include', 'https://formidableforms.com/lite-upgrade/' );
} );

cy.log( 'PayPal Standard card' );
cy.log( 'PayPal Legacy card' );
cy.get( 'li[data-slug="paypal-standard"]' ).within( () => {
cy.get( '.frm-font-medium.frm-truncate' ).should( 'contain.text', 'PayPal Standard' );
cy.get( '.frm-font-medium.frm-truncate' ).should( 'contain.text', 'PayPal Legacy' );
cy.get( 'svg.frmsvg > use' ).should( 'have.attr', 'href', '#frm_paypal_icon' );
cy.get( 'p.frm-line-clamp-2' ).should( 'contain.text', 'Collect instant payments and recurring payments to automate your online business. Calculate a total and send customers on to PayPal.' );
cy.contains( 'Plan required:' ).within( () => {
Expand Down Expand Up @@ -647,7 +647,7 @@ describe( 'Add-Ons page', () => {
it( 'should search for add-ons', () => {
cy.log( 'Search for valid add-ons by name' );
cy.get( '#addon-search-input' ).type( 'PayPal Standard' );
cy.get( '.plugin-card-paypal-standard' ).should( 'contain', 'PayPal Standard' );
cy.get( '.plugin-card-paypal-standard' ).should( 'contain', 'PayPal Legacy' );

cy.log( 'Search for valid add-ons by description' );
cy.get( '#addon-search-input' ).clear().type( 'Add an electronic signature to your WordPress form. The visitor may write their signature with a trackpad/mouse or type it.' );
Expand Down
Loading