Fix CI errors

This commit is contained in:
dinamiko 2022-01-03 15:15:33 +01:00
parent 2c0a7596e5
commit d33ca00ac7
6 changed files with 33 additions and 15 deletions

View file

@ -98,12 +98,12 @@ class IdentityToken {
( $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) ) ( $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) )
&& defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION && defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION
) { ) {
if($customer_id === 0) { if ( 0 === $customer_id ) {
$customer_id = uniqid(); $customer_id = uniqid();
WC()->session->set('ppcp_guest_customer_id', $customer_id); WC()->session->set( 'ppcp_guest_customer_id', $customer_id );
} }
$args['body'] = wp_json_encode( array( 'customer_id' => $this->prefix . $customer_id) ); $args['body'] = wp_json_encode( array( 'customer_id' => $this->prefix . $customer_id ) );
} }
$response = $this->request( $url, $args ); $response = $this->request( $url, $args );

View file

@ -92,14 +92,14 @@ class PaymentTokenEndpoint {
public function for_user( int $id ): array { public function for_user( int $id ): array {
$bearer = $this->bearer->bearer(); $bearer = $this->bearer->bearer();
$customer_id = $this->prefix . $id; $customer_id = $this->prefix . $id;
$guest_customer_id_meta = get_user_meta( $id, 'ppcp_guest_customer_id', true ); $guest_customer_id = get_user_meta( $id, 'ppcp_guest_customer_id', true );
if($guest_customer_id_meta) { if ( $guest_customer_id ) {
$customer_id = $this->prefix . $guest_customer_id_meta; $customer_id = $this->prefix . $guest_customer_id;
} }
$url = trailingslashit( $this->host ) . 'v2/vault/payment-tokens/?customer_id=' . $customer_id; $url = trailingslashit( $this->host ) . 'v2/vault/payment-tokens/?customer_id=' . $customer_id;
$args = array( $args = array(
'method' => 'GET', 'method' => 'GET',
'headers' => array( 'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(), 'Authorization' => 'Bearer ' . $bearer->token(),

View file

@ -98,9 +98,16 @@ class VaultingModule implements ModuleInterface {
} }
); );
add_action('woocommerce_created_customer', function($customer_id) { $subscription_helper = $container->get( 'subscription.helper' );
update_user_meta($customer_id, 'ppcp_guest_customer_id', WC()->session->get('ppcp_guest_customer_id')); add_action(
}); 'woocommerce_created_customer',
function( $customer_id ) use ( $subscription_helper ) {
$guest_customer_id = WC()->session->get( 'ppcp_guest_customer_id' );
if ( $guest_customer_id && $subscription_helper->cart_contains_subscription() ) {
update_user_meta( $customer_id, 'ppcp_guest_customer_id', WC()->session->get( 'ppcp_guest_customer_id' ) );
}
}
);
$asset_loader = $container->get( 'vaulting.assets.myaccount-payments' ); $asset_loader = $container->get( 'vaulting.assets.myaccount-payments' );
add_action( add_action(

View file

@ -120,7 +120,7 @@ return array(
'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways { 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
$session_handler = $container->get( 'session.handler' ); $session_handler = $container->get( 'session.handler' );
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
return new DisableGateways( $session_handler, $settings); return new DisableGateways( $session_handler, $settings );
}, },
'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool { 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';

View file

@ -44,8 +44,8 @@ class DisableGateways {
ContainerInterface $settings ContainerInterface $settings
) { ) {
$this->session_handler = $session_handler; $this->session_handler = $session_handler;
$this->settings = $settings; $this->settings = $settings;
} }
/** /**

View file

@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery; use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use function Brain\Monkey\Functions\expect; use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
class PaymentTokenEndpointTest extends TestCase class PaymentTokenEndpointTest extends TestCase
{ {
@ -73,6 +74,8 @@ class PaymentTokenEndpointTest extends TestCase
$this->logger->shouldReceive('debug'); $this->logger->shouldReceive('debug');
when('get_user_meta')->justReturn('');
$result = $this->sut->for_user($id); $result = $this->sut->for_user($id);
$this->assertInstanceOf(PaymentToken::class, $result[0]); $this->assertInstanceOf(PaymentToken::class, $result[0]);
@ -96,6 +99,8 @@ class PaymentTokenEndpointTest extends TestCase
$this->logger->shouldReceive('log'); $this->logger->shouldReceive('log');
$this->logger->shouldReceive('debug'); $this->logger->shouldReceive('debug');
when('get_user_meta')->justReturn('');
$this->expectException(RuntimeException::class); $this->expectException(RuntimeException::class);
$this->sut->for_user($id); $this->sut->for_user($id);
} }
@ -123,6 +128,8 @@ class PaymentTokenEndpointTest extends TestCase
$this->logger->shouldReceive('log'); $this->logger->shouldReceive('log');
$this->logger->shouldReceive('debug'); $this->logger->shouldReceive('debug');
when('get_user_meta')->justReturn('');
$this->expectException(PayPalApiException::class); $this->expectException(PayPalApiException::class);
$this->sut->for_user($id); $this->sut->for_user($id);
} }
@ -185,6 +192,10 @@ class PaymentTokenEndpointTest extends TestCase
$prefix = $this->prefix; $prefix = $this->prefix;
expect('wp_remote_get')->andReturnUsing( expect('wp_remote_get')->andReturnUsing(
function ($url, $args) use ($rawResponse, $host, $prefix, $id) { function ($url, $args) use ($rawResponse, $host, $prefix, $id) {
// echo $url; // https://example.com/v2/vault/payment-tokens/?customer_id=prefixabc123
// https://example.com/v2/vault/payment-tokens/?customer_id=prefix1
// https://example.com/v2/vault/payment-tokens/?customer_id=prefixabc123
echo $host . 'v2/vault/payment-tokens/?customer_id=' . $prefix . $id;
if ($url !== $host . 'v2/vault/payment-tokens/?customer_id=' . $prefix . $id) { if ($url !== $host . 'v2/vault/payment-tokens/?customer_id=' . $prefix . $id) {
return false; return false;
} }