8889841cDonationFormSettingPage.php 0000644 00000004511 15051455662 0012021 0 ustar 00 canRegisterTab()) { return $settings; } $settings['stripe_form_account_options'] = [ 'id' => 'stripe_form_account_options', 'title' => esc_html__('Stripe Account', 'give'), 'icon-html' => '', 'fields' => $this->getMainSettingFields($formId), ]; return $settings; } /** * @since 2.13.0 * * @param int $formId * * @return array[] */ private function getMainSettingFields($formId) { $formAccount = give_is_setting_enabled( give_get_meta( $formId, 'give_stripe_per_form_accounts', true ) ); return [ [ 'id' => 'give_stripe_per_form_accounts', 'type' => 'give_stripe_per_form_accounts', 'callback' => [give(CustomizeAccountField::class), 'handle'], 'default' => CustomizeAccountField::DEFAULT_VALUE, ], [ 'id' => 'give_manage_accounts', 'type' => 'give_manage_accounts', 'callback' => [give(AccountManagerSettingField::class), 'handle'], 'wrapper_class' => $formAccount ? 'give-stripe-manage-account-options' : 'give-stripe-manage-account-options give-hidden', ], [ 'name' => 'donation_stripe_per_form_docs', 'type' => 'docs_link', 'url' => 'http://docs.givewp.com/stripe-free', 'title' => esc_html__('Stripe Documentation', 'give'), ], ]; } /** * @since 2.13.0 * @return bool */ private function canRegisterTab() { return give_stripe_is_any_payment_method_active(); } } Admin/AccountManagerSettingField.php 0000644 00000064636 15051455662 0013526 0 ustar 00 accountDetailRepository = $accountDetailRepository; $this->settings = $settings; $this->connectClient = $connectClient; } /** * @since 2.13.0 */ private function setUpProperties() { global $post; $this->stripeAccounts = $this->settings->getAllStripeAccounts(); $this->defaultStripeAccountSlug = $this->isGlobalSettingPage() ? $this->settings->getDefaultStripeAccountSlug() : $this->settings->getDefaultStripeAccountSlugForDonationForm($post->ID); } /** * Render Stripe account manager setting field. * * @since 2.13.0 * * @param array $field */ public function handle($field) { $this->setUpProperties(); $classes = ! empty($field['wrapper_class']) ? esc_attr($field['wrapper_class']) : '' ?>
canShowFreeStripeVersionNotice()) { $this->getFreeStripeVersionNoticeMarkup(); } ?>
Stripe add-on and never applies to subscription donations made through the Recurring Donations add-on. Learn More >', 'give' ), esc_url('http://docs.givewp.com/settings-stripe-addon'), esc_url('http://docs.givewp.com/settings-stripe-recurring'), esc_url('http://docs.givewp.com/settings-stripe-free') ); ?>
isGlobalSettingPage() ? esc_html__('Connect an account to get started!', 'give') : esc_html__( 'Add a new account to customize the Stripe account used for this donation form.', 'give' ) ?>
getStripeConnectButtonMarkup(); ?>isGlobalSettingPage() ? esc_html__('All payments go to the default account', 'give') : esc_html__('Stripe donations process through the account set above', 'give'); ?>
isGlobalSettingPage() ? esc_html__( 'You can set this globally (for all donation forms) or override the Stripe account per donation form.', 'give' ) : esc_html__('This overrides the global default account setting for this donation form.', 'give'); ?>
< > \ \' " *
.',
'give'
)
);
}
}
/**
* Return filtered statement descriptor.
* This function should be used to filter statement description
* which was storing in stripe_statement_descriptor give setting prior to Giver 2.19.
*
* @since 2.19.1
* @deprecated
*
* @param string $text
*
* @return false|string
*/
protected function filterOldStatementDescriptor($text)
{
$statementDescriptor = trim($text);
$unsupportedCharacters = ['<', '>', '"', '\''];
$statementDescriptor = str_replace($unsupportedCharacters, '', $statementDescriptor);
return substr($statementDescriptor, 0, 22);
}
}
Exceptions/StripeAccountAlreadyConnected.php 0000644 00000000435 15051455662 0015321 0 ustar 00 settingsRepository = $settingsRepository;
}
/**
* @since 2.13.0
*/
public function __invoke()
{
$this->validateRequest();
$requestData = SetDefaultStripeAccountDto::fromArray(give_clean($_POST));
try {
if ($requestData->formId) {
$this->settingsRepository
->setDefaultStripeAccountSlugForDonationForm(
$requestData->formId,
$requestData->accountSlug
);
give()->form_meta->update_meta(
$requestData->formId,
'give_stripe_per_form_accounts',
'enabled'
);
wp_send_json_success();
}
$this->settingsRepository->setDefaultGlobalStripeAccountSlug($requestData->accountSlug);
wp_send_json_success();
} catch (\Exception $e) {
wp_send_json_error(
[
'error' => $e->getMessage(),
]
);
}
}
/**
* @since 2.13.0
*/
private function validateRequest()
{
if ( ! current_user_can('manage_give_settings')) {
die();
}
}
}
Controllers/DisconnectStripeAccountController.php 0000644 00000002122 15051455662 0016432 0 ustar 00 validateRequest();
$requestedData = DisconnectStripeAccountDto::fromArray(give_clean($_GET));
$this->securityCheck($requestedData->accountSlug);
give_stripe_disconnect_account($requestedData->accountSlug);
wp_send_json_success();
}
/**
* @since 2.13.0
*/
private function validateRequest()
{
if ( ! current_user_can('manage_give_settings')) {
die();
}
}
/**
* @since 2.13.0
*
* @param $accountSlug
*/
private function securityCheck($accountSlug)
{
if ( ! check_admin_referer('give_disconnect_connected_stripe_account_' . $accountSlug)) {
die();
}
}
}
Controllers/NewStripeAccountOnBoardingController.php 0000644 00000012165 15051455662 0017045 0 ustar 00 settings = $settings;
}
/**
* @since 2.13.0
*/
public function __invoke()
{
if (!current_user_can('manage_give_settings')) {
return;
}
$requestedData = NewStripeAccountOnBoardingDto::fromArray(give_clean($_GET));
if (!$requestedData->hasValidateData()) {
return;
}
$stripe_accounts = give_stripe_get_all_accounts();
$secret_key = !give_is_test_mode() ? $requestedData->stripeAccessToken : $requestedData->stripeAccessTokenTest;
Stripe::setApiKey($secret_key);
// Get Account Details.
$account_details = give_stripe_get_account_details($requestedData->stripeUserId);
// Setup Account Details for Connected Stripe Accounts.
if (empty($account_details->id)) {
Give_Admin_Settings::add_error(
'give-stripe-account-id-fetching-error',
sprintf(
'%1$s %2$s',
esc_html__('Stripe Error:', 'give'),
esc_html__(
'We are unable to connect your Stripe account. Please contact the support team for assistance.',
'give'
)
)
);
return;
}
$account_name = !empty($account_details->business_profile->name) ?
$account_details->business_profile->name :
$account_details->settings->dashboard->display_name;
$account_slug = $account_details->id;
$account_email = $account_details->email;
$account_country = $account_details->country;
// Set first Stripe account as default.
if (!$stripe_accounts) {
give_update_option('_give_stripe_default_account', $account_slug);
}
try {
$accountDetailModel = AccountDetailModel::fromArray(
[
'type' => 'connect',
'account_name' => $account_name,
'account_slug' => $account_slug,
'account_email' => $account_email,
'account_country' => $account_country,
'account_id' => $requestedData->stripeUserId,
'live_secret_key' => $requestedData->stripeAccessToken,
'test_secret_key' => $requestedData->stripeAccessTokenTest,
'live_publishable_key' => $requestedData->stripePublishableKey,
'test_publishable_key' => $requestedData->stripePublishableKeyTest,
'statement_descriptor' => $account_details->settings->payments->statement_descriptor,
]
);
$this->settings->addNewStripeAccount($accountDetailModel);
if ($requestedData->formId) {
if (!Settings::getDefaultStripeAccountSlugForDonationForm($requestedData->formId)) {
Settings::setDefaultStripeAccountSlugForDonationForm(
$requestedData->formId,
$accountDetailModel->accountSlug
);
}
give()->form_meta->update_meta(
$requestedData->formId,
'give_stripe_per_form_accounts',
'enabled'
);
}
wp_redirect(
esc_url_raw(
add_query_arg(
['stripe_account' => 'connected'],
$requestedData->formId ?
admin_url(
"post.php?post=$requestedData->formId&action=edit&give_tab=stripe_form_account_options"
) :
admin_url(
'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=stripe-settings'
)
)
)
);
exit();
} catch (\Exception $e) {
Give_Admin_Settings::add_error(
'give-stripe-account-on-boarding-error',
sprintf(
'%1$s %2$s',
esc_html__('Stripe Error:', 'give'),
esc_html__(
'We are unable to connect your Stripe account. Please contact the support team for assistance.',
'give'
)
)
);
return;
}
}
}
Controllers/GetStripeAccountDetailsController.php 0000644 00000002706 15051455662 0016376 0 ustar 00 accountDetailServiceProvider = $accountDetailServiceProvider;
}
/**
* @since 2.13.3
*/
public function __invoke()
{
$this->validateRequest();
$requestedData = GetStripeAccountDetailsDto::fromArray(give_clean($_POST));
try {
wp_send_json_success(
$this->accountDetailServiceProvider
->getAccountDetailBySlug($requestedData->accountSlug)
->toArray()
);
} catch (InvalidArgumentException $e) {
wp_send_json_error();
}
}
/**
* @since 2.13.0
*/
private function validateRequest()
{
if ( ! current_user_can('manage_give_settings')) {
die();
}
}
}
DataTransferObjects/SetDefaultStripeAccountDto.php 0000644 00000001322 15051455662 0016367 0 ustar 00 accountSlug = ! empty($array['account_slug']) ? $array['account_slug'] : '';
$self->formId = ! empty($array['form_id']) ? absint($array['form_id']) : '';
return $self;
}
}
DataTransferObjects/GetStripeAccountDetailsDto.php 0000644 00000001126 15051455662 0016356 0 ustar 00 accountSlug = ! empty($array['account_slug']) ? $array['account_slug'] : '';
return $self;
}
}
DataTransferObjects/NewStripeAccountOnBoardingDto.php 0000644 00000003703 15051455662 0017030 0 ustar 00 formId = ! empty($array['post']) ? absint($array['post']) : 0;
$self->stripePublishableKey = ! empty($array['stripe_publishable_key']) ? $array['stripe_publishable_key'] : '';
$self->stripePublishableKeyTest = ! empty($array['stripe_publishable_key_test']) ? $array['stripe_publishable_key_test'] : '';
$self->stripeUserId = ! empty($array['stripe_user_id']) ? $array['stripe_user_id'] : '';
$self->stripeAccessToken = ! empty($array['stripe_access_token']) ? $array['stripe_access_token'] : '';
$self->stripeAccessTokenTest = ! empty($array['stripe_access_token_test']) ? $array['stripe_access_token_test'] : '';
$self->isConnected = ! empty($array['connected']) && absint($array['connected']);
return $self;
}
/**
* @since 2.13.0
* @return bool
*/
public function hasValidateData()
{
return $this->stripePublishableKey &&
$this->stripeUserId &&
$this->stripeAccessToken &&
$this->stripeAccessTokenTest &&
$this->isConnected;
}
}
DataTransferObjects/DisconnectStripeAccountDto.php 0000644 00000001364 15051455662 0016426 0 ustar 00 accountType = ! empty($array['account_type']) ? $array['account_type'] : '';
$self->accountSlug = ! empty($array['account_slug']) ? $array['account_slug'] : '';
return $self;
}
}
ApplicationFee.php 0000644 00000005212 15051455662 0010151 0 ustar 00 accountDetail = $accountDetail;
}
/**
* Returns true or false based on whether the Stripe fee should be applied or not
*
* @since 2.10.2
* @return bool
*/
public static function canAddFee()
{
/* @var self $gate */
$gate = give(static::class);
return $gate->doesCountrySupportApplicationFee()
&& ! ($gate->isStripeProAddonActive() || $gate->isStripeProAddonInstalled(
get_plugins()
) || $gate->hasLicense());
}
/**
* Returns true or false based on whether the Stripe Pro add-on is activated
*
* @since 2.10.2
*
* @return bool
*/
public function isStripeProAddonActive()
{
return defined('GIVE_STRIPE_VERSION');
}
/**
* Returns true or false based on whether the plugin is installed (but not necessarily active)
*
* @param array $plugins Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data().
*
* @return bool
*/
public function isStripeProAddonInstalled(array $plugins)
{
return (bool)array_filter(
$plugins,
static function ($plugin) {
return static::PluginName === $plugin['Name'];
}
);
}
/**
* Returns true or false based on whether a license has been provided for the Stripe add-on
*
* @since 2.10.2
*
* @return bool
*/
public function hasLicense()
{
return (bool)Give_License::get_license_by_plugin_dirname(static::PluginSlug);
}
/**
* Return whether or not country support application fee.
*
* @since 2.10.2
*
* @return bool
*/
public function doesCountrySupportApplicationFee()
{
return 'BR' !== $this->accountDetail->accountCountry;
}
}
DonationFormElements.php 0000644 00000001201 15051455662 0011354 0 ustar 00