Get payment info based on transactionid and orderid

Using a payment link and a notification redirect, the redirect target receives a transactionid and and an orderid. Two questions:

  • Can I provide URL parameters to the payment link to prefill custom fields?
  • How can I retrieve info about the payment using transaction id and orderid, preferably using php?

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Retrieve Payments
Square Developer
Create a Card on File from a Payment ID

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Unfortunately, the ability to provide URL parameters to the payment link to pre-fill custom fields isn’t currently available.

To retrieve information about the payment using the transaction ID and order ID, you can use the Payments API. The transaction ID can be used as the Order ID to retrieve an Order object using the RetrieveOrder endpoint of the Orders API. The response from this call includes a tenders array, each item in which is the ID of a Payment object. You can then use the GetPayment endpoint of the Payments API to retrieve the Payment object using the payment ID from the tenders array. :slight_smile:

I removed the post because for some reason I couldn’t edit it and the post contained your access token. Please never share an access token. They are secret and all other values are safe to share. :slight_smile:

It didn’t contain my access token, just the following:

token: $_ENV[‘SQUARE_ACCESS_TOKEN’],

The access token is stored locally and never in a source file.

Skipping the creation of the Square client, the rest of the code is:

try {
$client->checkout->paymentLinks->create(
new CreatePaymentLinkRequest([
‘idempotencyKey’ => ‘cd9e25dc-d9f2-4430-aedb-61605070e95f’,
‘quickPay’ => new QuickPay([
‘name’ => ‘Auto Detailing’,
‘priceMoney’ => new Money([
‘amount’ => 10000,
‘currency’ => Currency::Usd->value,
]),
‘locationId’ => $locationid,
]),
]),
);

} catch (Square\Exceptions\SquareApiException $e) {
echo 'Square API Exception occurred: ’ . $e->getMessage() . “\n”;
echo 'Status Code: ’ . $e->getCode() . “\n”;
}

It is entirely taken from a published example, except that I added error handling.

Regards,
Rob

What published example? Because this is what I saw in the post:

The client was included.

What exactly are you trying to do with the link next? :slight_smile:

I think that is the access token from the coding example provided by Square. It is not used here. I would assume that if Square publishes it, it is not a valid token but just an example. The real token is retrieved from the ENV.

The use case: someone signs up for an outing and I want to allow them to pay in advance online. The form needs to be prepopulated with the particular outing and date and to return the ID of the outing (all of which would be prefilled) along with the email of the payer. Then the info can be stored in our outings system.

I thought the payment link was to be shared with the payer. What is the purpose of the endpoint otherwise?

If that is not the appropriate API, which one should I use to fulfill the use case?

Regards,
Rob

Is the example publicly available? Do you have the link to the example?

That’s correct the generated link can be shared with the customer. That’s a function that you will need to build. We leave the delivery up to the developer and there use case since it can be delivered in so many ways. :slight_smile:

My original question was how to get the link created by the function:

“I got it to the point where it no longer produces errors, but have not been able to figure out how to extract the returned link.”

Once I have it, I can give it to the customer. Then when it is submitted, I will need to get the values of the fields of the submitted form.

Regards,
Rob

So all you need to do is to extract it from the JSON response. :slight_smile: