Validierungsfehler bei Virtuellen Produkten
-
Hi there,
I found a bug.
Steps to reproduce:
when I only have virtual products in my cart, set paypal as my payment method and then click buy now, the user gets an “Validierungsfehler” and is unable to submit the order.
The woocommerce logs show this error from your plugin:2022-02-10T13:53:09+00:00 ERROR Got Http response code 400 when accessing https://api.paypal.com/v1/payments/payment/PAYID-MICRFRA5TK40537YC309443X. {“name”:”VALIDATION_ERROR”,”details”:[{“field”:”purchase_units[0].item_list.shipping_address”,”issue”:”The specified country requires a postal code”}],”message”:”Invalid request – see details”,”information_link”:”https://developer.paypal.com/docs/api/payments/v1/#error-VALIDATION_ERROR”,”debug_id”:”8faabd86ebcc2″}
Cause:
when having only virtual products, there is no shipping address at the order, only a billing address. But it seems like your plugin always expects a shipping address.Workaround:
this is my workaround (set billing address as shipping address if only virtual products):add_action( 'woocommerce_checkout_order_processed', 'rd_checkout_update_shipping_address_if_only_coupons', 1000, 3 ); function rd_checkout_update_shipping_address_if_only_coupons( $order_id, $posted_data, $order ){ foreach ($order->get_items() as $order_item){ $item = wc_get_product($order_item->get_product_id()); if (!$item->is_virtual()) { return; } } $company = $order->get_billing_company(); $address_1 = $order->get_billing_address_1(); $address_2 = $order->get_billing_address_2(); $city = $order->get_billing_city(); $postcode = $order->get_billing_postcode(); $country = $order->get_billing_country(); $order->set_shipping_company($company); $order->set_shipping_address_1($address_1); $order->set_shipping_address_2($address_2); $order->set_shipping_city($city); $order->set_shipping_postcode($postcode); $order->set_shipping_country($country); $order->save(); }
Solution:
I talked to an engineer at paypal and he proposed to set the “shipping_preference”
to “NO_SHIPPING” in the “application_context” object when creating the payment. See
https://developer.paypal.com/api/payments/v1/#definition-application_contextI hope you can fix the error.
Best regards,
Nicolas
- The topic ‘Validierungsfehler bei Virtuellen Produkten’ is closed to new replies.