-
Notifications
You must be signed in to change notification settings - Fork 41
New sales API #2205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New sales API #2205
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
bf19f2e
New sales API (first commit_
Crabcyborg 295abc4
Add a new helper function to reduce code
Crabcyborg 60996bf
Add a new helper function to reduce code
Crabcyborg 0f2fd41
Optimize, update function
Crabcyborg faebd90
Add footer CTA to API
Crabcyborg aa766ed
Replace the menu link/text
Crabcyborg 3bde007
Also update the dashboard license box
Crabcyborg 5985f4b
Update strings in the license box
Crabcyborg 07efda9
Update another URL
Crabcyborg 8b965d3
Use best discount if higher than 50
Crabcyborg ce22f7f
Change case
Crabcyborg f91a23a
Check for A/B test groups
Crabcyborg 218d8e5
Remove die copde
Crabcyborg 0eff751
Run php cs fixer
Crabcyborg e000ed9
phpcs fixes
Crabcyborg 28f684f
Check starts timestamp as well and compare against New York time
Crabcyborg 93914e1
Remove more code that is not required
Crabcyborg 14c163b
Do not autoload the option
Crabcyborg 212146e
Re-use code in inbox code
Crabcyborg 4111ec1
phpcs fixes
Crabcyborg 05b3cb3
Add line break
Crabcyborg a127f8c
Fix broken php
Crabcyborg 0c9821e
Add a comment
Crabcyborg 50eb65b
Add missing var
Crabcyborg 8ab852a
Remove unused $for_parent constructor param
Crabcyborg d22d88e
Remove phpstan exception
Crabcyborg 9bb7318
Merge branch 'lite-to-pro-improvement' into new_sales_api
Crabcyborg 8df2e3e
Merge branch 'master' into new_sales_api
Crabcyborg 1fac935
Clear sales API when clearing caches, stop using hard coded test data
Crabcyborg 41da4cd
Merge branch 'master' into new_sales_api
Crabcyborg 616826c
Add a check for Psalm
Crabcyborg 8bb347a
Update sales API URL (use cloudflare worker)
Crabcyborg fd6524c
Add day in seconds to expires check to include the expires date
Crabcyborg 8c3a688
Also update the link in the plugins page
Crabcyborg 4c0189e
Merge branch 'master' into new_sales_api
Crabcyborg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <?php | ||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| die( 'You are not allowed to call this page directly.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| */ | ||
| class FrmApiHelper { | ||
|
|
||
| /** | ||
| * Check if an API item matches the current site license target. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param array $item Inbox or Sale item. | ||
| * @return bool | ||
| */ | ||
| public static function is_for_user( $item ) { | ||
| if ( ! isset( $item['who'] ) || $item['who'] === 'all' ) { | ||
| return true; | ||
| } | ||
| $who = (array) $item['who']; | ||
| if ( self::is_for_everyone( $who ) ) { | ||
| return true; | ||
| } | ||
| if ( self::is_user_type( $who ) ) { | ||
| return true; | ||
| } | ||
| if ( in_array( 'free_first_30', $who, true ) && self::is_free_first_30() ) { | ||
| return true; | ||
| } | ||
| if ( in_array( 'free_not_first_30', $who, true ) && self::is_free_not_first_30() ) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
Crabcyborg marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @param array $who | ||
| * @return bool | ||
| */ | ||
| private static function is_for_everyone( $who ) { | ||
| return in_array( 'all', $who, true ); | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @param array $who | ||
| * @return bool | ||
| */ | ||
| private static function is_user_type( $who ) { | ||
| return in_array( self::get_user_type(), $who, true ); | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @return string | ||
| */ | ||
| private static function get_user_type() { | ||
| if ( ! FrmAppHelper::pro_is_installed() ) { | ||
| return 'free'; | ||
| } | ||
|
|
||
| return FrmAddonsController::license_type(); | ||
| } | ||
|
|
||
| /** | ||
| * Check if user is still using the Lite version only, and within | ||
| * the first 30 days of activation. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function is_free_first_30() { | ||
| return self::is_free() && self::is_first_30(); | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function is_first_30() { | ||
| $activation_timestamp = get_option( 'frm_first_activation' ); | ||
| if ( false === $activation_timestamp ) { | ||
| // If the option does not exist, assume that it is | ||
| // because the user was active before this option was introduced. | ||
| return false; | ||
| } | ||
|
Crabcyborg marked this conversation as resolved.
|
||
| $cutoff = strtotime( '-30 days' ); | ||
| return $activation_timestamp > $cutoff; | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function is_free_not_first_30() { | ||
| return self::is_free() && ! self::is_first_30(); | ||
| } | ||
|
|
||
| /** | ||
| * Check if the Pro plugin is active. If not, consider the user to be on the free version. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function is_free() { | ||
| return ! FrmAppHelper::pro_is_included(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.