Hi everyone. My first post… How exciting!
As the title says, I’m struggling to incorporate the payload into a curl call in PHP. The following is the script and within it you can see the API Explorer-generated curl (Which works in the Explorer tool)
Below that is my curl code. This works if I remove the POSTFIELDS line (It generates a list of all my sandbox transactions) so I don’t feel to be far off - Just a syntax thing with the payload itself probably - I’m no PHP expert.
I’m stuck now and seem to have exhausted the permutations so is anybody able to help with the correct syntax for this POSTFIELDS line?
<?php/*
curl https://connect.squareupsandbox.com/v2/payments \
-X POST \
-H 'Square-Version: 2021-05-13' \
-H 'Authorization: Bearer ' \
-H 'Content-Type: application/json' \
-d '{ "idempotency_key": "67f1fd4a-23d8-48c1-8405-fe3582708dff", "source_id": "cnon:card-nonce-ok", "amount_money": { "amount": 3500, "currency": "GBP" } }'
*/
$access_token="";
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, "https://connect.squareupsandbox.com/v2/payments");
curl_setopt($curl,CURLOPT_POST, "true");
curl_setopt($curl,CURLOPT_HTTPHEADER, array('authorization: Bearer '.$access_token,'content-type: application/json','Square-Version: 2021-05-13','Content-Type: application/json'));
// curl_setopt($curl,CURLOPT_POSTFIELDS, ???);
$response = curl_exec($curl);
curl_close($curl);
echo "$response";
?>
Many thanks for any help.
Best regards
Simon
PS For info, node.js isn’t available with my host and I’m not allowed to install the Square SDK either unfortunately so this is my only option…