Skip to content

Commit

Permalink
fix: paymentMethod fields no longer throw for guest users (#809)
Browse files Browse the repository at this point in the history
* fix: paymentMethod fields no longer throw for guest users

* chore: CollectionStatsQueryTest reverted
  • Loading branch information
kidunot89 authored Oct 5, 2023
1 parent 966ab37 commit d0db73a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions includes/type/object/class-customer-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public static function register() {
return array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) );
}

if ( get_current_user_id() === 0 ) {
return [];
}

throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) );
},
],
Expand All @@ -244,6 +248,10 @@ static function ( $token ) {
);
}

if ( get_current_user_id() === 0 ) {
return [];
}

throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) );
},
],
Expand All @@ -260,6 +268,10 @@ static function ( $token ) {
);
}

if ( get_current_user_id() === 0 ) {
return [];
}

throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) );
},
],
Expand Down
13 changes: 12 additions & 1 deletion vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;

class BeforeValidException extends \UnexpectedValueException
class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
{
private object $payload;

public function setPayload(object $payload): void
{
$this->payload = $payload;
}

public function getPayload(): object
{
return $this->payload;
}
}
13 changes: 12 additions & 1 deletion vendor-prefixed/firebase/php-jwt/src/ExpiredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;

class ExpiredException extends \UnexpectedValueException
class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
{
private object $payload;

public function setPayload(object $payload): void
{
$this->payload = $payload;
}

public function getPayload(): object
{
return $this->payload;
}
}
12 changes: 9 additions & 3 deletions vendor-prefixed/firebase/php-jwt/src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,29 @@ public static function decode(
// Check the nbf if it is defined. This is the time that the
// token can actually be used. If it's not yet that time, abort.
if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
$ex = new BeforeValidException(
'Cannot handle token with nbf prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf)
);
$ex->setPayload($payload);
throw $ex;
}

// Check that this token has been created before 'now'. This prevents
// using tokens that have been created for later use (and haven't
// correctly used the nbf claim).
if (!isset($payload->nbf) && isset($payload->iat) && floor($payload->iat) > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
$ex = new BeforeValidException(
'Cannot handle token with iat prior to ' . \date(DateTime::ISO8601, (int) $payload->iat)
);
$ex->setPayload($payload);
throw $ex;
}

// Check if this token has expired.
if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
throw new ExpiredException('Expired token');
$ex = new ExpiredException('Expired token');
$ex->setPayload($payload);
throw $ex;
}

return $payload;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @license BSD-3-Clause
*
* Modified by Geoff Taylor using Strauss.
* @see https://github.com/BrianHenryIE/strauss
*/
namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;

interface JWTExceptionWithPayloadInterface
{
/**
* Get the payload that caused this exception.
*
* @return object
*/
public function getPayload(): object;

/**
* Get the payload that caused this exception.
*
* @param object $payload
* @return void
*/
public function setPayload(object $payload): void;
}

0 comments on commit d0db73a

Please sign in to comment.