mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge remote-tracking branch 'origin/trunk' into PCP-155-tracking-api
# Conflicts: # modules/ppcp-wc-gateway/services.php # modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php # tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
This commit is contained in:
commit
9b63ab0b91
81 changed files with 3707 additions and 1031 deletions
|
@ -46,6 +46,7 @@ class IdentityTokenTest extends TestCase
|
|||
|
||||
public function testGenerateForCustomerReturnsToken()
|
||||
{
|
||||
$id = 1;
|
||||
define( 'PPCP_FLAG_SUBSCRIPTION', true );
|
||||
$token = Mockery::mock(Token::class);
|
||||
$token
|
||||
|
@ -60,6 +61,7 @@ class IdentityTokenTest extends TestCase
|
|||
$this->settings->shouldReceive('has')->andReturn(true);
|
||||
$this->settings->shouldReceive('get')->andReturn(true);
|
||||
$this->customer_repository->shouldReceive('customer_id_for_user')->andReturn('prefix1');
|
||||
expect('update_user_meta')->with($id, 'ppcp_customer_id', 'prefix1');
|
||||
|
||||
$rawResponse = [
|
||||
'body' => '{"client_token":"abc123", "expires_in":3600}',
|
||||
|
@ -97,6 +99,7 @@ class IdentityTokenTest extends TestCase
|
|||
|
||||
public function testGenerateForCustomerFailsBecauseWpError()
|
||||
{
|
||||
$id = 1;
|
||||
$token = Mockery::mock(Token::class);
|
||||
$token
|
||||
->expects('token')->andReturn('bearer');
|
||||
|
@ -111,7 +114,8 @@ class IdentityTokenTest extends TestCase
|
|||
$this->logger->shouldReceive('debug');
|
||||
$this->settings->shouldReceive('has')->andReturn(true);
|
||||
$this->settings->shouldReceive('get')->andReturn(true);
|
||||
$this->customer_repository->shouldReceive('customer_id_for_user');
|
||||
$this->customer_repository->shouldReceive('customer_id_for_user')->andReturn('prefix1');
|
||||
expect('update_user_meta')->with($id, 'ppcp_customer_id', 'prefix1');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->sut->generate_for_user(1);
|
||||
|
@ -119,6 +123,7 @@ class IdentityTokenTest extends TestCase
|
|||
|
||||
public function testGenerateForCustomerFailsBecauseResponseCodeIsNot200()
|
||||
{
|
||||
$id = 1;
|
||||
$token = Mockery::mock(Token::class);
|
||||
$token
|
||||
->expects('token')->andReturn('bearer');
|
||||
|
@ -137,7 +142,8 @@ class IdentityTokenTest extends TestCase
|
|||
$this->logger->shouldReceive('debug');
|
||||
$this->settings->shouldReceive('has')->andReturn(true);
|
||||
$this->settings->shouldReceive('get')->andReturn(true);
|
||||
$this->customer_repository->shouldReceive('customer_id_for_user');
|
||||
$this->customer_repository->shouldReceive('customer_id_for_user')->andReturn('prefix1');
|
||||
expect('update_user_meta')->with($id, 'ppcp_customer_id', 'prefix1');
|
||||
|
||||
$this->expectException(PayPalApiException::class);
|
||||
$this->sut->generate_for_user(1);
|
||||
|
|
|
@ -1046,8 +1046,6 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer->expects('email_address')->andReturn('email@email.com');
|
||||
$payerName = Mockery::mock(PayerName::class);
|
||||
$payer->expects('name')->andReturn($payerName);
|
||||
$payer->expects('to_array')->andReturn(['payer']);
|
||||
$result = $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer);
|
||||
$this->assertEquals($expectedOrder, $result);
|
||||
|
@ -1138,8 +1136,6 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer->expects('email_address')->andReturn('email@email.com');
|
||||
$payerName = Mockery::mock(PayerName::class);
|
||||
$payer->expects('name')->andReturn($payerName);
|
||||
$payer->expects('to_array')->andReturn(['payer']);
|
||||
$testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING, $payer);
|
||||
}
|
||||
|
@ -1229,8 +1225,6 @@ class OrderEndpointTest extends TestCase
|
|||
$this->expectException(RuntimeException::class);
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer->expects('email_address')->andReturn('email@email.com');
|
||||
$payerName = Mockery::mock(PayerName::class);
|
||||
$payer->expects('name')->andReturn($payerName);
|
||||
$payer->expects('to_array')->andReturn(['payer']);
|
||||
$testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
|||
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\CardBillingMode;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
|
||||
|
@ -152,6 +153,7 @@ class CreateOrderEndpointTest extends TestCase
|
|||
$session_handler = Mockery::mock(SessionHandler::class);
|
||||
$settings = Mockery::mock(Settings::class);
|
||||
$early_order_handler = Mockery::mock(EarlyOrderHandler::class);
|
||||
$settings->shouldReceive('has')->andReturnFalse();
|
||||
|
||||
$testee = new CreateOrderEndpoint(
|
||||
$request_data,
|
||||
|
@ -163,6 +165,7 @@ class CreateOrderEndpointTest extends TestCase
|
|||
$settings,
|
||||
$early_order_handler,
|
||||
false,
|
||||
CardBillingMode::MINIMAL_INPUT,
|
||||
new NullLogger()
|
||||
);
|
||||
return array($payer_factory, $testee);
|
||||
|
|
|
@ -23,6 +23,8 @@ use Mockery;
|
|||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
class RenewalHandlerTest extends TestCase
|
||||
{
|
||||
|
@ -48,6 +50,11 @@ class RenewalHandlerTest extends TestCase
|
|||
$this->shippingPreferenceFactory = Mockery::mock(ShippingPreferenceFactory::class);
|
||||
$this->payerFactory = Mockery::mock(PayerFactory::class);
|
||||
$this->environment = new Environment(new Dictionary([]));
|
||||
$authorizedPaymentProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class);
|
||||
$settings = Mockery::mock(Settings::class);
|
||||
$settings
|
||||
->shouldReceive('has')
|
||||
->andReturnFalse();
|
||||
|
||||
$this->logger->shouldReceive('error')->andReturnUsing(function ($msg) {
|
||||
throw new Exception($msg);
|
||||
|
@ -61,7 +68,9 @@ class RenewalHandlerTest extends TestCase
|
|||
$this->purchaseUnitFactory,
|
||||
$this->shippingPreferenceFactory,
|
||||
$this->payerFactory,
|
||||
$this->environment
|
||||
$this->environment,
|
||||
$settings,
|
||||
$authorizedPaymentProcessor
|
||||
);
|
||||
}
|
||||
|
||||
|
|
146
tests/PHPUnit/Vaulting/VaultedCreditCardHandlerTest.php
Normal file
146
tests/PHPUnit/Vaulting/VaultedCreditCardHandlerTest.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
namespace PHPUnit\Vaulting;
|
||||
|
||||
use Mockery;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WC_Customer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSourceCard;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\VaultedCreditCardHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
use function Brain\Monkey\Functions\expect;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class VaultedCreditCardHandlerTest extends TestCase
|
||||
{
|
||||
private $subscriptionHelper;
|
||||
private $paymentTokenRepository;
|
||||
private $purchaseUnitFactory;
|
||||
private $payerFactory;
|
||||
private $shippingPreferenceFactory;
|
||||
private $orderEndpoint;
|
||||
private $environment;
|
||||
private $authorizedPaymentProcessor;
|
||||
private $config;
|
||||
private $testee;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
|
||||
$this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class);
|
||||
$this->purchaseUnitFactory = Mockery::mock(PurchaseUnitFactory::class);
|
||||
$this->payerFactory = Mockery::mock(PayerFactory::class);
|
||||
$this->shippingPreferenceFactory = Mockery::mock(ShippingPreferenceFactory::class);
|
||||
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
|
||||
$this->environment = Mockery::mock(Environment::class);
|
||||
$this->authorizedPaymentProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class);
|
||||
$this->config = Mockery::mock(ContainerInterface::class);
|
||||
|
||||
$this->testee = new VaultedCreditCardHandler(
|
||||
$this->subscriptionHelper,
|
||||
$this->paymentTokenRepository,
|
||||
$this->purchaseUnitFactory,
|
||||
$this->payerFactory,
|
||||
$this->shippingPreferenceFactory,
|
||||
$this->orderEndpoint,
|
||||
$this->environment,
|
||||
$this->authorizedPaymentProcessor,
|
||||
$this->config
|
||||
);
|
||||
}
|
||||
|
||||
public function testHandlePaymentChangingPayment()
|
||||
{
|
||||
when('filter_input')->justReturn(1);
|
||||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder->shouldReceive('get_id')->andReturn(1);
|
||||
$this->subscriptionHelper->shouldReceive('has_subscription')->andReturn(true);
|
||||
$this->subscriptionHelper->shouldReceive('is_subscription_change_payment')->andReturn(true);
|
||||
expect('update_post_meta')->with(1, 'payment_token_id', 'abc123');
|
||||
|
||||
$customer = Mockery::mock(WC_Customer::class);
|
||||
|
||||
$result = $this->testee->handle_payment('abc123', $wcOrder, $customer);
|
||||
$this->assertInstanceOf(\WC_Order::class, $result);
|
||||
}
|
||||
|
||||
public function testHandlePayment()
|
||||
{
|
||||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder->shouldReceive('get_id')->andReturn(1);
|
||||
$wcOrder->shouldReceive('get_customer_id')->andReturn(1);
|
||||
$wcOrder->shouldReceive('update_meta_data')->andReturn(1);
|
||||
$wcOrder->shouldReceive('save')->once();
|
||||
$wcOrder->shouldReceive('payment_complete')->andReturn(true);
|
||||
|
||||
$token = Mockery::mock(PaymentToken::class);
|
||||
$tokenId = 'abc123';
|
||||
$token->shouldReceive('id')->andReturn($tokenId);
|
||||
$this->paymentTokenRepository->shouldReceive('all_for_user_id')
|
||||
->andReturn([$token]);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
|
||||
$this->purchaseUnitFactory->shouldReceive('from_wc_order')
|
||||
->andReturn($purchaseUnit);
|
||||
|
||||
$customer = Mockery::mock(WC_Customer::class);
|
||||
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$this->payerFactory->shouldReceive('from_wc_order')
|
||||
->andReturn($payer);
|
||||
$this->shippingPreferenceFactory->shouldReceive('from_state')
|
||||
->andReturn('some_preference');
|
||||
|
||||
$order = Mockery::mock(Order::class);
|
||||
$order->shouldReceive('id')->andReturn('1');
|
||||
$order->shouldReceive('intent')->andReturn('CAPTURE');
|
||||
$paymentSource = Mockery::mock(PaymentSource::class);
|
||||
$paymentSourceCard = Mockery::mock(PaymentSourceCard::class);
|
||||
$paymentSource->shouldReceive('card')->andReturn($paymentSourceCard);
|
||||
$order->shouldReceive('payment_source')->andReturn($paymentSource);
|
||||
$orderStatus = Mockery::mock(OrderStatus::class);
|
||||
$orderStatus->shouldReceive('is')->andReturn(true);
|
||||
$order->shouldReceive('status')->andReturn($orderStatus);
|
||||
|
||||
$order->shouldReceive('purchase_units')->andReturn([$purchaseUnit]);
|
||||
$payments = Mockery::mock(Payments::class);
|
||||
$capture = Mockery::mock(Capture::class);
|
||||
$capture->shouldReceive('id')->andReturn('1');
|
||||
$captureStatus = Mockery::mock(CaptureStatus::class);
|
||||
$captureStatus->shouldReceive('details')->andReturn(null);
|
||||
$captureStatus->shouldReceive('name')->andReturn(CaptureStatus::COMPLETED);
|
||||
$capture->shouldReceive('status')->andReturn($captureStatus);
|
||||
$payments->shouldReceive('captures')->andReturn([$capture]);
|
||||
$purchaseUnit->shouldReceive('payments')->andReturn($payments);
|
||||
|
||||
$this->orderEndpoint->shouldReceive('create')
|
||||
->with([$purchaseUnit], 'some_preference', $payer, $token)
|
||||
->andReturn($order);
|
||||
|
||||
$this->environment->shouldReceive('current_environment_is')->andReturn(true);
|
||||
|
||||
$this->config->shouldReceive('has')->andReturn(false);
|
||||
|
||||
$result = $this->testee->handle_payment($tokenId, $wcOrder, $customer);
|
||||
$this->assertInstanceOf(\WC_Order::class, $result);
|
||||
}
|
||||
}
|
109
tests/PHPUnit/WcGateway/Gateway/CreditCardGatewayTest.php
Normal file
109
tests/PHPUnit/WcGateway/Gateway/CreditCardGatewayTest.php
Normal file
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use Mockery;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\VaultedCreditCardHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class CreditCardGatewayTest extends TestCase
|
||||
{
|
||||
private $settingsRenderer;
|
||||
private $orderProcessor;
|
||||
private $config;
|
||||
private $moduleUrl;
|
||||
private $sessionHandler;
|
||||
private $refundProcessor;
|
||||
private $state;
|
||||
private $transactionUrlProvider;
|
||||
private $subscriptionHelper;
|
||||
private $logger;
|
||||
private $paymentsEndpoint;
|
||||
private $vaultedCreditCardHandler;
|
||||
private $testee;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->settingsRenderer = Mockery::mock(SettingsRenderer::class);
|
||||
$this->orderProcessor = Mockery::mock(OrderProcessor::class);
|
||||
$this->config = Mockery::mock(ContainerInterface::class);
|
||||
$this->moduleUrl = '';
|
||||
$this->sessionHandler = Mockery::mock(SessionHandler::class);
|
||||
$this->refundProcessor = Mockery::mock(RefundProcessor::class);
|
||||
$this->state = Mockery::mock(State::class);
|
||||
$this->transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class);
|
||||
$this->subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
|
||||
$this->logger = Mockery::mock(LoggerInterface::class);
|
||||
$this->paymentsEndpoint = Mockery::mock(PaymentsEndpoint::class);
|
||||
$this->vaultedCreditCardHandler = Mockery::mock(VaultedCreditCardHandler::class);
|
||||
|
||||
$this->state->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
|
||||
$this->config->shouldReceive('has')->andReturn(true);
|
||||
$this->config->shouldReceive('get')->andReturn('');
|
||||
|
||||
$this->testee = new CreditCardGateway(
|
||||
$this->settingsRenderer,
|
||||
$this->orderProcessor,
|
||||
$this->config,
|
||||
$this->moduleUrl,
|
||||
$this->sessionHandler,
|
||||
$this->refundProcessor,
|
||||
$this->state,
|
||||
$this->transactionUrlProvider,
|
||||
$this->subscriptionHelper,
|
||||
$this->logger,
|
||||
$this->paymentsEndpoint,
|
||||
$this->vaultedCreditCardHandler
|
||||
);
|
||||
}
|
||||
|
||||
public function testProcessPayment()
|
||||
{
|
||||
$wc_order = Mockery::mock(WC_Order::class);
|
||||
when('wc_get_order')->justReturn($wc_order);
|
||||
|
||||
$this->orderProcessor->shouldReceive('process')
|
||||
->with($wc_order)
|
||||
->andReturn(true);
|
||||
$this->subscriptionHelper->shouldReceive('has_subscription')
|
||||
->andReturn(false);
|
||||
$this->sessionHandler->shouldReceive('destroy_session_data')->once();
|
||||
|
||||
$result = $this->testee->process_payment(1);
|
||||
$this->assertEquals('success', $result['result']);
|
||||
}
|
||||
|
||||
public function testProcessPaymentVaultedCard()
|
||||
{
|
||||
$wc_order = Mockery::mock(WC_Order::class);
|
||||
$wc_order->shouldReceive('get_customer_id')->andReturn(1);
|
||||
when('wc_get_order')->justReturn($wc_order);
|
||||
|
||||
$savedCreditCard = 'abc123';
|
||||
when('filter_input')->justReturn($savedCreditCard);
|
||||
|
||||
$this->vaultedCreditCardHandler
|
||||
->shouldReceive('handle_payment')
|
||||
->with($savedCreditCard, $wc_order)
|
||||
->andReturn($wc_order);
|
||||
|
||||
$this->sessionHandler->shouldReceive('destroy_session_data')->once();
|
||||
|
||||
$result = $this->testee->process_payment(1);
|
||||
$this->assertEquals('success', $result['result']);
|
||||
}
|
||||
}
|
141
tests/PHPUnit/WcGateway/Gateway/OXXO/OXXOGatewayTest.php
Normal file
141
tests/PHPUnit/WcGateway/Gateway/OXXO/OXXOGatewayTest.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO;
|
||||
|
||||
use Mockery;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class OXXOGatewayTest extends TestCase
|
||||
{
|
||||
private $orderEndpoint;
|
||||
private $purchaseUnitFactory;
|
||||
private $shippingPreferenceFactory;
|
||||
private $logger;
|
||||
private $wcOrder;
|
||||
private $testee;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
|
||||
$this->purchaseUnitFactory = Mockery::mock(PurchaseUnitFactory::class);
|
||||
$this->shippingPreferenceFactory = Mockery::mock(ShippingPreferenceFactory::class);
|
||||
$this->logger = Mockery::mock(LoggerInterface::class);
|
||||
|
||||
$this->wcOrder = Mockery::mock(WC_Order::class);
|
||||
when('wc_get_order')->justReturn($this->wcOrder);
|
||||
when('get_option')->justReturn([
|
||||
'title' => 'foo',
|
||||
'description' => 'bar',
|
||||
]);
|
||||
|
||||
$this->testee = new OXXOGateway(
|
||||
$this->orderEndpoint,
|
||||
$this->purchaseUnitFactory,
|
||||
$this->shippingPreferenceFactory,
|
||||
'oxxo.svg',
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
||||
public function testProcessPaymentSuccess()
|
||||
{
|
||||
$this->wcOrder->shouldReceive('get_billing_first_name')->andReturn('John');
|
||||
$this->wcOrder->shouldReceive('get_billing_last_name')->andReturn('Doe');
|
||||
$this->wcOrder->shouldReceive('get_billing_email')->andReturn('foo@bar.com');
|
||||
$this->wcOrder->shouldReceive('get_billing_country')->andReturn('MX');
|
||||
|
||||
list($purchaseUnit, $shippingPreference) = $this->setStubs();
|
||||
|
||||
$linkHref = 'https://sandbox.paypal.com/payment/oxxo?token=ABC123';
|
||||
$this->orderEndpoint
|
||||
->shouldReceive('confirm_payment_source')
|
||||
->with('1', [
|
||||
'oxxo' => [
|
||||
'name' => 'John Doe',
|
||||
'email' => 'foo@bar.com',
|
||||
'country_code' => 'MX',
|
||||
]
|
||||
]
|
||||
)->andReturn((object)[
|
||||
'links' => [
|
||||
(object)[
|
||||
'rel' => 'payer-action',
|
||||
'href' => $linkHref,
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$order = Mockery::mock(Order::class);
|
||||
$order->shouldReceive('id')->andReturn('1');
|
||||
|
||||
$this->orderEndpoint
|
||||
->shouldReceive('create')
|
||||
->with([$purchaseUnit], $shippingPreference)
|
||||
->andReturn($order);
|
||||
|
||||
$this->wcOrder
|
||||
->shouldReceive('add_meta_data')
|
||||
->with('ppcp_oxxo_payer_action', $linkHref)
|
||||
->andReturn(true);
|
||||
$this->wcOrder->shouldReceive('save_meta_data');
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
when('WC')->justReturn($woocommerce);
|
||||
$woocommerce->cart = $cart;
|
||||
$cart->shouldReceive('empty_cart');
|
||||
|
||||
$result = $this->testee->process_payment(1);
|
||||
$this->assertEquals('success', $result['result']);
|
||||
}
|
||||
|
||||
public function testProcessPaymentFailure()
|
||||
{
|
||||
list($purchaseUnit, $shippingPreference) = $this->setStubs();
|
||||
|
||||
$this->orderEndpoint
|
||||
->shouldReceive('create')
|
||||
->with([$purchaseUnit], $shippingPreference)
|
||||
->andThrows(RuntimeException::class);
|
||||
|
||||
$this->logger->shouldReceive('error');
|
||||
when('wc_add_notice')->justReturn();
|
||||
when('wc_get_checkout_url')->justReturn();
|
||||
$this->wcOrder->shouldReceive('update_status');
|
||||
|
||||
$result = $this->testee->process_payment(1);
|
||||
$this->assertEquals('failure', $result['result']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function setStubs(): array
|
||||
{
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
|
||||
$this->purchaseUnitFactory
|
||||
->shouldReceive('from_wc_order')
|
||||
->with($this->wcOrder)
|
||||
->andReturn($purchaseUnit);
|
||||
|
||||
$shippingPreference = 'SOME_SHIPPING_PREFERENCE';
|
||||
$this->shippingPreferenceFactory
|
||||
->shouldReceive('from_state')
|
||||
->with($purchaseUnit, 'checkout')
|
||||
->andReturn($shippingPreference);
|
||||
return array($purchaseUnit, $shippingPreference);
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
|
@ -26,6 +27,7 @@ class PayUponInvoiceGatewayTest extends TestCase
|
|||
private $logger;
|
||||
private $testee;
|
||||
private $pui_helper;
|
||||
private $checkout_helper;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
|
@ -38,6 +40,7 @@ class PayUponInvoiceGatewayTest extends TestCase
|
|||
$this->logger = Mockery::mock(LoggerInterface::class);
|
||||
$this->transaction_url_provider = Mockery::mock(TransactionUrlProvider::class);
|
||||
$this->pui_helper = Mockery::mock(PayUponInvoiceHelper::class);
|
||||
$this->checkout_helper = Mockery::mock(CheckoutHelper::class);
|
||||
|
||||
$this->setInitStubs();
|
||||
|
||||
|
@ -48,7 +51,8 @@ class PayUponInvoiceGatewayTest extends TestCase
|
|||
$this->environment,
|
||||
$this->transaction_url_provider,
|
||||
$this->logger,
|
||||
$this->pui_helper
|
||||
$this->pui_helper,
|
||||
$this->checkout_helper
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
||||
use Psr\Log\NullLogger;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
|
@ -37,7 +30,6 @@ class WcGatewayTest extends TestCase
|
|||
private $settingsRenderer;
|
||||
private $funding_source_renderer;
|
||||
private $orderProcessor;
|
||||
private $authorizedOrdersProcessor;
|
||||
private $settings;
|
||||
private $refundProcessor;
|
||||
private $onboardingState;
|
||||
|
@ -45,10 +37,7 @@ class WcGatewayTest extends TestCase
|
|||
private $subscriptionHelper;
|
||||
private $environment;
|
||||
private $paymentTokenRepository;
|
||||
private $shipping_preference_factory;
|
||||
private $logger;
|
||||
private $paymentsEndpoint;
|
||||
private $orderEndpoint;
|
||||
private $apiShopCountry;
|
||||
|
||||
public function setUp(): void {
|
||||
|
@ -60,7 +49,6 @@ class WcGatewayTest extends TestCase
|
|||
|
||||
$this->settingsRenderer = Mockery::mock(SettingsRenderer::class);
|
||||
$this->orderProcessor = Mockery::mock(OrderProcessor::class);
|
||||
$this->authorizedOrdersProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class);
|
||||
$this->settings = Mockery::mock(Settings::class);
|
||||
$this->sessionHandler = Mockery::mock(SessionHandler::class);
|
||||
$this->refundProcessor = Mockery::mock(RefundProcessor::class);
|
||||
|
@ -69,10 +57,7 @@ class WcGatewayTest extends TestCase
|
|||
$this->subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
|
||||
$this->environment = Mockery::mock(Environment::class);
|
||||
$this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class);
|
||||
$this->shipping_preference_factory = Mockery::mock(ShippingPreferenceFactory::class);
|
||||
$this->logger = Mockery::mock(LoggerInterface::class);
|
||||
$this->paymentsEndpoint = Mockery::mock(PaymentsEndpoint::class);
|
||||
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
|
||||
$this->funding_source_renderer = new FundingSourceRenderer($this->settings);
|
||||
$this->apiShopCountry = 'DE';
|
||||
|
||||
|
@ -87,6 +72,7 @@ class WcGatewayTest extends TestCase
|
|||
$this->settings->shouldReceive('has')->andReturnFalse();
|
||||
|
||||
$this->logger->shouldReceive('info');
|
||||
$this->logger->shouldReceive('error');
|
||||
}
|
||||
|
||||
private function createGateway()
|
||||
|
@ -95,7 +81,6 @@ class WcGatewayTest extends TestCase
|
|||
$this->settingsRenderer,
|
||||
$this->funding_source_renderer,
|
||||
$this->orderProcessor,
|
||||
$this->authorizedOrdersProcessor,
|
||||
$this->settings,
|
||||
$this->sessionHandler,
|
||||
$this->refundProcessor,
|
||||
|
@ -105,10 +90,7 @@ class WcGatewayTest extends TestCase
|
|||
PayPalGateway::ID,
|
||||
$this->environment,
|
||||
$this->paymentTokenRepository,
|
||||
$this->shipping_preference_factory,
|
||||
$this->logger,
|
||||
$this->paymentsEndpoint,
|
||||
$this->orderEndpoint,
|
||||
$this->apiShopCountry
|
||||
);
|
||||
}
|
||||
|
@ -173,8 +155,10 @@ class WcGatewayTest extends TestCase
|
|||
when('wc_get_checkout_url')
|
||||
->justReturn($redirectUrl);
|
||||
|
||||
expect('wc_add_notice')
|
||||
->with('Couldn\'t find order to process','error');
|
||||
$this->sessionHandler
|
||||
->shouldReceive('destroy_session_data');
|
||||
|
||||
expect('wc_add_notice');
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
|
@ -195,7 +179,6 @@ class WcGatewayTest extends TestCase
|
|||
->andReturnFalse();
|
||||
$this->orderProcessor
|
||||
->expects('last_error')
|
||||
->twice()
|
||||
->andReturn($lastError);
|
||||
$this->subscriptionHelper->shouldReceive('has_subscription')->with($orderId)->andReturn(true);
|
||||
$this->subscriptionHelper->shouldReceive('is_subscription_change_payment')->andReturn(true);
|
||||
|
@ -206,6 +189,8 @@ class WcGatewayTest extends TestCase
|
|||
expect('wc_get_order')
|
||||
->with($orderId)
|
||||
->andReturn($wcOrder);
|
||||
$this->sessionHandler
|
||||
->shouldReceive('destroy_session_data');
|
||||
expect('wc_add_notice')
|
||||
->with($lastError, 'error');
|
||||
|
||||
|
|
|
@ -14,8 +14,7 @@ class PayUponInvoiceHelperTest extends TestCase
|
|||
*/
|
||||
public function testValidateBirthDate($input, $output)
|
||||
{
|
||||
$pui_product_status = Mockery::mock(PayUponInvoiceProductStatus::class);
|
||||
$this->assertSame((new PayUponInvoiceHelper('DE', $pui_product_status))->validate_birth_date($input), $output);
|
||||
$this->assertSame((new CheckoutHelper())->validate_birth_date($input), $output);
|
||||
}
|
||||
|
||||
public function datesProvider(): array{
|
||||
|
@ -28,6 +27,7 @@ class PayUponInvoiceHelperTest extends TestCase
|
|||
['1942-02-31', false],
|
||||
['01-01-1942', false],
|
||||
['1942-01-01', true],
|
||||
['0001-01-01', false],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
||||
|
||||
|
||||
use Mockery\MockInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use WC_Order;
|
||||
|
@ -26,7 +27,11 @@ use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
|||
|
||||
class AuthorizedPaymentsProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var WC_Order&MockInterface
|
||||
*/
|
||||
private $wcOrder;
|
||||
|
||||
private $paypalOrderId = 'abc';
|
||||
private $authorizationId = 'qwe';
|
||||
private $amount = 42.0;
|
||||
|
@ -37,7 +42,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
|||
private $paymentsEndpoint;
|
||||
private $notice;
|
||||
private $config;
|
||||
private $subscription_helperauthorization;
|
||||
private $captureId = '123qwe';
|
||||
private $testee;
|
||||
|
||||
public function setUp(): void {
|
||||
|
@ -79,7 +84,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
|||
$this->paymentsEndpoint
|
||||
->expects('capture')
|
||||
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
|
||||
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
|
||||
->andReturn($this->createCapture($this->captureId, CaptureStatus::COMPLETED));
|
||||
|
||||
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
|
||||
}
|
||||
|
@ -99,7 +104,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
|||
$this->paymentsEndpoint
|
||||
->expects('capture')
|
||||
->with($authorizations[2]->id(), equalTo(new Money($this->amount, $this->currency)))
|
||||
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
|
||||
->andReturn($this->createCapture($this->captureId, CaptureStatus::COMPLETED));
|
||||
|
||||
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
|
||||
}
|
||||
|
@ -150,12 +155,13 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
|||
$this->paymentsEndpoint
|
||||
->expects('capture')
|
||||
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
|
||||
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
|
||||
->andReturn($this->createCapture($this->captureId, CaptureStatus::COMPLETED));
|
||||
|
||||
$this->wcOrder->shouldReceive('payment_complete')->andReturn(true);
|
||||
$this->wcOrder->expects('add_order_note');
|
||||
$this->wcOrder->expects('add_order_note')->twice();
|
||||
$this->wcOrder->expects('update_meta_data');
|
||||
$this->wcOrder->expects('save');
|
||||
$this->wcOrder->expects('set_transaction_id')->with($this->captureId);
|
||||
$this->wcOrder->shouldReceive('save')->atLeast()->times(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->testee->capture_authorized_payment($this->wcOrder)
|
||||
|
@ -248,8 +254,11 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
|||
return new Authorization($id, new AuthorizationStatus($status));
|
||||
}
|
||||
|
||||
private function createCapture(string $status): Capture {
|
||||
private function createCapture(string $id, string $status): Capture {
|
||||
$capture = Mockery::mock(Capture::class);
|
||||
$capture
|
||||
->shouldReceive('id')
|
||||
->andReturn($id);
|
||||
$capture
|
||||
->shouldReceive('status')
|
||||
->andReturn(new CaptureStatus($status));
|
||||
|
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
class WC_Payment_Gateway
|
||||
{
|
||||
|
||||
protected function get_option(string $key) : string {
|
||||
public function get_option(string $key, $empty_value = null) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,4 @@ class WC_Payment_Gateway
|
|||
public function process_admin_options() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,5 +3,10 @@ declare(strict_types=1);
|
|||
|
||||
class WC_Payment_Gateway_CC
|
||||
{
|
||||
public function init_settings() {}
|
||||
public function process_admin_options() {}
|
||||
|
||||
protected function get_return_url($wcOrder) {
|
||||
return $wcOrder;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue