Laravel8 : syntax error, unexpected single-quoted string “)); ?>”> “, expecting “)

        <script type="text/javascript" src="{{ asset('/chart-area-demo.js') }}"></script>
        <script type="text/javascript" src="{{ asset('/chart-bar-demo.js') }}"></script>
        <script type="text/javascript" src="{{ asset('/datatables-demo.js') }}"></script>
        <script type="text/javascript" src="{{ asset('/datatables-simple-demo.js') }}"></script>
        <script type="text/javascript" src="{{ asset('/scripts.js') }}"></script>

These are my scripts, I do not understand what am I supposed to do, or what did I do wrong with them.
Also these are the unconverted scripts from laravel

        <script type="text/javascript" src="<?php echo e(asset('/chart-area-demo.js')); ?>"></script>
        <script type="text/javascript" src="<?php echo e(asset('/chart-bar-demo.js')); ?>"></script>
        <script type="text/javascript" src="<?php echo e(asset('/datatables-demo.js')); ?>"></script>
        <script type="text/javascript" src="<?php echo e(asset('/datatables-simple-demo.js')); ?>"></script>
        <script type="text/javascript" src="<?php echo e(asset('/scripts.js')); ?>"></script>

Laravel check if mail server is up

I’m working on a Laravel application and I want to know if there is a way to check that the mail server is up and running normally. Is there any way to maybe ping the server? The only way I can think of is to simply send an email and check if the email was sent or failed. This however could end up easily spamming the inbox with each time the mail server is checked.

Prestashop 1.7.5.2 How to add manually the customer vat_number on invoice

I need to add the customer delivery and billing vat_number on the invoice generated by prestashop.

I’ve tryed to modify my classes/pdf/HTMLTemplateInvoice.php adding ‘customer_vat_number’ => $invoice_address->vat_number like that:

$data = array(
            'order' => $this->order,
            'order_invoice' => $this->order_invoice,
            'order_details' => $order_details,
            'carrier' => $carrier,
            'cart_rules' => $cart_rules,
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
            'tax_excluded_display' => $tax_excluded_display,
            'display_product_images' => $display_product_images,
            'layout' => $layout,
            'tax_tab' => $this->getTaxTabContent(),
            'customer' => $customer,
            'footer' => $footer,
            'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_,
            'round_type' => $round_type,
            'legal_free_text' => $legal_free_text,
            'customer_vat_number' => $invoice_address->vat_number, // <= that doesn't works!!
        );

and also adding this to the pdf/invoice.addresses-tab.tpl

<table id="addresses-tab" cellspacing="0" cellpadding="0">
    <tr>
        <td width="50%">{if $delivery_address}<span class="bold">{l s='Delivery Address' d='Shop.Pdf' pdf='true'}</span><br/><br/>
                {$delivery_address}<br/>{$customer_vat_number} // <= that
            {/if}
        </td>
        <td width="50%"><span class="bold">{l s='Billing Address' d='Shop.Pdf' pdf='true'}</span><br/><br/>
                {$invoice_address}<br/>{$customer_vat_number} // <= that
        </td>
    </tr>
</table>

But it doesn’t works!

Help please!

Eloquent select field after aggregation

I have three models, User, Post and Comment. User and Post are in a One-To-Many relationship, and so are User and Comment. For the sake of this example, there isn’t a PostComment relationship.

When I run the following query

User::withCount(['posts', 'comments'])->get()

I obtain the expected results:

[
...
  AppModelsUser {#3459
    id: 18,
    username: "Foo",
    created_at: "2021-12-08 11:38:39",
    updated_at: "2021-12-08 11:38:39",
    posts_count: 5,
    comments_count: 15,
  }
...
]

