Retrieve payment Id

I’m using Square order checkout with CreateOrderRequest & CreateCheckoutRequest.

How I can retrieve the payment id after receiving the payment confirmation?

This is the request:

                $create_order_request = new Square\Models\CreateOrderRequest();
                $create_order_request->setOrder($order);
                $checkout_request = new Square\Models\CreateCheckoutRequest(uniqid(), $create_order_request);
                $checkout_request->setRedirectUrl($conf_url);

                $response = $checkout_api->createCheckout($settings['locationid'], $checkout_request);
                header('Location: ' . $response->getResult()->getCheckout()->getCheckoutPageUrl());


// And the succcessful payment confirmation:

        $orders_api = $client->getOrdersApi();
        $response = $orders_api->retrieveOrder($_GET["transactionId"]);
        if ($response->isError()) {
            // Handle errors
        } else {
          // Retrieve payment id
        }

:wave: 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
Checkout API Overview
Quick Pay Checkout

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.

After receiving the payment confirmation, you can use the Orders API to retrieve the order details using the order ID. The order details will include the payment ID.

In your case, you can retrieve the payment ID from the order details as follows:

$order = $response->getResult()->getOrder();
$paymentId = $order->getTenders()[0]->getPaymentId();

This code retrieves the first payment ID associated with the order. If there are multiple payments associated with the order, you may need to iterate over the tenders array to retrieve all payment IDs.

This answer was reviewed by @Bryan-Square.

After trying:
$paymentId = $order->getTenders()[0]->getPaymentId();

It returns an empty result. I did a row print of the Tender object and the paymentId array is empty. I can confirm that the order status is completed.

Here’s a row dump:

Array ( [0] => Square\Models\Tender Object ( [id:Square\Models\Tender:private] => jtS2Q5G03FtdNjzalnT6FNNrvaB [locationId:Square\Models\Tender:private] => Array ( [value] => ************* ) [transactionId:Square\Models\Tender:private] => Array ( [value] => ****************************** ) [createdAt:Square\Models\Tender:private] => 2024-02-07T04:19:27Z [note:Square\Models\Tender:private] => Array ( [value] => Online Transaction ) [amountMoney:Square\Models\Tender:private] => Square\Models\Money Object ( [amount:Square\Models\Money:private] => Array ( [value] => 12801 ) [currency:Square\Models\Money:private] => CAD ) [tipMoney:Square\Models\Tender:private] => [processingFeeMoney:Square\Models\Tender:private] => [customerId:Square\Models\Tender:private] => Array ( ) [type:Square\Models\Tender:private] => CARD [cardDetails:Square\Models\Tender:private] => Square\Models\TenderCardDetails Object ( [status:Square\Models\TenderCardDetails:private] => CAPTURED [card:Square\Models\TenderCardDetails:private] => Square\Models\Card Object ( [id:Square\Models\Card:private] => [cardBrand:Square\Models\Card:private] => VISA [last4:Square\Models\Card:private] => 1111 [expMonth:Square\Models\Card:private] => Array ( ) [expYear:Square\Models\Card:private] => Array ( ) [cardholderName:Square\Models\Card:private] => Array ( ) [billingAddress:Square\Models\Card:private] => [fingerprint:Square\Models\Card:private] => sq-1-_PDzA5AsDkQRxLd2ELuo9USn-l4Yi1xtMFmGXAKZPOCh0oysyVWP_kH60h9XvyJbQQ [customerId:Square\Models\Card:private] => Array ( ) [merchantId:Square\Models\Card:private] => [referenceId:Square\Models\Card:private] => Array ( ) [enabled:Square\Models\Card:private] => [cardType:Square\Models\Card:private] => [prepaidType:Square\Models\Card:private] => [bin:Square\Models\Card:private] => [version:Square\Models\Card:private] => [cardCoBrand:Square\Models\Card:private] => ) [entryMethod:Square\Models\TenderCardDetails:private] => KEYED ) [cashDetails:Square\Models\Tender:private] => [bankAccountDetails:Square\Models\Tender:private] => [buyNowPayLaterDetails:Square\Models\Tender:private] => [squareAccountDetails:Square\Models\Tender:private] => [additionalRecipients:Square\Models\Tender:private] => Array ( ) [paymentId:Square\Models\Tender:private] => Array ( ) ) )

If the payment_id is empty and there’s a tender_id that’s also the payment_id. :slightly_smiling_face:

Excellent, it worked!

Thanks a lot!

:slightly_smiling_face: