Admin
11 months 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
11 months ago
DonationFormElements.php
4 years ago
DonationFormSettingPage.php
4 years ago
ApplicationFee.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe; |
| 4 | |
| 5 | use Give\License\Repositories\LicenseRepository; |
| 6 | use Give\PaymentGateways\Stripe\Models\AccountDetail as AccountDetailModel; |
| 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 | * @since 2.10.2 |
| 20 | */ |
| 21 | protected AccountDetailModel $accountDetail; |
| 22 | |
| 23 | /** |
| 24 | * @since 4.3.0 |
| 25 | */ |
| 26 | protected LicenseRepository $licenseRepository; |
| 27 | |
| 28 | /** |
| 29 | * @since 4.3.0 added LicenseRepository |
| 30 | * @since 2.10.2 |
| 31 | */ |
| 32 | public function __construct(AccountDetailModel $accountDetail) |
| 33 | { |
| 34 | $this->accountDetail = $accountDetail; |
| 35 | $this->licenseRepository = give(LicenseRepository::class); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns true or false based on whether the Stripe fee should be applied or not |
| 40 | * |
| 41 | * @since 4.3.0 updated logic to check license for gateway fee |
| 42 | * @since 2.10.2 |
| 43 | */ |
| 44 | public static function canAddFee(): bool |
| 45 | { |
| 46 | /* @var self $gate */ |
| 47 | $gate = give(static::class); |
| 48 | |
| 49 | if (!$gate->doesCountrySupportApplicationFee()) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | return $gate->licenseRepository->hasPlatformFeePercentage(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Return whether country support application fee. |
| 58 | * |
| 59 | * @since 4.5.0 Add India, Malaysia, Mexico, Singapore, Thailand to the list of unsupported countries |
| 60 | * @since 2.10.2 |
| 61 | */ |
| 62 | public function doesCountrySupportApplicationFee(): bool |
| 63 | { |
| 64 | $unsupportedCountries = [ |
| 65 | 'BR', // Brazil |
| 66 | 'IN', // India |
| 67 | 'MY', // Malaysia |
| 68 | 'MX', // Mexico |
| 69 | 'SG', // Singapore |
| 70 | 'TH', // Thailand |
| 71 | ]; |
| 72 | |
| 73 | return !in_array($this->accountDetail->accountCountry, $unsupportedCountries); |
| 74 | } |
| 75 | } |
| 76 |