I would like to remove the timestamps from the resulting models.
I’ve tried putting the array of fields I want as parameter for get (as in ->get(['username', 'posts_count', 'comments_count']), but the result didn’t change at all.

I’ve also tried replacing get(...) with select(...)->get(), but that produces this error:

IlluminateDatabaseQueryException with message 
'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'posts_count' in 'field list'  
(SQL: select `username`, `posts_count`, `comments_count` from `users`)'

which I assume it is due to the fact that the aggregation function is not yet being executed.

So I came up with this solution

$usersWithCounts = User::withCount(['posts', 'comments'])->get()
    ->map(function ($item, $key) {
         return $item->only(['username', 'posts_count', 'comments_count']); 
      });

but it doesn’t feel right: the returned collection is no longer made of Eloquent models, just simple arrays.

What’s the right way of proceeding?

The datatable cant display the searching and sorting, may I know why?

The datatable cant display the searching and sorting, may I know why? The problem is, the searching, sorting didn’t display. But when I use HTML code 100% then it will display, but when I use data that fetch from MySQL, it didn’t display the searching and sorting but it displays the table. I’m new to this and still a student. This is where the js and css link I take
datatable

table for datatype

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Content filter for IHSR</title>

    <!--Link from datatable for sort,pagging,search-->
    <link href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
</head>

<body >
    <?php
    include('connection.php');

    // select column from table ihsr_facebook_content
    $query = "SELECT * FROM customer ORDER BY Customer_Name ASC";//later change to DESC
    // get results from database
    $result = mysqli_query($connect, $query);

    // display data in table
    if(mysqli_num_rows($result)>0)
    {
    $output = '<div>
                <table id="example" class="display" style="width:100%">
                  <thead class="table-dark">
                    <tr>
                      <th style="padding-left: 10px; padding-right: 20px;" >No.</th>
                      <th style="padding-left: 10px; padding-right: 20px;" colspan="2">Name</th>
                      <th style="padding-left: 10px; padding-right: 20px;" >Email</th>
                      <th style="padding-left: 10px; padding-right: 20px;" >Contact</th>
                      <th style="padding-left: 10px; padding-right: 20px;" >Address</th>
                      <th width="7%">Edit</th>
                      <th width="9%">Delete</th>
                    </tr>
                  </thead>
                <tbody>';
    $num = mysqli_num_rows($result);
    $count= 1 ;
    // loop through results of database query, displaying them in the table
    while($row = mysqli_fetch_array( $result )) {
      $Customer_ID = $row['Customer_Id'];
      $Customer_Name = $row['Customer_Name'];
      $Customer_Email = $row['Customer_Email'];
      $Customer_Contact = $row['Customer_Contact'];
      $Customer_Address = $row['Customer_Address'];

    // echo out the contents of each row into a table
      $output.='<tr>
                  <td>'.$count.'</td>
                  <td colspan="2">'.$Customer_Name.'</td>
                  <td>'.$Customer_Email.'</td>
                  <td>'.$Customer_Contact.'</td>
                  <td>'.$Customer_Address.'</td>
                  <td><a class="btn-1" href="product_edit.php?GetEdit='.$Customer_ID.'" id="myBtn">Edit</a></td>
                  <td><button type="button" class="delButton btn-1" data-toggle="modal" id="'.$Customer_ID.'" data-target="#myModal" >Delete</button></td>
                </tr>';
      $count++;
    }
    }
    // close table>
    echo $output.'</tbody></table></div>';
    ?>

<script>
$(document).ready(function() {
    $('#example').DataTable();
} );

</script>
</body>
</html>

first time trying email for with php, help would be appreciated

I am trying to send some basic text data from a html form to an email. I found an article online with the php code contain below. Here is the link to the article https://html.form.guide/email-form/php-form-to-email/. I am using easyphp dev server to run my code and it is reporting an error on line 22 of the php file. Here is the error: Parse error: syntax error, unexpected ‘mail’ (T_STRING) in C:Program Files (x86)EasyPHP-Devserver-17eds-wwwform-to-email.php on line 22. Any help in clarifying what this means would be greatly appreciated as this is my first time attempting this. Thanks in advance.

<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

$email_from = '[email protected]';

$email_subject = "New Form submission";

$email_body = "You have received a new message from the user $name.n".
                        "Here is the message:n $message".
                        

$to = "[email protected]";

$headers = "From: $email_from rn";

$headers .= "Reply-To: $visitor_email rn";


ini_set(25)
mail($to,$email_subject, $email_body,$headers);

?>

Sort A Multi Dimensional Array In Laravel

enter image description here

This is the result of dd() that I use in my controller on laravel 8. I want to sort the data based on the JB column. I can’t use the manual order by in SQL syntax because I get JB from complex DB RAW. Therefore I want to sort this multi-dimensional array using php. Does anyone know how to sort the multi-dimensional array based on JB column value?

Send data with cURL by post’s data

Hi can I concatenate my post data?

CURLOPT_POSTFIELDS => "{"contact":{"dataFields":[{"key":"FIRSTNAME","value":"Foo"},{"key":"LASTNAME","value":"Bar"}],"email":"[email protected]","optInType":"Single","emailType":"PlainText"},"consentFields":{"fields":[{"key":"UK_OPT_IN_COUNT","value":"Y"}]}}"

I need to replace Foo with $_POST['firstName'], Bar with $_POST['lastName'], and [email protected] with $_POST['email']

Carry over Phone Number field to meta field WooCommerce

so I’ve implemented a phone login and register option in WooCommerce with the code:

function wooc_add_phone_number_field() {
    return apply_filters( 'woocommerce_forms_field', array(
        'wooc_user_phone' => array(
            'type'        => 'text',
            'pattern'     => '[0][0-9]{9}',
            'label'       => __( 'Phone Number', ' woocommerce' ),
            'placeholder' => __( 'MUST START WITH 0 e.g 081 123 4567', 'woocommerce' ),
            'required'    => true,
        ),
    ) );
}
add_action( 'woocommerce_register_form', 'wooc_add_field_to_registeration_form', 15 );
function wooc_add_field_to_registeration_form() {
    $fields = wooc_add_phone_number_field();
    foreach ( $fields as $key => $field_args ) {
        woocommerce_form_field( $key, $field_args );
    }
}


//Store
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
function wooc_save_extra_register_fields( $customer_id ) {
    if (isset($_POST['wooc_user_phone'])){
        update_user_meta( $customer_id, 'wooc_user_phone', sanitize_text_field( $_POST['wooc_user_phone'] ) );
    }
}

//Check against phone
function wooc_get_users_by_phone($phone_number){
    $user_query = new WP_User_Query( array(
        'meta_key' => 'wooc_user_phone',
        'meta_value' => $phone_number,
        'compare'=> '='
    ));
    return $user_query->get_results();
}


//Authenticate 
add_filter('authenticate','wooc_login_with_phone',30,3);
function wooc_login_with_phone($user, $username, $password ){
    if($username != ''){
        $users_with_phone = wooc_get_users_by_phone($username);
        if(empty($users_with_phone)){
            return $user;
  }
  $phone_user = $users_with_phone[0];
  
  if ( wp_check_password( $password, $phone_user->user_pass, $phone_user->ID ) ){
   return $phone_user;
  }
    }
    return $user;
}


//Login label
add_filter( 'gettext', 'wooc_change_login_label', 10, 3 );
function wooc_change_login_label( $translated, $original, $domain ) {
    if ( $translated == "Username or email address" && $domain === 'woocommerce' ) {
        $translated = "Username or email address or phone";
    }
    return $translated;
}

Which works perfectly fine however what I want to do is then populate the phone field in the Billing Address with the value that is stored here so when a user goes to Billing Form theyll find the same details they entered when registering.

Run PHP script after Azure Web app deployment

I am having an Azure app Service and I want to upload/deploy an .php file to it an run it right after the upload.

I managed to upload it via curl and also start a post deployment script. Unfortunately I can not use the command “php …” in it because I get an error like: “/opt/Kudu/Scripts/starter.sh: line 2: exec: php: not foundn” in the logs.
The same occurs if I use the “/api/command” endpoint with the same command. I get the same kind of error in the response.

It seems like the php executable is not known in that environment.
Is there any way to run a php script via the command API or in a post deployment script?

Thanks in advance

PHP simplexml – dealing with namespaces

Background
I am trying to extract the value of the following element

<D:POD>2021-08-07</D:POD>

from the following XML.

The output I am trying to get

2021-08-07

The problem of this XML is that its elements (including the root element) contain namespaces. I am struggling to deal with this using simplexml.

My steps

I request and receive the above XML from the api using

$this->curl = curl_init($this->url);
curl_setopt($this->curl, CURLOPT_URL, $this->url);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
$this->headers = array(
    "Accept: application/xml",
 );
 curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->headers);

 $this->resp = curl_exec($this->curl);
 curl_close($this->curl); 

