Skip to content

Commit

Permalink
Merge branch 'hotfix/return-single-ip-7015' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
angelablake committed Oct 10, 2023
2 parents c13464c + 30f3c19 commit f90fbae
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion give.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private function setup_constants()
{
// Plugin version.
if (!defined('GIVE_VERSION')) {
define('GIVE_VERSION', '3.0.0');
define('GIVE_VERSION', '2.33.4');
}

// Plugin Root File.
Expand Down
11 changes: 4 additions & 7 deletions includes/gateways/stripe/includes/give-stripe-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* @license https://opensource.org/licenses/gpl-license GNU Public License
*/

use Give\Log\Log;
use Give\PaymentGateways\Exceptions\InvalidPropertyName;
use Give\PaymentGateways\Stripe\Models\AccountDetail;
use Give\PaymentGateways\Stripe\Repositories\Settings;
use Give\ValueObjects\Money;

Expand Down Expand Up @@ -1475,15 +1473,14 @@ function give_stripe_get_account_options() {
/**
* This function is used to get single ip address for Stripe.
*
* @since 2.7.0
* @since 2.7.0
*
* @return string
*
* @deprecated 2.33.5 Use give_get_ip method to get the single IP address.
*/
function give_stripe_get_ip_address() {

$ip_address_details = explode( ',', give_get_ip() );

return $ip_address_details[0];
return give_get_ip();
}

/**
Expand Down
41 changes: 26 additions & 15 deletions includes/misc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,51 @@ function give_get_timezone_id() {
*
* Returns the IP address of the current visitor
*
* @since 2.33.5 Add $single param.
* @since 1.0
*
* @return string $ip User's IP address
* @since 1.0
*/
function give_get_ip() {

$ip = '127.0.0.1';
function give_get_ip($single = true)
{
$ip_addresses = '127.0.0.1';
$header_type = '';

if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
// check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
$ip_addresses = $_SERVER['HTTP_CLIENT_IP'];
$header_type = 'HTTP_CLIENT_IP';
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
// to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip_addresses = $_SERVER['HTTP_X_FORWARDED_FOR'];
$header_type = 'HTTP_X_FORWARDED_FOR';
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = $_SERVER['REMOTE_ADDR'];
$ip_addresses = $_SERVER['REMOTE_ADDR'];
$header_type = 'REMOTE_ADDR';
}

/**
* Filter the IP
*
* @since 1.0
* @since 2.33.5 Add $single and $header_type params.
* @since 1.0
*/
$ip = apply_filters( 'give_get_ip', $ip );
$ip_addresses = apply_filters('give_get_ip', $ip_addresses, $single, $header_type);

// Filter empty values.
if ( false !== strpos( $ip, ',' ) ) {
$ip = give_clean( explode( ',', $ip ) );
$ip = array_filter( $ip );
$ip = implode( ',', $ip );
if (false !== strpos($ip_addresses, ',')) {
$ip_addresses = give_clean(explode(',', $ip_addresses));
$ip_addresses = array_filter($ip_addresses);
$ip_addresses = implode(',', $ip_addresses);
} else {
$ip = give_clean( $ip );
$ip_addresses = give_clean($ip_addresses);
}

return $ip;
if ($single && false !== strpos($ip_addresses, ',')) {
return explode(',', $ip_addresses)[0];
}

return $ip_addresses;
}


Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri
8. GiveWP has a dedicated support team to help answer any questions you may have and help you through stumbling blocks.

== Changelog ==
= 2.33.4: October 4th, 2023 =
* Fix: Update old sendwp buttons and remove unused Stripe disconnect function.

= 2.33.3: September 29th, 2023 =
* Fix: Multi-site installations no longer produce an error on subsites.

Expand Down
3 changes: 2 additions & 1 deletion src/PaymentGateways/Gateways/Stripe/BECSGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function getLegacyFormFieldMarkup(int $formId, array $args): string
}

/**
* @since 2.33.5 Use give_get_ip() instead of give_stripe_get_ip_address()
* @since 2.19.0
* @return array
*/
Expand All @@ -125,7 +126,7 @@ protected function getPaymentIntentArgs(): array
'customer_acceptance' => [
'type' => 'online',
'online' => [
'ip_address' => give_stripe_get_ip_address(),
'ip_address' => give_get_ip(),
'user_agent' => give_get_user_agent(),
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/PaymentGateways/Gateways/Stripe/SEPAGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function getLegacyFormFieldMarkup(int $formId, array $args): string
}

/**
* @since 2.33.5 Use give_get_ip() instead of give_stripe_get_ip_address()
* @since 2.19.0
* @return array
*/
Expand All @@ -127,7 +128,7 @@ protected function getPaymentIntentArgs(): array
'customer_acceptance' => [
'type' => 'online',
'online' => [
'ip_address' => give_stripe_get_ip_address(),
'ip_address' => give_get_ip(),
'user_agent' => give_get_user_agent(),
],
],
Expand Down

0 comments on commit f90fbae

Please sign in to comment.