rename WcGateway to PayPalGateway

This commit is contained in:
David Remer 2020-08-18 08:46:18 +03:00
parent 781760a82c
commit 03d2ed9897
14 changed files with 52 additions and 52 deletions

View file

@ -11,7 +11,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Entity\PaymentToken;
use Inpsyde\PayPalCommerce\ApiClient\Factory\PayerFactory;
use Inpsyde\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use Inpsyde\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Psr\Log\LoggerInterface;
class RenewalHandler
@ -141,7 +141,7 @@ class RenewalHandler
if ($order->intent() === 'AUTHORIZE') {
$this->orderEndpoint->authorize($order);
$wcOrder->update_meta_data(WcGateway::CAPTURED_META_KEY, 'false');
$wcOrder->update_meta_data(PayPalGateway::CAPTURED_META_KEY, 'false');
\WC_Subscriptions_Manager::process_subscription_payments_on_order($wcOrder);
}
}

View file

@ -6,7 +6,7 @@ namespace Inpsyde\PayPalCommerce\Subscription;
use Dhii\Container\ServiceProvider;
use Dhii\Modular\Module\ModuleInterface;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
@ -27,7 +27,7 @@ class SubscriptionModule implements ModuleInterface
public function run(ContainerInterface $container)
{
add_action(
'woocommerce_scheduled_subscription_payment_' . WcGateway::ID,
'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID,
static function ($amount, $order) use ($container) {
if (! is_a($order, \WC_Order::class)) {
return;

View file

@ -11,7 +11,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
use Inpsyde\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
@ -22,14 +22,14 @@ use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use WpOop\TransientCache\CachePoolFactory;
return [
'wcgateway.gateway' => static function (ContainerInterface $container): WcGateway {
'wcgateway.paypal-gateway' => static function (ContainerInterface $container): PayPalGateway {
$orderProcessor = $container->get('wcgateway.order-processor');
$settingsRenderer = $container->get('wcgateway.settings.render');
$authorizedPayments = $container->get('wcgateway.processor.authorized-payments');
$notice = $container->get('wcgateway.notice.authorize-order-action');
$settings = $container->get('wcgateway.settings');
return new WcGateway(
return new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPayments,

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
class OrderTablePaymentStatusColumn
@ -65,12 +65,12 @@ class OrderTablePaymentStatusColumn
private function renderForOrder(\WC_Order $order): bool
{
return !empty($order->get_meta(WcGateway::CAPTURED_META_KEY));
return !empty($order->get_meta(PayPalGateway::CAPTURED_META_KEY));
}
private function isCaptured(\WC_Order $wcOrder): bool
{
$captured = $wcOrder->get_meta(WcGateway::CAPTURED_META_KEY);
$captured = $wcOrder->get_meta(PayPalGateway::CAPTURED_META_KEY);
return wc_string_to_bool($captured);
}

View file

@ -4,15 +4,15 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
class PaymentStatusOrderDetail
{
public function render(int $wcOrderId)
{
$wcOrder = new \WC_Order($wcOrderId);
$intent = $wcOrder->get_meta(WcGateway::INTENT_META_KEY);
$captured = $wcOrder->get_meta(WcGateway::CAPTURED_META_KEY);
$intent = $wcOrder->get_meta(PayPalGateway::INTENT_META_KEY);
$captured = $wcOrder->get_meta(PayPalGateway::CAPTURED_META_KEY);
if (strcasecmp($intent, 'AUTHORIZE') !== 0) {
return;

View file

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Checkout;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Psr\Container\ContainerInterface;
class DisableGateways
@ -24,14 +24,14 @@ class DisableGateways
public function handler(array $methods): array
{
if (! isset($methods[WcGateway::ID])) {
if (! isset($methods[PayPalGateway::ID])) {
return $methods;
}
if (
! $this->settings->has('merchant_email')
|| ! is_email($this->settings->get('merchant_email'))
) {
unset($methods[WcGateway::ID]);
unset($methods[PayPalGateway::ID]);
return $methods;
}
@ -39,7 +39,7 @@ class DisableGateways
return $methods;
}
return [WcGateway::ID => $methods[WcGateway::ID]];
return [PayPalGateway::ID => $methods[PayPalGateway::ID]];
}
private function needsToDisableGateways(): bool

View file

@ -22,7 +22,7 @@ use Psr\Container\ContainerInterface;
//phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
class WcGateway extends \WC_Payment_Gateway
class PayPalGateway extends \WC_Payment_Gateway
{
public const ID = 'ppcp-gateway';

View file

@ -10,7 +10,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Authorization;
use Inpsyde\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
class AuthorizedPaymentsProcessor
{
@ -71,7 +71,7 @@ class AuthorizedPaymentsProcessor
private function payPalOrderFromWcOrder(\WC_Order $wcOrder): Order
{
$orderId = $wcOrder->get_meta(WcGateway::ORDER_ID_META_KEY);
$orderId = $wcOrder->get_meta(PayPalGateway::ORDER_ID_META_KEY);
return $this->orderEndpoint->order($orderId);
}

View file

@ -12,7 +12,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Factory\OrderFactory;
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
use Inpsyde\PayPalCommerce\Button\Helper\ThreeDSecure;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
class OrderProcessor
{
@ -45,8 +45,8 @@ class OrderProcessor
public function process(\WC_Order $wcOrder, \WooCommerce $woocommerce): bool
{
$order = $this->sessionHandler->order();
$wcOrder->update_meta_data(WcGateway::ORDER_ID_META_KEY, $order->id());
$wcOrder->update_meta_data(WcGateway::INTENT_META_KEY, $order->intent());
$wcOrder->update_meta_data(PayPalGateway::ORDER_ID_META_KEY, $order->id());
$wcOrder->update_meta_data(PayPalGateway::INTENT_META_KEY, $order->intent());
$errorMessage = null;
if (!$order || ! $this->orderIsApproved($order)) {
@ -71,7 +71,7 @@ class OrderProcessor
if ($order->intent() === 'AUTHORIZE') {
$order = $this->orderEndpoint->authorize($order);
$wcOrder->update_meta_data(WcGateway::CAPTURED_META_KEY, 'false');
$wcOrder->update_meta_data(PayPalGateway::CAPTURED_META_KEY, 'false');
}
$wcOrder->update_status(

View file

@ -12,7 +12,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
use Inpsyde\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
@ -98,7 +98,7 @@ class WcGatewayModule implements ModuleInterface
add_filter(
'woocommerce_payment_gateways',
static function ($methods) use ($container): array {
$methods[] = $container->get('wcgateway.gateway');
$methods[] = $container->get('wcgateway.paypal-gateway');
return (array)$methods;
}
);
@ -168,9 +168,9 @@ class WcGatewayModule implements ModuleInterface
'woocommerce_order_action_ppcp_authorize_order',
static function (\WC_Order $wcOrder) use ($container) {
/**
* @var WcGateway $gateway
* @var PayPalGateway $gateway
*/
$gateway = $container->get('wcgateway.gateway');
$gateway = $container->get('wcgateway.paypal-gateway');
$gateway->captureAuthorizedPayment($wcOrder);
}
);

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Webhooks\Handler;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Psr\Log\LoggerInterface;
class PaymentCaptureCompleted implements RequestHandler
@ -78,7 +78,7 @@ class PaymentCaptureCompleted implements RequestHandler
);
$wcOrder->set_status('processing');
$wcOrder->update_meta_data(WcGateway::CAPTURED_META_KEY, 'true');
$wcOrder->update_meta_data(PayPalGateway::CAPTURED_META_KEY, 'true');
$wcOrder->save();
$this->logger->log(
'info',

View file

@ -37,7 +37,7 @@ class WcGatewayTest extends TestCase
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')->andReturnFalse();
$testee = new WcGateway(
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,
@ -68,7 +68,7 @@ class WcGatewayTest extends TestCase
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')->andReturnFalse();
$testee = new WcGateway(
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,
@ -105,7 +105,7 @@ class WcGatewayTest extends TestCase
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')->andReturnFalse();
$testee = new WcGateway(
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,
@ -136,7 +136,7 @@ class WcGatewayTest extends TestCase
->with('processing');
$wcOrder
->expects('update_meta_data')
->with(WcGateway::CAPTURED_META_KEY, 'true');
->with(PayPalGateway::CAPTURED_META_KEY, 'true');
$wcOrder
->expects('save');
$settingsRenderer = Mockery::mock(SettingsRenderer::class);
@ -157,7 +157,7 @@ class WcGatewayTest extends TestCase
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')->andReturnFalse();
$testee = new WcGateway(
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,
@ -181,7 +181,7 @@ class WcGatewayTest extends TestCase
->with('processing');
$wcOrder
->expects('update_meta_data')
->with(WcGateway::CAPTURED_META_KEY, 'true');
->with(PayPalGateway::CAPTURED_META_KEY, 'true');
$wcOrder
->expects('save');
$settingsRenderer = Mockery::mock(SettingsRenderer::class);
@ -201,7 +201,7 @@ class WcGatewayTest extends TestCase
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')->andReturnFalse();
$testee = new WcGateway(
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,
@ -238,7 +238,7 @@ class WcGatewayTest extends TestCase
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')->andReturnFalse();
$testee = new WcGateway(
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,

View file

@ -13,7 +13,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Entity\Payments;
use Inpsyde\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use Inpsyde\PayPalCommerce\ApiClient\Exception\RuntimeException;
use Inpsyde\PayPalCommerce\TestCase;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Mockery;
class AuthorizedPaymentsProcessorTest extends TestCase
{
@ -60,7 +60,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_meta')
->with(WcGateway::ORDER_ID_META_KEY)
->with(PayPalGateway::ORDER_ID_META_KEY)
->andReturn($orderId);
$this->assertTrue($testee->process($wcOrder));
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $testee->lastStatus());
@ -79,7 +79,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_meta')
->with(WcGateway::ORDER_ID_META_KEY)
->with(PayPalGateway::ORDER_ID_META_KEY)
->andReturn($orderId);
$this->assertFalse($testee->process($wcOrder));
$this->assertEquals(AuthorizedPaymentsProcessor::INACCESSIBLE, $testee->lastStatus());
@ -98,7 +98,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_meta')
->with(WcGateway::ORDER_ID_META_KEY)
->with(PayPalGateway::ORDER_ID_META_KEY)
->andReturn($orderId);
$this->assertFalse($testee->process($wcOrder));
$this->assertEquals(AuthorizedPaymentsProcessor::NOT_FOUND, $testee->lastStatus());
@ -146,7 +146,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_meta')
->with(WcGateway::ORDER_ID_META_KEY)
->with(PayPalGateway::ORDER_ID_META_KEY)
->andReturn($orderId);
$this->assertFalse($testee->process($wcOrder));
$this->assertEquals(AuthorizedPaymentsProcessor::FAILED, $testee->lastStatus());
@ -190,7 +190,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_meta')
->with(WcGateway::ORDER_ID_META_KEY)
->with(PayPalGateway::ORDER_ID_META_KEY)
->andReturn($orderId);
$this->assertFalse($testee->process($wcOrder));
$this->assertEquals(AuthorizedPaymentsProcessor::ALREADY_CAPTURED, $testee->lastStatus());

View file

@ -13,7 +13,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
use Inpsyde\PayPalCommerce\Button\Helper\ThreeDSecure;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\TestCase;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Inpsyde\Woocommerce\Logging\WoocommerceLoggingModule;
use Mockery;
@ -85,19 +85,19 @@ class OrderProcessorTest extends TestCase
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::ORDER_ID_META_KEY,
PayPalGateway::ORDER_ID_META_KEY,
$orderId
);
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::CAPTURED_META_KEY,
PayPalGateway::CAPTURED_META_KEY,
'false'
);
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::INTENT_META_KEY,
PayPalGateway::INTENT_META_KEY,
$orderIntent
);
$wcOrder
@ -171,13 +171,13 @@ class OrderProcessorTest extends TestCase
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::ORDER_ID_META_KEY,
PayPalGateway::ORDER_ID_META_KEY,
$orderId
);
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::INTENT_META_KEY,
PayPalGateway::INTENT_META_KEY,
$orderIntent
);
$wcOrder
@ -235,13 +235,13 @@ class OrderProcessorTest extends TestCase
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::ORDER_ID_META_KEY,
PayPalGateway::ORDER_ID_META_KEY,
$orderId
);
$wcOrder
->expects('update_meta_data')
->with(
WcGateway::INTENT_META_KEY,
PayPalGateway::INTENT_META_KEY,
$orderIntent
);
$this->assertFalse($testee->process($wcOrder, $woocommerce));