Search code examples
square

Checkout API get email of buyer on redirect


So using the square checkout api, after the user uses the square checkout, I get a transaction id and checkout id, but it seems theres no way to get the information the buyer entered at checkout. How can I get the email and name of said buyer?

Tried getting the info through the checkout id but it seems its not possible

// pull out the transaction ID returned by Square Checkout
$returnedTransactionId = $_GET["transactionId"];

// Create a new API object to verify the transaction
$transactionClient = new \SquareConnect\Api\TransactionsApi($defaultApiClient);

// Ping the Transactions API endpoint for transaction details
try {

  // Get transaction details for this order from the Transactions API endpoint
  $apiResponse = $transactionClient->retrieveTransaction(
    $locationId,
    $returnedTransactionId
  );

} catch (Exception $e) {
  echo "The SquareConnect\Configuration object threw an exception while " .
       "calling TransactionsApi->retrieveTransaction: ",
       $e->getMessage(), PHP_EOL;
  exit;
}

Solution

  • Once you retrieve the transaction like you're already doing, the response will have a field called tenders, and in this array field you'll find a field called customer_id. Using this customer_id, you can call RetrieveCustomer and get the customer's information, including their name and email.