| 1 |
<?php |
| 2 |
/** |
| 3 |
* Give - Stripe Core Admin Helper Functions. |
| 4 |
* |
| 5 |
* @since 2.5.4 |
| 6 |
* |
| 7 |
* @package Give |
| 8 |
* @subpackage Stripe Core |
| 9 |
* @copyright Copyright (c) 2019, GiveWP |
| 10 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit, if accessed directly. |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* This function is used to get a list of slug which are supported by payment gateways. |
| 21 |
* |
| 22 |
* @since 2.27.0 add filter for the array of supported stripe gateways. |
| 23 |
* @since 2.5.5 |
| 24 |
* |
| 25 |
* @return array |
| 26 |
*/ |
| 27 |
function give_stripe_supported_payment_methods() |
| 28 |
{ |
| 29 |
return apply_filters('give_stripe_supported_payment_methods', [ |
| 30 |
'stripe', |
| 31 |
'stripe_ach', |
| 32 |
'stripe_ideal', |
| 33 |
'stripe_google_pay', |
| 34 |
'stripe_apple_pay', |
| 35 |
'stripe_checkout', |
| 36 |
'stripe_sepa', |
| 37 |
'stripe_becs', |
| 38 |
]); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* This function is used to check whether a payment method supported by Stripe with Give is active or not. |
| 43 |
* |
| 44 |
* @since 2.5.5 |
| 45 |
* |
| 46 |
* @return bool |
| 47 |
*/ |
| 48 |
function give_stripe_is_any_payment_method_active() |
| 49 |
{ |
| 50 |
$settings = give_get_settings(); |
| 51 |
$gateways = $settings['gateways'] ?? []; |
| 52 |
$stripePaymentMethods = give_stripe_supported_payment_methods(); |
| 53 |
|
| 54 |
$active = false; |
| 55 |
foreach (array_keys($gateways) as $gateway) { |
| 56 |
// Return true, if even single payment method is active. |
| 57 |
if ( in_array( $gateway, $stripePaymentMethods, true ) ) { |
| 58 |
$active = true; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @since 3.0.0 |
| 64 |
*/ |
| 65 |
return apply_filters('give_stripe_is_any_payment_method_active', $active, $gateways, $stripePaymentMethods); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* This helper function is used to convert slug into name of Stripe connection. |
| 70 |
* |
| 71 |
* @param string $slug Connection Type Slug. |
| 72 |
* |
| 73 |
* @since 2.7.0 |
| 74 |
* |
| 75 |
* @return string |
| 76 |
*/ |
| 77 |
function give_stripe_connection_type_name( $slug = 'connect' ) { |
| 78 |
$names = [ |
| 79 |
'manual' => esc_html__( 'API Keys', 'give' ), |
| 80 |
'connect' => esc_html__( 'Stripe Connect', 'give' ), |
| 81 |
]; |
| 82 |
|
| 83 |
return $names[ $slug ]; |
| 84 |
} |
| 85 |
|