Fix setting the shipping to null in PurchaseUnitFactory

The country code can be empty because the shipping is not mandatory information.
If it's not configured from WC the value is empty. Fixes #3
This commit is contained in:
Mészáros Róbert 2020-04-10 20:21:05 +03:00
parent 2182147f11
commit f67bac7c43

View file

@ -8,7 +8,6 @@ use Inpsyde\PayPalCommerce\ApiClient\Entity\AmountBreakdown;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Item;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Money;
use Inpsyde\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Shipping;
use Inpsyde\PayPalCommerce\ApiClient\Exception\RuntimeException;
class PurchaseUnitFactory
@ -105,7 +104,9 @@ class PurchaseUnitFactory
$breakdown
);
$shipping = $this->shippingFactory->fromWcOrder($order);
if ($shipping->address()->countryCode() && !$shipping->address()->postalCode()) {
if (empty($shipping->address()->countryCode()) ||
($shipping->address()->countryCode() && !$shipping->address()->postalCode())
) {
$shipping = null;
}