Square Payment Api

I am having issues with the payment api for customers on file. I am able to obtain the source ID but the actual creation of payment is failing in production even though it was working in sandbox. I have updated the tokens for production. I have also verfied the cutsomer_id. I just don’t know what I am doing wrong. Here is my request random_uuid = uuid.uuid4()
idempotency_key = f"{int(time.time())}_{str(random_uuid)[:15]}"

                response = square_client.payments.create_payment(
                        "source_id": "ccof:customer-card-id-ok",
                        "idempotency_key": idempotency_key,
                        "amount_money": {
                            'amount': amount_in_cents,
                            'currency': 'USD',
                        "autocomplete": False,
                        "customer_id": customer_id,
                        "accept_partial_authorization": False



And the Response {
“errors”: [
“code”: “NOT_FOUND”,
“detail”: “Did not find matching card”,
“field”: “source_id”,
}. My Square ID is sq0idp-2fg-YHsBRXzYeZT3EjRZXA

: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

Create and Publish Invoices
Card Payments
Create a Card on File and a Payment

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.

When testing in production are you using a valid card, because the value that you have in the code example ccof:customer-card-id-ok is a sandbox test value. :slightly_smiling_face:

Bryan, thank you for the reply. I assumed that was a standard call for a Credit Card on File because API Explorer was doing the same thing in production mode. Obviously I did not go past generating the api call on there. So what replaces it in a production environment?

You’ll need to pass in the card_id that was first generated by the Cards API for the customer profile. If you RetrieveCustomer with the customer_id the profile will have the card_id that you’ll pass into the CreatePayment request when trying to charge a card on file. :slightly_smiling_face:

I see! Thanks for your assistance Bryan! Cheers! :+1: :pray:

I am facing another issue. I have successfully processed a payment, got all the approval responses including receipt number. But the transaction is not in my production dashboard. Tried * Reporting > Transactions.

  • Select eCommerce Integrations from the All Payment Methods dropdown. Still nothing. It is not reflected in my balance either. What am I missing?

I solved the issue. Autocomplete was set to ‘false’, hence creating a delayed process. Thanks for your assistance. I am closing this as solved.

Glad to hear you figured it out. :slightly_smiling_face: