ApplicationFee.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe; |
| 4 | |
| 5 | use Give_License; |
| 6 | |
| 7 | /** |
| 8 | * Class ApplicationFee |
| 9 | * @package Give\PaymentGateways\Stripe |
| 10 | * |
| 11 | * @see https://github.com/impress-org/givewp/issues/5555#issuecomment-759596226 |
| 12 | * |
| 13 | * @unreleased |
| 14 | */ |
| 15 | class ApplicationFee { |
| 16 | /** |
| 17 | * Slug of the Stripe add-on on GiveWP.com |
| 18 | */ |
| 19 | const PluginSlug = 'give-stripe'; |
| 20 | |
| 21 | /** |
| 22 | * Name of the Stripe add-on on GiveWP.com |
| 23 | */ |
| 24 | const PluginName = 'Give - Stripe Gateway'; |
| 25 | |
| 26 | /** |
| 27 | * Returns true or false based on whether the Stripe fee should be applied or not |
| 28 | * |
| 29 | * @unreleased |
| 30 | * |
| 31 | * @return bool |
| 32 | */ |
| 33 | public static function canAddFee() { |
| 34 | $gate = new static(); |
| 35 | |
| 36 | return ! ( $gate->hasLicense() |
| 37 | || $gate->isStripeProAddonActive() |
| 38 | || $gate->isStripeProAddonInstalled( get_plugins() ) ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns true or false based on whether the Stripe Pro add-on is activated |
| 43 | * |
| 44 | * @unreleased |
| 45 | * |
| 46 | * @return bool |
| 47 | */ |
| 48 | public function isStripeProAddonActive() { |
| 49 | return defined( 'GIVE_STRIPE_VERSION' ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns true or false based on whether the plugin is installed (but not necessarily active) |
| 54 | * |
| 55 | * @param array $plugins Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data(). |
| 56 | * |
| 57 | * @return bool |
| 58 | */ |
| 59 | public function isStripeProAddonInstalled( array $plugins ) { |
| 60 | return (bool) array_filter( |
| 61 | $plugins, |
| 62 | static function ( $plugin ) { |
| 63 | return static::PluginName === $plugin['Name']; |
| 64 | } |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns true or false based on whether a license has been provided for the Stripe add-on |
| 70 | * |
| 71 | * @unreleased |
| 72 | * |
| 73 | * @return bool |
| 74 | */ |
| 75 | public function hasLicense() { |
| 76 | return (bool) Give_License::get_license_by_plugin_dirname( static::PluginSlug ); |
| 77 | } |
| 78 | } |
| 79 |