Admin
1 year 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
1 year ago
DonationFormElements.php
4 years ago
DonationFormSettingPage.php
4 years ago
ApplicationFee.php
66 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 2.10.2 |
| 60 | */ |
| 61 | public function doesCountrySupportApplicationFee(): bool |
| 62 | { |
| 63 | return 'BR' !== $this->accountDetail->accountCountry; |
| 64 | } |
| 65 | } |
| 66 |