Skip to content
Merged
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
2 changes: 1 addition & 1 deletion classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FrmAppHelper {
*
* @var int
*/
public static $db_version = 103;
public static $db_version = 104;

/**
* Used by the API add-on.
Expand Down
20 changes: 19 additions & 1 deletion classes/models/FrmMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private function migrate_data( $old_db_version ) {
return;
}

$migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 );
$migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
foreach ( $migrations as $migration ) {
if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
$function_name = 'migrate_to_' . $migration;
Expand Down Expand Up @@ -395,6 +395,24 @@ public function uninstall() {
return true;
}

/**
* In older versions of Lite, it's possible we've saved the wrong location ID.
* So force it to get valid values again.
*
* @since x.x
Comment thread
Crabcyborg marked this conversation as resolved.
*
* @return void
*/
private function migrate_to_104() {
if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
}

if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
}
}
Comment thread
Crabcyborg marked this conversation as resolved.

/**
* Disables summary email for multisite (not the main site) if recipient setting isn't changed.
*
Expand Down
38 changes: 26 additions & 12 deletions square/helpers/FrmSquareLiteConnectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private static function get_mode_value() {
}

/**
* @param string $mode
* @param string $mode either 'auto', 'live', or 'test'.
* @return bool|string
*/
public static function get_merchant_id( $mode = 'auto' ) {
Expand All @@ -376,6 +376,7 @@ private static function get_location_id_option_name( $mode = 'auto' ) {
}

/**
* @param string $mode either 'auto', 'live', or 'test'.
* @return string
*/
private static function get_merchant_currency_option_name( $mode = 'auto' ) {
Expand Down Expand Up @@ -450,8 +451,8 @@ private static function check_server_for_oauth_merchant_id() {
if ( is_object( $data ) && ! empty( $data->merchant_id ) ) {
update_option( self::get_merchant_id_option_name( $mode ), $data->merchant_id, 'no' );

$currency = self::get_merchant_currency( true );
$location_id = self::get_location_id( true );
$currency = self::get_merchant_currency( true, $mode );
$location_id = self::get_location_id( true, $mode );

if ( $currency ) {
update_option( self::get_merchant_currency_option_name( $mode ), $currency, 'no' );
Expand Down Expand Up @@ -547,17 +548,23 @@ public static function create_subscription( $info ) {
* @param bool $force
* @return false|string
*/
public static function get_location_id( $force = false ) {
public static function get_location_id( $force = false, $mode = 'auto' ) {
if ( ! $force ) {
$location_id = get_option( self::get_location_id_option_name() );
$location_id = get_option( self::get_location_id_option_name( $mode ) );
if ( $location_id ) {
return $location_id;
}
}

$response = self::post_with_authenticated_body( 'get_location_id' );
$request_body = array();
if ( 'auto' !== $mode ) {
$_POST['testMode'] = 'test' === $mode ? 1 : 0;
$request_body['frm_square_api_mode'] = $mode;
}

$response = self::post_with_authenticated_body( 'get_location_id', $request_body );
if ( is_object( $response ) ) {
update_option( self::get_location_id_option_name(), $response->id, 'no' );
update_option( self::get_location_id_option_name( $mode ), $response->id, 'no' );
return $response->id;
}

Expand Down Expand Up @@ -650,20 +657,27 @@ public static function reset_square_api_integration() {
}

/**
* @param bool $force
* @param bool $force
* @param string $mode
* @return false|string
*/
public static function get_merchant_currency( $force = false ) {
public static function get_merchant_currency( $force = false, $mode = 'auto' ) {
if ( ! $force ) {
$currency = get_option( self::get_merchant_currency_option_name() );
$currency = get_option( self::get_merchant_currency_option_name( $mode ) );
if ( $currency ) {
return $currency;
}
}

$response = self::post_with_authenticated_body( 'get_merchant_currency' );
$request_body = array();
if ( 'auto' !== $mode ) {
$_POST['testMode'] = 'test' === $mode ? 1 : 0;
$request_body['frm_square_api_mode'] = $mode;
}

$response = self::post_with_authenticated_body( 'get_merchant_currency', $request_body );
if ( is_object( $response ) && ! empty( $response->currency ) ) {
update_option( self::get_merchant_currency_option_name(), $response->currency, 'no' );
update_option( self::get_merchant_currency_option_name( $mode ), $response->currency, 'no' );
return $response->currency;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/Forms/formPageDataValidation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe( 'Forms page', () => {
const text = $el.text().trim();
const href = $el.attr( 'href' );

if ( href && ( text.includes( 'upgrading to PRO' ) || text.includes( 'Get 60% Off Pro!' ) || text.includes( 'Get the Deal' ) || text.match( /GET \d+% OFF|SAVE \d+%/ ) ) ) {
if ( href && ( text.includes( 'upgrading to PRO' ) || text.includes( 'Get 60% Off Pro!' ) || text.includes( 'Get the Deal' ) || text.match( /GET \d+% OFF|SAVE \d+%/ ) || text.includes( 'upgrading for 60% off during our No Brainer Sale!' ) ) ) {
cy.origin( 'https://formidableforms.com', { args: { href } }, ( { href } ) => {
cy.visit( href );
cy.get( 'h1' ).should( $h1 => {
Expand Down