From c9da7b8e57ef7e197cfef26adeca08d08fdb4a1a Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 29 Oct 2020 23:41:09 +0100 Subject: [PATCH 1/2] Inform about empty billing address after PayPal checkout --- src/Api/CreateOrderApi.php | 13 +---------- src/Controller/ProcessPayPalOrderAction.php | 9 +++++--- src/Resources/translations/messages.en.yml | 2 ++ .../Common/Order/_addresses.html.twig | 23 +++++++++++++++++++ 4 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig 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/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..0a7203cf --- /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 not order.isShippingRequired() and order.billingAddress.street == '' %} +
+ +
+
{{ 'sylius.pay_pal.missing_billing_address_header'|trans }}
+

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

+
+
+{% endif %} From ec680239403f0853e427fc5c5c8a4f2f3af9108c Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Fri, 6 Nov 2020 10:07:39 +0100 Subject: [PATCH 2/2] Check order billing address missing with twig function --- src/Resources/config/services.xml | 4 +++ .../Common/Order/_addresses.html.twig | 2 +- src/Twig/OrderAddressExtension.php | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/Twig/OrderAddressExtension.php 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/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig index 0a7203cf..6d7ee9f4 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig @@ -12,7 +12,7 @@ {% endif %} -{% if not order.isShippingRequired() and order.billingAddress.street == '' %} +{% if sylius_is_billing_address_missing(order) %}
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() === '' + ; + } +}