Admin
3 years ago
Controllers
2 years ago
DataTransferObjects
3 years ago
Exceptions
4 years ago
Models
3 years ago
Repositories
4 years ago
Traits
4 years ago
ApplicationFee.php
4 years ago
DonationFormElements.php
4 years ago
DonationFormSettingPage.php
4 years ago
ApplicationFee.php
113 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe; |
| 4 | |
| 5 | use Give\PaymentGateways\Stripe\Models\AccountDetail as AccountDetailModel; |
| 6 | use Give_License; |
| 7 | |
| 8 | /** |
| 9 | * Class ApplicationFee |
| 10 | * @package Give\PaymentGateways\Stripe |
| 11 | * |
| 12 | * @see https://github.com/impress-org/givewp/issues/5555#issuecomment-759596226 |
| 13 | * |
| 14 | * @since 2.10.2 |
| 15 | */ |
| 16 | class ApplicationFee |
| 17 | { |
| 18 | /** |
| 19 | * Slug of the Stripe add-on on GiveWP.com |
| 20 | */ |
| 21 | const PluginSlug = 'give-stripe'; |
| 22 | |
| 23 | /** |
| 24 | * Name of the Stripe add-on on GiveWP.com |
| 25 | */ |
| 26 | const PluginName = 'Give - Stripe Gateway'; |
| 27 | |
| 28 | /** |
| 29 | * @var AccountDetailModel |
| 30 | */ |
| 31 | private $accountDetail; |
| 32 | |
| 33 | /** |
| 34 | * ApplicationFee constructor. |
| 35 | * |
| 36 | * @param AccountDetailModel $accountDetail |
| 37 | */ |
| 38 | public function __construct(AccountDetailModel $accountDetail) |
| 39 | { |
| 40 | $this->accountDetail = $accountDetail; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns true or false based on whether the Stripe fee should be applied or not |
| 45 | * |
| 46 | * @since 2.10.2 |
| 47 | * @return bool |
| 48 | */ |
| 49 | public static function canAddFee() |
| 50 | { |
| 51 | /* @var self $gate */ |
| 52 | $gate = give(static::class); |
| 53 | |
| 54 | return $gate->doesCountrySupportApplicationFee() |
| 55 | && ! ($gate->isStripeProAddonActive() || $gate->isStripeProAddonInstalled( |
| 56 | get_plugins() |
| 57 | ) || $gate->hasLicense()); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns true or false based on whether the Stripe Pro add-on is activated |
| 62 | * |
| 63 | * @since 2.10.2 |
| 64 | * |
| 65 | * @return bool |
| 66 | */ |
| 67 | public function isStripeProAddonActive() |
| 68 | { |
| 69 | return defined('GIVE_STRIPE_VERSION'); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Returns true or false based on whether the plugin is installed (but not necessarily active) |
| 74 | * |
| 75 | * @param array $plugins Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data(). |
| 76 | * |
| 77 | * @return bool |
| 78 | */ |
| 79 | public function isStripeProAddonInstalled(array $plugins) |
| 80 | { |
| 81 | return (bool)array_filter( |
| 82 | $plugins, |
| 83 | static function ($plugin) { |
| 84 | return static::PluginName === $plugin['Name']; |
| 85 | } |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns true or false based on whether a license has been provided for the Stripe add-on |
| 91 | * |
| 92 | * @since 2.10.2 |
| 93 | * |
| 94 | * @return bool |
| 95 | */ |
| 96 | public function hasLicense() |
| 97 | { |
| 98 | return (bool)Give_License::get_license_by_plugin_dirname(static::PluginSlug); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Return whether or not country support application fee. |
| 103 | * |
| 104 | * @since 2.10.2 |
| 105 | * |
| 106 | * @return bool |
| 107 | */ |
| 108 | public function doesCountrySupportApplicationFee() |
| 109 | { |
| 110 | return 'BR' !== $this->accountDetail->accountCountry; |
| 111 | } |
| 112 | } |
| 113 |