mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-10 23:42:39 +08:00
do drop shipping address when no country code given in PurchaseUnitFactory::fromWcCart
This commit is contained in:
parent
2d8d62c71d
commit
77c170713d
2 changed files with 106 additions and 7 deletions
|
@ -77,7 +77,7 @@ class PurchaseUnitFactory
|
||||||
$customer = \WC()->customer;
|
$customer = \WC()->customer;
|
||||||
if (is_a($customer, \WC_Customer::class)) {
|
if (is_a($customer, \WC_Customer::class)) {
|
||||||
$shipping = $this->shippingFactory->fromWcCustomer(\WC()->customer);
|
$shipping = $this->shippingFactory->fromWcCustomer(\WC()->customer);
|
||||||
if ($shipping->address()->countryCode() && !$shipping->address()->postalCode()) {
|
if (! $shipping->address()->countryCode() || ($shipping->address()->countryCode() && !$shipping->address()->postalCode())) {
|
||||||
$shipping = null;
|
$shipping = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ use Inpsyde\PayPalCommerce\ApiClient\Entity\Payee;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Shipping;
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\Shipping;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Repository\PayeeRepository;
|
use Inpsyde\PayPalCommerce\ApiClient\Repository\PayeeRepository;
|
||||||
use Mockery;
|
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\TestCase;
|
use Inpsyde\PayPalCommerce\ApiClient\TestCase;
|
||||||
use function Brain\Monkey\Functions\expect;
|
use function Brain\Monkey\Functions\expect;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
class PurchaseUnitFactoryTest extends TestCase
|
class PurchaseUnitFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -169,7 +169,7 @@ class PurchaseUnitFactoryTest extends TestCase
|
||||||
$this->assertEquals(null, $unit->shipping());
|
$this->assertEquals(null, $unit->shipping());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWcCart()
|
public function testWcCartDefault()
|
||||||
{
|
{
|
||||||
|
|
||||||
$wcCustomer = Mockery::mock(\WC_Customer::class);
|
$wcCustomer = Mockery::mock(\WC_Customer::class);
|
||||||
|
@ -196,15 +196,15 @@ class PurchaseUnitFactoryTest extends TestCase
|
||||||
|
|
||||||
$address = Mockery::mock(Address::class);
|
$address = Mockery::mock(Address::class);
|
||||||
$address
|
$address
|
||||||
->expects('countryCode')
|
->shouldReceive('countryCode')
|
||||||
->andReturn('DE');
|
->andReturn('DE');
|
||||||
$address
|
$address
|
||||||
->expects('postalCode')
|
->shouldReceive('postalCode')
|
||||||
->andReturn('12345');
|
->andReturn('12345');
|
||||||
$shipping = Mockery::mock(Shipping::class);
|
$shipping = Mockery::mock(Shipping::class);
|
||||||
$shipping
|
$shipping
|
||||||
->expects('address')
|
->shouldReceive('address')
|
||||||
->times(2)
|
->zeroOrMoreTimes()
|
||||||
->andReturn($address);
|
->andReturn($address);
|
||||||
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||||
$shippingFactory
|
$shippingFactory
|
||||||
|
@ -267,5 +267,104 @@ class PurchaseUnitFactoryTest extends TestCase
|
||||||
$unit = $testee->fromWcCart($wcCart);
|
$unit = $testee->fromWcCart($wcCart);
|
||||||
$this->assertNull($unit->shipping());
|
$this->assertNull($unit->shipping());
|
||||||
}
|
}
|
||||||
|
public function testWcCartShippingGetsDroppendWhenNoPostalCode() {
|
||||||
|
|
||||||
|
expect('WC')
|
||||||
|
->andReturn((object) ['customer' => Mockery::mock(\WC_Customer::class)]);
|
||||||
|
|
||||||
|
$wcCart = Mockery::mock(\WC_Cart::class);
|
||||||
|
$amount = Mockery::mock(Amount::class);
|
||||||
|
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||||
|
$amountFactory
|
||||||
|
->expects('fromWcCart')
|
||||||
|
->with($wcCart)
|
||||||
|
->andReturn($amount);
|
||||||
|
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||||
|
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||||
|
$payee = Mockery::mock(Payee::class);
|
||||||
|
$payeeRepository
|
||||||
|
->expects('payee')->andReturn($payee);
|
||||||
|
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||||
|
$itemFactory
|
||||||
|
->expects('fromWcCart')
|
||||||
|
->with($wcCart)
|
||||||
|
->andReturn([]);
|
||||||
|
|
||||||
|
|
||||||
|
$address = Mockery::mock(Address::class);
|
||||||
|
$address
|
||||||
|
->shouldReceive('countryCode')
|
||||||
|
->andReturn('DE');
|
||||||
|
$address
|
||||||
|
->shouldReceive('postalCode')
|
||||||
|
->andReturn('');
|
||||||
|
$shipping = Mockery::mock(Shipping::class);
|
||||||
|
$shipping
|
||||||
|
->shouldReceive('address')
|
||||||
|
->andReturn($address);
|
||||||
|
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||||
|
$shippingFactory
|
||||||
|
->expects('fromWcCustomer')
|
||||||
|
->andReturn($shipping);
|
||||||
|
|
||||||
|
$testee = new PurchaseUnitFactory(
|
||||||
|
$amountFactory,
|
||||||
|
$payeeRepository,
|
||||||
|
$payeeFactory,
|
||||||
|
$itemFactory,
|
||||||
|
$shippingFactory
|
||||||
|
);
|
||||||
|
|
||||||
|
$unit = $testee->fromWcCart($wcCart);
|
||||||
|
$this->assertNull($unit->shipping());
|
||||||
|
}
|
||||||
|
public function testWcCartShippingGetsDroppendWhenNoCountryCode() {
|
||||||
|
|
||||||
|
expect('WC')
|
||||||
|
->andReturn((object) ['customer' => Mockery::mock(\WC_Customer::class)]);
|
||||||
|
|
||||||
|
$wcCart = Mockery::mock(\WC_Cart::class);
|
||||||
|
$amount = Mockery::mock(Amount::class);
|
||||||
|
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||||
|
$amountFactory
|
||||||
|
->expects('fromWcCart')
|
||||||
|
->with($wcCart)
|
||||||
|
->andReturn($amount);
|
||||||
|
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||||
|
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||||
|
$payee = Mockery::mock(Payee::class);
|
||||||
|
$payeeRepository
|
||||||
|
->expects('payee')->andReturn($payee);
|
||||||
|
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||||
|
$itemFactory
|
||||||
|
->expects('fromWcCart')
|
||||||
|
->with($wcCart)
|
||||||
|
->andReturn([]);
|
||||||
|
|
||||||
|
|
||||||
|
$address = Mockery::mock(Address::class);
|
||||||
|
$address
|
||||||
|
->shouldReceive('countryCode')
|
||||||
|
->andReturn('');
|
||||||
|
$shipping = Mockery::mock(Shipping::class);
|
||||||
|
$shipping
|
||||||
|
->shouldReceive('address')
|
||||||
|
->andReturn($address);
|
||||||
|
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||||
|
$shippingFactory
|
||||||
|
->expects('fromWcCustomer')
|
||||||
|
->andReturn($shipping);
|
||||||
|
|
||||||
|
$testee = new PurchaseUnitFactory(
|
||||||
|
$amountFactory,
|
||||||
|
$payeeRepository,
|
||||||
|
$payeeFactory,
|
||||||
|
$itemFactory,
|
||||||
|
$shippingFactory
|
||||||
|
);
|
||||||
|
|
||||||
|
$unit = $testee->fromWcCart($wcCart);
|
||||||
|
$this->assertNull($unit->shipping());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue