• Resolved snowdragon97

    (@snowdragon97)


    Hi, there is an issue with the plugin when trying to check out my specific items in the cart. for example here cosplayhero.de/product/sonstige-stilrichtungen/halloween/anime-tomoe-cosplay-peruecke-silber-weiss-100cm-lang-gerade-hitzebestaendige-synthetische-haar-halloween-anime-peruecken-peruecken-kappe

    if you select the variation for 52,95 it always give the error the response is not a valid json response. here is the log, can you please look into it? thanks

    2025-04-12T16:48:26+00:00 Error Error creating PayPal order. Msg: WpOrg\Requests\Transport\Curl::request(): Argument #3 ($data) must be of type array|string, boolean given Params: Array ( [intent] => CAPTURE [payer] => Array ( [name] => Array ( [given_name] => Michelle [surname] => Goletz ) [address] => Array ( [address_line_1] => Ursula-Querner-Straße 2 [address_line_2] => [admin_area_1] => DE-HH [admin_area_2] => Hamburg [postal_code] => 21035 [country_code] => DE ) [email_address] => michelle.goletz@googlemail.com ) [purchase_units] => Array ( [0] => Array ( [amount] => Array ( [value] => 153.85 [currency_code] => EUR [breakdown] => Array ( [item_total] => Array ( [currency_code] => EUR [value] => 153.85 ) [shipping] => Array ( [currency_code] => EUR [value] => 0.00 ) [tax_total] => Array ( [value] => 0.00 [currency_code] => EUR ) [discount] => Array ( [value] => 0.00 [currency_code] => EUR ) [handling] => Array ( [currency_code] => EUR [value] => 0.00 ) ) ) [items] => Array ( [0] => Array ( [name] => Sebastian Michaelis Cosplay Perücke Schwarz 32cm Anime Qualität Hitzebeständige Synthetik Haare Halloween + Gratis Perücken [quantity] => 1 [unit_amount] => Array ( [currency_code] => EUR [value] => 46.95 ) [sku] => 19145605942353 [description] => Produkt-ID: 1443983. Variations-ID: 1445418 ) [1] => Array (   [quantity] => 1 [unit_amount] => Array ( [currency_code] => EUR [value] => 52.95 ) [sku] => 10RTEMJD2T4N [description] => Produkt-ID: 1278615. Variations-ID: 1292429 ) [2] => Array ( [name] => Anime Kaito Cosplay Perücke Kurz Blau Gemischt Hitzebeständig Synthetisches Haar Party Perücke + Gratis Perückenkappe [quantity] => 1 [unit_amount] => Array ( [currency_code] => EUR [value] => 53.95 ) [sku] => WX2AX4IMCTVC [description] => Produkt-ID: 1278945 ) ) [shipping] => Array ( [name] => Array ( [full_name] => Michelle Goletz ) [address] => Array ( [address_line_1] => Ursula-Querner-Straße 2 [address_line_2] => [admin_area_1] => DE-HH [admin_area_2] => Hamburg [postal_code] => 21035 [country_code] => DE ) ) ) ) [application_context] => Array ( [shipping_preference] => GET_FROM_FILE [return_url] => https://cosplayhero.de/wc-api/ppcp_checkout_return/?_checkoutnonce=4b3e9f624b [cancel_url] => https://cosplayhero.de/kasse [brand_name] => CosplayHero ) )

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    Is this a duplicate of your other request?

    This error happens when 3rd party plugins or custom code incorrectly uses the WordPress request filter http_request_args. This plugin uses core WordPress API’s to make requests and there are filters that WordPress provides that some plugins might not be using correctly.

    I’d recommend checking for a plugin conflict or theme conflict as a first step.

    Kind Regards

    Thread Starter snowdragon97

    (@snowdragon97)

    yes a duplicate. I doubt that to be honest. The issue seems to appear only with a few specific products. please see the log here: https://drive.google.com/file/d/11X9rw27RFlU4tDzy-8T3HcP330aNxrLj/view?usp=sharing

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    The same code in the plugin is called regardless of the product. I believe that adds to the evidence that there is a 3rd party plugin that’s causing that conflict.

    What I recommend you try is testing for a plugin conflict. For example, deactivate everything but WooCommerce and PayPal. Does the error go away? What about when you test a default theme?

    I doubt that to be honest.

    Can you elaborate on what it is you doubt?

    Kind Regards

    Thread Starter snowdragon97

    (@snowdragon97)

    I tested it with plugins deactivated and standard theme. Still happens. Have you checked the log? My ai says that according to the log the product name is empty in the request. But the product has a name. I cant find any solution for this. Customers message me that it happens to them and they cant order.

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    Have you checked the log?

    Yes, and the error that shows over and over again in the log you provided is this one:

    ERROR Error creating PayPal order. Msg: WpOrg\Requests\Transport\Curl::request(): Argument #3 ($data) must be of type array|string, boolean given Params: Array

    My ai says that according to the log the product name is empty in the request

    I am not seeing that in the log file you provided. If there is another file that shows that can you share it?

    Thanks

    Thread Starter snowdragon97

    (@snowdragon97)

    after more digging:  



    You are getting the error because your PayPal API call is passing a “boolean” value (true/false) to a place where it expects either an array or a string.

    When looking at your order details, most of the data looks correct:

    The payer name and email are fine, shipping details are there, products are listed.

    But there is something suspicious in the product list:

    One of your products has a corrupted name. Specifically, the second product ends with this:

    “Anime Tomoe Cosplay Perücke Silber Weiß 100cm Lang Gerade Hitzebeständige Synthetische Haar Halloween Anime Perücken + Per�”

    The strange character at the end (“�”) means there is a broken or invalid character encoding.

    This is likely coming from the product title in your database or from how the title was saved.

    What happens is:

    • When your system tries to prepare the data for PayPal, it runs json_encode() to convert the data to JSON.

    • If there’s a broken character like this, json_encode() fails and returns “false”.

    • When this “false” is sent to the PayPal API, the system throws an error because it expected a proper array or string, not a boolean value.

    That’s why you get this error.

    So

    could this be the reason? can I add a code snippet so such things do not cause the JSON to get broken?

    Do you think sth like this works:

    // Clean up product names and descriptions before PayPal order creation
    add_filter(‘woocommerce_paypal_payments_create_order_request’, function($request, $order) {
    // Safety check
    if (empty($request[‘purchase_units’][0][‘items’])) {
    return $request;
    }

    // Loop through all items in the request
    foreach ($request['purchase_units'][0]['items'] as &$item) {
        if (!empty($item['name'])) {
            $item['name'] = clean_utf8_string($item['name']);
        }
        if (!empty($item['description'])) {
            $item['description'] = clean_utf8_string($item['description']);
        }
    }
    
    return $request;

    }, 10, 2);

    // Helper function to clean UTF-8 strings
    function clean_utf8_string($string) {
    // Convert to UTF-8 and remove invalid characters
    $string = mb_convert_encoding($string, ‘UTF-8’, ‘UTF-8’);
    // Optionally strip other problematic characters
    $string = preg_replace(‘/[^\P{C}]+/u’, ”, $string); // Remove control characters
    return $string;
    }

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    It’s certainly worth a try to see if there is an invalid encoding. Or you could temporarily change the name of your product and test.

    Kind Regards,

    Thread Starter snowdragon97

    (@snowdragon97)

    still the reason is somehow the product name

    Your PayPal order fails because the product in the order is missing the “name” field.

    When you send data to PayPal, every product in the order needs:

    • A name

    • A quantity

    • A price (unit amount)

    In your current order, the product has:

    • Quantity ✅

    • Price ✅

    • But no name ❌

    Because the “name” is missing, your system tries to prepare the data for PayPal, but when it converts the data to JSON, it fails and returns “false”.

    When this “false” is sent to PayPal, the error happens:

    Argument #3 ($data) must be of type array|string, boolean given

    maybe the most simple solution is to not send the product name to PayPal?

    Thread Starter snowdragon97

    (@snowdragon97)

    I found the issue after digging a few hours! This probably affects many other plugin users, because it seems like it errors for German characters like ä ö ü which are frequently in use all over…

    I think this requires a fix from your side.

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    Thank you for the update regarding the German characters. We’ll do some testing on our end and include an update in the next release.

    PayPal’s API accepts UTF-8 so those characters will need to either be removed by the plugin or encoded. In either case, those characters won’t show up in PayPal’s line item display I don’t believe.

    Did you end up changing the name for those products or encoding the characters?

    Kind Regards

    Thread Starter snowdragon97

    (@snowdragon97)

    I tried to remove the characters for testing, which fixed the issue. Added them back, and the issue was there again. Would you like to debug this further on my store?

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    There is something else at play here. I performed a test using the same characters as in your product name and there was no issue with the German characters. Here is a screenshot showing the line item in PayPal.

    That tells me that in the Curl request, the response to encoding the body of the request is a boolean of false which means on your site, the encoding is failing.

    The PayPal plugin uses the json_encode function like this:

    $args['body'] = \json_encode( $options['json'] );

    Kind Regards,

    Thread Starter snowdragon97

    (@snowdragon97)

    Well at least on my site, as I mentioned, when I remove the special characters it works fine. Could you maybe give me a snippet to hook into the encoding, so it converts the special characters before actually doing the encoding? This would be awesome, as I was not able to create this by myself. Thanks!

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    Try this code snippet and see if it resolves your issue:

    add_filter('wc_ppcp_get_cart_item', function($item){
    $item->setName(mb_convert_encoding($item->getName(), 'UTF-8'));
    return $item;
    });

    add_filter('wc_ppcp_get_order_item', function($item){
    $item->setName(mb_convert_encoding($item->getName(), 'UTF-8'));
    return $item;
    });

    Kind Regards,

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @snowdragon97

    Did you try the suggested code?

    Thanks

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.