AccountDetail.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe\Repositories; |
| 4 | |
| 5 | use Give\PaymentGateways\Stripe\Models\AccountDetail as AccountDetailModel; |
| 6 | |
| 7 | /** |
| 8 | * Class AccountDetail |
| 9 | * |
| 10 | * @package Give\PaymentGateways\Stripe\Repository |
| 11 | * @since 2.10.2 |
| 12 | */ |
| 13 | class AccountDetail { |
| 14 | /** |
| 15 | * Return Stripe account id for donation form. |
| 16 | * |
| 17 | * @since 2.10.2 |
| 18 | * @param int $formId |
| 19 | * |
| 20 | * @return AccountDetailModel |
| 21 | */ |
| 22 | public function getDonationFormStripeAccountId( $formId ) { |
| 23 | $formHasStripeAccount = give_is_setting_enabled( give_get_meta( $formId, 'give_stripe_per_form_accounts', true ) ); |
| 24 | if ( $formId > 0 && $formHasStripeAccount ) { |
| 25 | // Return default Stripe account of the form, if enabled. |
| 26 | $accountId = give_get_meta( $formId, '_give_stripe_default_account', true ); |
| 27 | } else { |
| 28 | // Global Stripe account. |
| 29 | $accountId = give_get_option( '_give_stripe_default_account', '' ); |
| 30 | } |
| 31 | |
| 32 | return $this->getAccountDetail( $accountId ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Get account detail by Stripe account id. |
| 37 | * |
| 38 | * @since 2.10.2 |
| 39 | * @param string $accountId |
| 40 | * |
| 41 | * @return AccountDetailModel |
| 42 | */ |
| 43 | public function getAccountDetail( $accountId ) { |
| 44 | $accountDetail = array_filter( |
| 45 | give_stripe_get_all_accounts(), |
| 46 | static function ( $data ) use ( $accountId ) { |
| 47 | return $data['account_id'] === $accountId; |
| 48 | } |
| 49 | ); |
| 50 | |
| 51 | $accountDetail = $accountDetail ? current( $accountDetail ) : $accountDetail; |
| 52 | return new AccountDetailModel( $accountDetail ); |
| 53 | } |
| 54 | } |
| 55 |