diff --git a/src/Api/CreateOrderApi.php b/src/Api/CreateOrderApi.php index 455677d7..a2e18ef5 100644 --- a/src/Api/CreateOrderApi.php +++ b/src/Api/CreateOrderApi.php @@ -88,17 +88,6 @@ public function create(string $token, PaymentInterface $payment, string $referen 'payee' => [ 'merchant_id' => $config['merchant_id'], ], - 'shipping' => [ - 'name' => ['full_name' => 'John Doe'], - 'address' => [ - 'address_line_1' => 'Test St. 123', - 'address_line_2' => '6', - 'admin_area_1' => 'CA', - 'admin_area_2' => 'New York', - 'postal_code' => '32000', - 'country_code' => 'US', - ], - ], 'soft_descriptor' => 'Sylius PayPal Payment', 'items' => $payPalItemData['items'], ], @@ -109,7 +98,7 @@ public function create(string $token, PaymentInterface $payment, string $referen ]; $address = $order->getShippingAddress(); - if ($address !== null) { + if ($address !== null && $order->isShippingRequired()) { $data['purchase_units'][0]['shipping'] = [ 'name' => ['full_name' => $address->getFullName()], 'address' => [ diff --git a/src/Controller/ProcessPayPalOrderAction.php b/src/Controller/ProcessPayPalOrderAction.php index dbc53ff8..59a4438d 100644 --- a/src/Controller/ProcessPayPalOrderAction.php +++ b/src/Controller/ProcessPayPalOrderAction.php @@ -113,9 +113,12 @@ public function __invoke(Request $request): Response } else { $address->setFirstName($customer->getFirstName()); $address->setLastName($customer->getLastName()); - $address->setStreet(''); - $address->setCity(''); - $address->setPostcode(''); + + $defaultAddress = $customer->getDefaultAddress(); + + $address->setStreet($defaultAddress ? $defaultAddress->getStreet() : ''); + $address->setCity($defaultAddress ? $defaultAddress->getCity() : ''); + $address->setPostcode($defaultAddress ? $defaultAddress->getPostcode() : ''); $address->setCountryCode($data['payer']['address']['country_code']); $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS); } diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 07177d5d..9ee48ceb 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -260,5 +260,9 @@ + + + + diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index b2d43271..4a7f307e 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -17,3 +17,5 @@ sylius: sftp_username: 'SFTP Username' share_data_consent_confirmation: "By clicking Yes, you accept PayPal share data consent" tender_type: 'Refunded to the PayPal wallet' + missing_billing_address_header: 'We could not fetch any billing address from PayPal' + missing_billing_address_content: 'Please, go back to the Addressing step and complete it' diff --git a/src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig new file mode 100644 index 00000000..6d7ee9f4 --- /dev/null +++ b/src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig @@ -0,0 +1,23 @@ +
+
+
+
{{ 'sylius.ui.billing_address'|trans }}
+ {% include '@SyliusShop/Common/_address.html.twig' with {'address': order.billingAddress} %} +
+ {% if order.isShippingRequired() %} +
+
{{ 'sylius.ui.shipping_address'|trans }}
+ {% include '@SyliusShop/Common/_address.html.twig' with {'address': order.shippingAddress} %} +
+ {% endif %} +
+
+{% if sylius_is_billing_address_missing(order) %} +
+ +
+
{{ 'sylius.pay_pal.missing_billing_address_header'|trans }}
+

{{ 'sylius.pay_pal.missing_billing_address_content'|trans }}

+
+
+{% endif %} diff --git a/src/Twig/OrderAddressExtension.php b/src/Twig/OrderAddressExtension.php new file mode 100644 index 00000000..08491a4f --- /dev/null +++ b/src/Twig/OrderAddressExtension.php @@ -0,0 +1,33 @@ +getBillingAddress(); + + return + !$order->isShippingRequired() && + $billingAddress->getStreet() === '' && + $billingAddress->getPostcode() === '' && + $billingAddress->getCity() === '' + ; + } +}