Hi everyone,
I now have the Quick Pay Checkout working correctly via the following code…
$access_token="My_Access_Token";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://connect.squareupsandbox.com/v2/online-checkout/payment-links");
curl_setopt($curl, CURLOPT_POST, "true");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('authorization: Bearer ' . $access_token, 'content-type: application/json', 'Square-Version: 2025-06-18'));
$body = array(
"idempotency_key" => "603ae3ba-d189-45c1-8498-fb8f74a5abb7",
"quick_pay" => array(
"name" => "Test Order", "price_money" => array(
"amount" => 9524, "currency" => "GBP"),
"location_id" => "My_Location_ID")
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body));
$response = curl_exec($curl);
curl_close($curl);
echo "$response";
It’s working perfectly, i.e. the $response contains the relevant data including the URL, which when copy/pasted into the browser and clicking “Preview Link”, the payment link appears as expected, so all is great!
However, the above code isn’t the same as shown in the Quick Pay Checkout example as follows…
curl https://connect.squareupsandbox.com/v2/online-checkout/payment-links \
-X POST \
-H 'Square-Version: 2025-06-18' \
-H 'Authorization: Bearer My_Access_Token' \
-H 'Content-Type: application/json' \
-d '{
"idempotency_key": "55dbdb70-e84e-4c9c-a6cb-6f267c7d90c2",
"quick_pay": {
"location_id": "L2A4E9BGPYY1R",
"name": "Another test 1",
"price_money": {
"amount": 4579,
"currency": "GBP"
}
}
}'
Now, I realise I’m looking at two different methods for requesting a payment link, i.e. the one I have working initialises via the curl_init() function, and the Quick Pay Checkout example via -X POST.
Presumably I can continue on with what I have working and simply not bother worrying about the -X POST method… but even so, it’s really bugging me that I’m getting the following error…
Parse error : syntax error, unexpected identifier “https”
I’m using PHP Version 8.4.8 and from checking via calling phpinfo(), I can see “cURL support enabled”, “cURL Information 7.76.1”, “Age 8”, “HTTPS_PROXY Yes”, and many other settings.
- Any ideas why I’m getting the Parse error?
- Even if I wasn’t getting the parse error, is there an equivalent way to access the response when working with headers via -X POST in this way, i.e. equivalent to the returned “$response = curl_exec($curl)”? Or is -X POST intended to just create the payment link for me to then access in my account, but not to handle the response in my code?
Cheers, Gary.