| 1 |
<?php |
| 2 |
/** |
| 3 |
* Stripe Connect helper functions. |
| 4 |
* |
| 5 |
* @package Charitable Stripe/Functions/Connect |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2021-2022, David Bisset |
| 8 |
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License |
| 9 |
* @since 1.4.0 |
| 10 |
* @version 1.4.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Returns the connected Stripe account id for a campaign. |
| 20 |
* |
| 21 |
* @since 1.4.0 |
| 22 |
* |
| 23 |
* @param int $campaign_id The campaign id. |
| 24 |
* @return string|false Returns account id if one is connected and Charitable |
| 25 |
* Stripe Connect is active. Otherwise, returns false. |
| 26 |
*/ |
| 27 |
function charitable_stripe_get_connected_account_for_campaign( $campaign_id ) { |
| 28 |
if ( ! class_exists( 'Charitable_Stripe_Connect' ) ) { |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
$connected_user_id = get_post_meta( $campaign_id, '_campaign_stripe_connect_user_id', true ); |
| 33 |
|
| 34 |
if ( ! $connected_user_id ) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
$stripe_user = new Charitable_Stripe_Connect_User( $connected_user_id ); |
| 39 |
$connected_account = $stripe_user->get( 'stripe_user_id' ); |
| 40 |
|
| 41 |
/* We don't have an access token for the user, so we're just going to send the funds to the platform. */ |
| 42 |
if ( ! $connected_account || ! $stripe_user->is_token_valid_for_current_mode() ) { |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
return $connected_account; |
| 47 |
} |