Find all payments made by customer by customer_id

I am building a web service with flask, and need to be able to return a list of all payments made by a given user (ideally, the payments would be filtered by user ID). This is a relatively simple requirement, however, I have not been able to find a solution. When using the square API and “client.payments.list_payments()”, the response often does not contain the user ids associated with each payment, or in fact any information which could be used to reliably trace the payment to a given user.

:wave: To get all the payments associated to a customer you will need to do the following:

  • First your application will need to know all the possible customer_ids for the customer you want the payments for. There’s a chance that if the customer has been merged there may be multiple Ids for them.

  • ListPayment for your locations and given time frame. Then parse the results for the customer_ids.

  • Also SearchOrders for your locations and given time frame. Then parse the results for the customer_ids and match the payment_ids with the previous ListPayments call and parse out any payment_ids that don’t have a matching payment_id. This is because the order may have the customer but the payment may not.

  • Use GetPayment to get the last of the payments associated to the customer. :slightly_smiling_face:

Thank you! This was helpful. I am now able to filter user payments by email address. I have noticed, however, that not all payments have an associated customer ID field in the return body. It would be easier (and more reliable) to filter payments by customer id - do you know why this is the case?