Online-checkout create payment link returns old confirmation link

Hello,

I’m using the quick_pay create payment link in the online-checkout API. The link that is returned is an older confirmation link that I had done earlier in the API explorer.

Here is code snippet:

<?php
$curl = curl_init();
$url = "https://connect.squareup.com/v2/online-checkout/payment-links";

$fields = [
   'idempotency_key' => uniqid(),
   'quick_pay' => ['name' => "Renewal Testing",'price_money' => ['amount' => 101, 'currency' => "USD"],
   'location_id' => "*location_id_from_dashboard*"]
   ];

$postdata = json_encode($fields);
echo '<p>var_dump postdata</p>';
var_dump($postdata);

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POST, $postdata);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HTTPHEADER, ['Square-Version: 2022-12-14', 'Authorization: Bearer *authorization_token_from_dashboard*','Content-Type:application/json']);

$result = curl_exec($curl);

$obj = json_decode($result,true);
echo '<p>var_dump obj</p>';
var_dump($obj);

?>

Here is what happens:
var_dump postdata
string(150) “{“idempotency_key”:“63b3877e3aa22”,“quick_pay”:{“name”:“Renewal Testing”,“price_money”:{“amount”:101,“currency”:“USD”},“location_id”:“QMM4HPWSNJ0W9”}}”

var_dump obj
array(1) { [“payment_links”]=> array(1) { [0]=> array(5) { [“id”]=> string(16) “4EGVW6YCD5FBKWKQ” [“version”]=> int(1) [“order_id”]=> string(29) “EftaiQCEA9Lsed7vjYN0ba6ck5CZY” [“url”]=> string(30) “https://square.link/u/xxxxx” [“created_at”]=> string(20) “2023-01-02T23:19:41Z” } } }

The square.link provide is an old confirmation link that I did with API explorer:

This test was done using production credentials. Similar thing happens with sandbox; however, the return result there contained two different confirmation links that I had done with API explorer.

I took a look at your API Logs and I only see one POST request from the API Explorer in production. Are you sure the call to CreatePaymentLink from the example worked? :slightly_smiling_face:

Thank you Brian. I only did one API Explorer transaction in production. In my snippet on the execution in my code, I do receive a result from the cURL execution that contained an URL. But URL isn’t a link to complete the payment. The URL takes me to the confirmation from the API Explorer.

One extra thought here. When I used sandbox credentials, I received two URLs in the cURL result. Both links were to separate confirmations that I had done via the API Explorer. It seem that the way I’m doing the create payment link is returning me a list of confirmations and not the expected finish payment link.

Make sense?

Do you have the URL so we can take a look? :slightly_smiling_face:

Here is the return result for sandbox (URLs are embedded)
string(345) "{“payment_links”:[{“id”:“7ZPBA7VOQLKUKZXP”,“version”:1,“order_id”:“ADAMRM6oIhLTC589ttO5ZPdlze4F”,“url”:"https://sandbox.square.link/u/b3EzOHPE",“created_at”:“2023-01-02T22:26:14Z”},{“id”:“BXSOIJHWNLS6T2OF”,“version”:1,“order_id”:“01gsCr6sh4apYTrqRqIwnjSzjh4F”,“url”:“https://sandbox.square.link/u/PbteDfZq”,“created_at”:“2023-01-02T19:06:15Z”}]}"

Here is the return result for production (URL embedded)
string(175) "{“payment_links”:[{“id”:“4EGVW6YCD5FBKWKQ”,“version”:1,“order_id”:“EftaiQCEA9Lsed7vjYN0ba6ck5CZY”,“url”:"https://square.link/u/UUTihcjD",“created_at”:“2023-01-02T23:19:41Z”}]}"

For the production link when you created the link were you able to pay the link right after creation? :slightly_smiling_face:

Unfortunately not. All I have received is the same links repeatedly. Even tried different access token (changed it in dashboard). Different browser. Always get the same responses (same id, same url(s), same created_at(s))

Small update here. Instead of using the quick_pay option, I did the order option with couple of line items. Same result. I receive a payment_links object with URLs for completed orders that were done via the API Explorer couple of days ago.

Now looking at the API documentation and examples in API Explorer, the response is to provide a “payment_link” object with an URL. Both the name and description imply singular (only one link). The object I’m receiving is “payment_links” which contains more than one URL. I see no mention of this object in the online API documentation. Maybe a clue?

Are you using the same idempotency_key for each request? :slightly_smiling_face:

No I’m using the php uniqid function to generate the idempotency_key.

Here is a recap summary of my observations:

The outgoing HTTP header from cURL:
"GET /v2/online-checkout/payment-links HTTP/1.1 Host: connect.squareupsandbox.com Accept: / Square-Version: 2022-12-14 Authorization: Bearer ACCESS_TOKEN Content-Type:application/json "

The post data:
“{“idempotency_key”:“63b72c9ed6236”,“quick_pay”:{“name”:“Auto Detailing”,“price_money”:{“amount”:12500,“currency”:“USD”},“location_id”:“LW669T32BBAHV”}}”

The return result:
"{“payment_links”:[{“id”:“7ZPBA7VOQLKUKZXP”,“version”:1,“order_id”:“ADAMRM6oIhLTC589ttO5ZPdlze4F”,“url”:"https://sandbox.square.link/u/b3EzOHPE",“created_at”:“2023-01-02T22:26:14Z”},{“id”:“BXSOIJHWNLS6T2OF”,“version”:1,“order_id”:“01gsCr6sh4apYTrqRqIwnjSzjh4F”,“url”:“https://sandbox.square.link/u/PbteDfZq”,“created_at”:“2023-01-02T19:06:15Z”}]}"

  • The HTTP header information appears to match the information that is in the API Explorer (other than the access token)
  • The post data information appears to match the information that is in the API Explorer (other than the location id). The idempotency_key is always an unique value. Even tried it without an idempotency_key.
  • The return result is always the same. Containing links of confirmation of old transactions (days in the past). No sign of a payment link.

Is there a way to see what is going on in the Square server that would trigger to send these old links and not an actual payment link?

The above example you provided is a GET request. The request to create a payment link is a POST /v2/online-checkout/payment-links request. :slightly_smiling_face:

1 Like