Then I run simplex_load_string:

$this->xml = simplexml_load_string($this->resp);

I am trying to access:

<are:Ares_odpovedi>(root)
   <are:Odpoved>
      <D:Vypis_OR>
         <D:ZAU>
 ->         <D:POD>2021-08-07</D:POD>

I am not able to point to the element <D:POD> with the standard $xml->element_lvl1->element_lvl2… since all the elements have namespaces.

I tried running print_r on the result to help me to point to these namespaced elements:

print_r($this->xml);

but it only displays the attributes of the root element (are:Ares_odpovedi) in the XMLobject. I cannot see any child elements of this root element.

SimpleXMLElement Object ( [@attributes] => Array ( [odpoved_datum_cas]
=> 2022-01-17T11:41:46 [odpoved_pocet] => 1 [odpoved_typ] => Vypis_OR [vystup_format] => XML [xslt] => klient [validation_XSLT] =>
http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_odpovedi.xsl
[Id] => ares ) )

Question:
Is there please a way how to get the value of a specific child element (<D:POD>2021-08-07</D:POD>) in this xml where all the elements (including the root element) contain namespaces?

HIGHCHARTS PROBLEM: ajax call from an .php JSON data file for display it on the chart not working

we are two students that have to load on a highcharts chart some x and y data taken from a .php file that contains the data in JSON format, but after making the AJAX call we do not know how to recall the data on the chart, we have seen a lot of guides but, we can’t find anything, if you can help us we will be glad.

Our complete code:
Html:

<html lang="it">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <script src="https://code.highcharts.com/highcharts.js"></script>
 <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
 <title>Grafico Stage</title>
</head>
<body>

 <div id="container"></div>

 <script src="index.js"></script>
</body>
</html>

.javaScript

    Highcharts.chart('container', {
        colors: ["#669900"],
        chart: {
            type: 'spline',
            zoomType: 'x,y',
        },
        title: {
            text: 'Grafico Stage Samela-Ungureanu'
        },
        credits: {
            text: 'Powered by Sirius s.r.l',
            href: 'http://www.sirius.to.it/',
            position: {
                align: 'left',
                x: 70,
                y: -355
            },
            style: {
                fontSize: "15px",
                color: "#669900"
            }
        },
        yAxis: {
            title: {
                text: null,
            },
        },
        series: [
            {
                name: 'Potenza',
                data: []
            },
        ],
        xAxis: {
            categories: []
        },
        series: [
            {
                name: 'SSEMontalto.Montalto.WPP.Line 01.WTG01.DMAV.Active Power',
                data: []

            },

        ]

    });
    $.ajax({
        url: "getData.php",
        cache: false,
        dataType: "json",
        type: "GET",
        complete: function (data) {
            console.log("Ajax request finished");
        },
        success: function (data) {

            console.log(data)
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log("Error:" + textStatus);
        }
    })

});

.php with JSON format

{"SSEMontalto.Montalto.WPP.Line 01.WTG01.DMAV.Active Power":[{"unixdate":1641769200000,"value":558.571,"valid":true},{"unixdate":1641769800000,"value":613.30537229,"valid":true},{"unixdate":1641770400000,"value":622.3602128064896,"valid":true},{"unixdate":1641771000000,"value":659.07448648037,"valid":true},{"unixdate":1641771600000,"value":779.1308358631477,"valid":true},{"unixdate":1641772200000,"value":929.2911635973804,"valid":true},{"unixdate":1641772800000,"value":986.1693585565218,"valid":true},{"unixdate":1641773400000,"value":941.6240886305237,"valid":true},{"unixdate":1641774000000,"value":954.4424173490511,"valid":true},{"unixdate":1641774600000,"value":871.015560090988,"valid":true},{"unixdate":1641775200000,"value":857.4163941512874,"valid":true},{"unixdate":1641775800000,"value":869.1389910921237,"valid":true},{"unixdate":1641776400000,"value":788.9252844652405,"valid":true},{"unixdate":1641777000000,"value":882.9557112700836,"valid":true},{"unixdate":1641777600000,"value":975.8267588928936,"valid":true},{"unixdate":1641778200000,"value":1082.4865752934047,"valid":true},{"unixdate":1641778800000,"value":1028.8623553265202,"valid":false},{"unixdate":1641779400000,"value":1004.2612275483077,"valid":false},{"unixdate":1641780000000,"value":916.8332578616346,"valid":false},{"unixdate":1641780600000,"value":834.2073278298863,"valid":false},{"unixdate":1641781200000,"value":802.6701198012775,"valid":false},{"unixdate":1641781800000,"value":832.7614199225076,"valid":true},{"unixdate":1641782400000,"value":777.5618292029441,"valid":true},{"unixdate":1641783000000,"value":916.6365379741827,"valid":true},{"unixdate":1641783600000,"value":981.8332283741345,"valid":true},{"unixdate":1641784200000,"value":942.9703055286295,"valid":true},{"unixdate":1641784800000,"value":886.8984622509806,"valid":true},{"unixdate":1641785400000,"value":1017.234399567998,"valid":true},{"unixdate":1641786000000,"value":1175.1203679593466,"valid":true},{"unixdate":1641786600000,"value":1371.0740395573036,"valid":true},{"unixdate":1641787200000,"value":1501.2547774651905,"valid":true},{"unixdate":1641787800000,"value":1356.8190553252646,"valid":true},{"unixdate":1641788400000,"value":1367.9571829504296,"valid":true},{"unixdate":1641789000000,"value":1477.3964935008298,"valid":true},{"unixdate":1641789600000,"value":1590.378912944812,"valid":true},{"unixdate":1641790200000,"value":1647.0536558865135,"valid":true},{"unixdate":1641790800000,"value":1889.096425887316,"valid":true},{"unixdate":1641791400000,"value":1847.0262484828054,"valid":true},{"unixdate":1641792000000,"value":1960.263733724789,"valid":true},{"unixdate":1641792600000,"value":2210.8442468068292,"valid":true},{"unixdate":1641793200000,"value":2519.3321879407736,"valid":true},{"unixdate":1641793800000,"value":2276.6172056223713,"valid":true},{"unixdate":1641794400000,"value":2315.142121975913,"valid":true},{"unixdate":1641795000000,"value":2382.065935295871,"valid":true},{"unixdate":1641795600000,"value":2344.3363929467196,"valid":true},{"unixdate":1641796200000,"value":2522.0488132140454,"valid":true},{"unixdate":1641796800000,"value":2652.630412567016,"valid":true},{"unixdate":1641797400000,"value":3045.331124104262,"valid":true},{"unixdate":1641798000000,"value":2870.0692725809376,"valid":true},{"unixdate":1641798600000,"value":2806.2389319587373,"valid":true},{"unixdate":1641799200000,"value":2678.3053052896703,"valid":true},{"unixdate":1641799800000,"value":2514.4331951855215,"valid":true},{"unixdate":1641800400000,"value":2664.9572239821073,"valid":true},{"unixdate":1641801000000,"value":3092.4003729654933,"valid":true},{"unixdate":1641801600000,"value":3103.059877051105,"valid":true},{"unixdate":1641802200000,"value":3015.2091488719116,"valid":true},{"unixdate":1641802800000,"value":2996.9430118480454,"valid":true},{"unixdate":1641803400000,"value":3459.90777137532,"valid":true},{"unixdate":1641804000000,"value":3149.616322622838,"valid":true},{"unixdate":1641804600000,"value":2876.0973419336256,"valid":true},{"unixdate":1641805200000,"value":2712.3496158679764,"valid":true},{"unixdate":1641805800000,"value":3128.5542397236854,"valid":true},{"unixdate":1641806400000,"value":3654.620635133223,"valid":true},{"unixdate":1641807000000,"value":3857.583646725982,"valid":true},{"unixdate":1641807600000,"value":3889.5321544881663,"valid":true},{"unixdate":1641808200000,"value":4231.877106129751,"valid":true},{"unixdate":1641808800000,"value":4260.962797480181,"valid":true},{"unixdate":1641809400000,"value":4643.022026716241,"valid":true},{"unixdate":1641810000000,"value":5323.015817638969,"valid":true},{"unixdate":1641810600000,"value":6113.084440372033,"valid":true},{"unixdate":1641811200000,"value":7118.216123311324,"valid":true},{"unixdate":1641811800000,"value":8109.207053782603,"valid":true},{"unixdate":1641812400000,"value":8321.01143282035,"valid":true},{"unixdate":1641813000000,"value":8448.655748199813,"valid":true},{"unixdate":1641813600000,"value":7753.37362340171,"valid":true},{"unixdate":1641814200000,"value":9149.438324657798,"valid":true},{"unixdate":1641814800000,"value":9207.509809704403,"valid":true},{"unixdate":1641815400000,"value":8299.115306898586,"valid":true},{"unixdate":1641816000000,"value":7600.04762813729,"valid":true},{"unixdate":1641816600000,"value":7496.732580680392,"valid":true},{"unixdate":1641817200000,"value":7229.024260224295,"valid":true},{"unixdate":1641817800000,"value":6512.302649944357,"valid":true},{"unixdate":1641818400000,"value":6925.951089663522,"valid":true},{"unixdate":1641819000000,"value":7955.3967558267495,"valid":true},{"unixdate":1641819600000,"value":9233.765371314063,"valid":true},{"unixdate":1641820200000,"value":8361.017569713571,"valid":true},{"unixdate":1641820800000,"value":9688.253859747472,"valid":true},{"unixdate":1641821400000,"value":11162.38950228507,"valid":true},{"unixdate":1641822000000,"value":10203.975577229372,"valid":true},{"unixdate":1641822600000,"value":11722.123063609557,"valid":true},{"unixdate":1641823200000,"value":12441.474589654084,"valid":true},{"unixdate":1641823800000,"value":12923.071629545006,"valid":true},{"unixdate":1641824400000,"value":11823.447464587021,"valid":true},{"unixdate":1641825000000,"value":12596.795516350729,"valid":true},{"unixdate":1641825600000,"value":12336.230801095015,"valid":true},{"unixdate":1641826200000,"value":12052.374130361819,"valid":true},{"unixdate":1641826800000,"value":11394.278345721674,"valid":true},{"unixdate":1641827400000,"value":12538.12716029198,"valid":true},{"unixdate":1641828000000,"value":11657.210884137026,"valid":true},{"unixdate":1641828600000,"value":10614.496684972737,"valid":true}]}

PHP Paypal MALFORMED_REQUEST_JSON although JSON seems to be well formatted

I try to implement a paypal express checkout flow to a website.

The user must be able to adjust the order after they have logged in with paypal and choosed their payment option.

To do so, I create the order with paypal with the intent “AUTHORIZE” and user action “CONTINUE”. It is created, the user is sent back to our website and I can fetch order and payer information with the (order) id created.

But then, when the payer is done checking and adjusting some final parameters and clicks the “buy now” button, I want to send the update order call as referenced here:
https://developer.paypal.com/api/orders/v2/#orders_patch

I create the payload in exactly the same way as for order creation, but this time with intent “CAPTURE” and user_action=”PAY_NOW”. I PATCH it to the correct path, but I keep getting the failure message “MALFORMED_REQUEST_JSON” .

Hoewever, the JSON itself is a valid JSON, no errors thrown in creation. Here is a sample:

{
    intent: "CAPTURE",
    application_context: {
        landing_page: "NO_PREFERENCE",
        shipping_preference: "SET_PROVIDED_ADDRESS",
        user_action: "PAY_NOW",
    },
    purchase_units: [{
        reference_id: "2289256",
        description: "Your Order with us",
        custom_id: "OrderId 2289256",
        soft_descriptor: "Name of the site",
        invoice_id: "2289256",
        amount: {
            currency_code: "EUR",
            value: 59.98,
            breakdown: {
                item_total: {
                    currency_code: "EUR",
                    value: 50.41,
                },
                shipping: {
                    currency_code: "EUR",
                    value: 0,
                },
                discount: {
                    currency_code: "EUR",
                    value: 0,
                },
                tax_total: {
                    currency_code: "EUR",
                    value: 9.57,
                },
            },
        },
        items: [{
            name: "Product 1",
            description: "Product 1 description",
            sku: "1019879",
            unit_amount: {
                currency_code: "EUR",
                value: 16.8,
            },
            tax: {
                currency_code: "EUR",
                value: 3.19,
            },
            quantity: "1",
            category: "PHYSICAL_GOODS",
        }, {
            name: "Product 2",
            description: "Product 2 description",
            sku: "1024593",
            unit_amount: {
                currency_code: "EUR",
                value: 33.61,
            },
            tax: {
                currency_code: "EUR",
                value: 6.38,
            },
            quantity: "1",
            category: "PHYSICAL_GOODS",
        }, ],
        shipping: {
            name: {
                full_name: "John Doe"
            },
            address: {
                address_line_1: "Badensche Str.    24",
                address_line_2: " ",
                admin_area_2: "Berlin(Berlin)",
                postal_code: "10715",
                country_code: "DE",
            },
        },
    }],
}

Here is paypal´s response

{
    name: "INVALID_REQUEST",
    message: "Request is not well-formed, syntactically incorrect, or violates schema.",
    debug_id: "c315ce9eb90b4",
    details: [{
        field: "/",
        location: "body",
        issue: "MALFORMED_REQUEST_JSON",
        description: "The request JSON is not well formed.",
    }],
    links: [{
        href: "https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON",
        rel: "information_link",
        encType: "application/json",
    }],
}

I just cannot figure out the problem. I tried to remove the whole application_context, purchase_units, intent and see if there is a problem within any of these parameters. Nothing changed. What exactly is wrong with this call?

Contact Form with Custom Datepicker NMR don’t validate field when required

Using Custom Datepicker NMR plugin with CF7 which nearly duplicate the CF7 date.php module and add a new $tag where we can use jquery-ui-datepicker.

Everything works as except but when the field is required, the validation do not validate the datepicker field on form submit.

Looks like this line have no effect :

 **$atts['aria-invalid'] = $validation_error ? 'true' : 'false';**

Any help would be appreciated !

Thanks in advance

[PHP]

add_action('wpcf7_init', 'nmr_add_jqueryui_datepicker');
function nmr_add_jqueryui_datepicker()
{
    wpcf7_add_form_tag(
        array('datepicker', 'datepicker*'),
        'nmr_datepicker_form_tag_handler',
        array('name-attr' => true)
    );
}

function nmr_datepicker_form_tag_handler($tag)
{
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);

    $class = wpcf7_form_controls_class($tag->type);

    $class .= ' wpcf7-validates-as-date';

    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }

    $atts = array();
    $atts['class'] = $tag->get_class_option($class) . ' nmr-datepicker';
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true);
    $atts['min'] = $tag->get_date_option('min');
    $atts['max'] = $tag->get_date_option('max');
    $atts['step'] = $tag->get_option('step', 'int', true);
    $atts['data-format'] = $tag->get_option('format', '', true);

    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }

    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }

    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';

    $value = (string) reset($tag->values);

    if (
        $tag->has_option('placeholder')
        or $tag->has_option('watermark')
    ) {
        $atts['placeholder'] = $value;
        $value = '';
    }

    $value = $tag->get_default_option($value);

    $value = wpcf7_get_hangover($tag->name, $value);

    $atts['value'] = $value;

    $atts['type'] = 'text';
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);

    $html = sprintf(
        '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
        sanitize_html_class($tag->name),
        $atts,
        $validation_error
    );
    return $html;
}

function nmr_datepicker_enqueue_script() {   
    $path = plugin_dir_url( __FILE__ );
    wp_enqueue_style('jquery-ui-css', $path .'css/jquery-ui.css');
    wp_enqueue_script( 'nmr_datepicker', $path . 'js/nmr-datepicker.js' , array('jquery', 'jquery-ui-datepicker'));
}
add_action('wp_enqueue_scripts', 'nmr_datepicker_enqueue_script');

[JS]

(function ($) {
    $(document).ready(function () {
        $(".nmr-datepicker").each(function (i, item) {
            var settings = {};
            if (item.dataset.format) {
                settings.dateFormat = item.dataset.format;
            }
            if (item.id) {
                $(`#${item.id}`).datepicker(settings);
            }
        });
    });
})(jQuery);